Skip to content

Commit

Permalink
added processing of link-as-file-annotation attibute, #283
Browse files Browse the repository at this point in the history
  • Loading branch information
Intelligent2013 committed Sep 25, 2024
1 parent eef947d commit 3133837
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 5 deletions.
9 changes: 7 additions & 2 deletions src/main/java/org/apache/fop/pdf/PDFFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -743,8 +743,13 @@ private PDFAction getActionForEmbeddedFile(String filename, boolean newWindow) {
scriptBuffer.append(fileSpec.getFilename());
scriptBuffer.append("\", nLaunch:2});");

//PDFJavaScriptLaunchAction action = new PDFJavaScriptLaunchAction(scriptBuffer.toString());
PDFFileAttachmentAnnotation action = new PDFFileAttachmentAnnotation(fileSpec);
PDFAction action;
if (fileSpec.getLinkAsFileAnnotation() != null && fileSpec.getLinkAsFileAnnotation().equals("true")) {
action = new PDFFileAttachmentAnnotation(fileSpec);
} else {
action = new PDFJavaScriptLaunchAction(scriptBuffer.toString());
}

return action;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ public String getAction() {

public String getFileAttachmentAnnotation() {
StringBuilder sb = new StringBuilder();
String annotationDesc = fileSpec.get("Desc").toString();
String annotationF = fileSpec.get("F").toString();
String relationship = fileSpec.get("AFRelationship").toString();
String annotationDesc = "";
if (fileSpec.get("Desc") != null) {
annotationDesc = fileSpec.get("Desc").toString();
}
//String annotationF = fileSpec.get("F").toString();
//String relationship = fileSpec.get("AFRelationship").toString();
String objNumber = fileSpec.referencePDF(); // "7 0 R"; Todo
/*sb.append("/FileAttachment\n" + "/FS " + //this.referencePDF() + "\n"
"<<\n" +
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/org/apache/fop/pdf/PDFFileSpec.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
*/
public class PDFFileSpec extends PDFDictionary {

private String linkAsFileAnnotation = "false";

/**
* create a /FileSpec object.
*
Expand Down Expand Up @@ -86,6 +88,22 @@ public void setAFRelationship(String relationship) {
put("AFRelationship", new PDFName(relationship));
}

/**
* Sets a linkAsFileAnnotation for the file spec.
* @param linkAsFileAnnotation the indication of file attachment annotation
*/
public void setLinkAsFileAnnotation(String linkAsFileAnnotation) {
this.linkAsFileAnnotation = linkAsFileAnnotation;
}

/**
* Gets the linkAsFileAnnotation.
* @return linkAsFileAnnotation
*/
public String getLinkAsFileAnnotation() {
return linkAsFileAnnotation;
}

/** {@inheritDoc} */
protected boolean contentEquals(PDFObject obj) {
if (this == obj) {
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/apache/fop/render/pdf/PDFRenderingUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,9 @@ public void addEmbeddedFile(PDFEmbeddedFileAttachment embeddedFile)
if (embeddedFile.getRel() != null) {
fileSpec.setAFRelationship(embeddedFile.getRel());
}
if (embeddedFile.getLinkAsFileAnnotation() != null) {
fileSpec.setLinkAsFileAnnotation(embeddedFile.getLinkAsFileAnnotation());
}
this.pdfDoc.registerObject(fileSpec);

//Make sure there is an EmbeddedFiles in the Names dictionary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public class PDFEmbeddedFileAttachment extends PDFExtensionAttachment {
the associated file denoted by this file specification dictionary */
private static final String ATT_REL = "afrelationship";

/** An indication how to process link to the embedded file */
private static final String ATT_LINKASFILEANNOTATION = "linkasfileannotation";

/** filename attribute */
private String filename;

Expand All @@ -64,6 +67,8 @@ public class PDFEmbeddedFileAttachment extends PDFExtensionAttachment {
/** associated file relationship */
private String rel;

/** add link as file annotation */
private String linkAsFileAnnotation;

/**
* No-argument contructor.
Expand Down Expand Up @@ -171,6 +176,21 @@ public void setRel(String rel) {
this.rel = rel;
}

/**
* Returns the indication of link as file annotation.
* @return the linkAsFileAnnotation
*/
public String getLinkAsFileAnnotation() {
return linkAsFileAnnotation;
}

/**
* Sets the indication of link as file annotation.
* @param linkAsFileAnnotation the indication
*/
public void setLinkAsFileAnnotation(String linkAsFileAnnotation) {
this.linkAsFileAnnotation = linkAsFileAnnotation;
}

/** {@inheritDoc} */
public String getCategory() {
Expand Down Expand Up @@ -204,6 +224,9 @@ public void toSAX(ContentHandler handler) throws SAXException {
if (rel != null && rel.length() > 0) {
atts.addAttribute("", ATT_REL, ATT_REL, "CDATA", rel);
}
if (linkAsFileAnnotation != null && linkAsFileAnnotation.length() > 0) {
atts.addAttribute("", ATT_LINKASFILEANNOTATION, ATT_LINKASFILEANNOTATION, "CDATA", linkAsFileAnnotation);
}

String element = getElement();
handler.startElement(CATEGORY, element, element, atts);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ public void processNode(String elementName, Locator locator,
if (rel != null && rel.length() > 0) {
embeddedFile.setRel(rel);
}
String linkAsFileAnnotation = attlist.getValue("link-as-file-annotation");
if (linkAsFileAnnotation != null && linkAsFileAnnotation.length() > 0) {
embeddedFile.setLinkAsFileAnnotation(linkAsFileAnnotation);
}
}

@Override
Expand Down

0 comments on commit 3133837

Please sign in to comment.