diff --git a/src/main/java/org/apache/fop/pdf/PDFFactory.java b/src/main/java/org/apache/fop/pdf/PDFFactory.java index 276a815..20891f6 100644 --- a/src/main/java/org/apache/fop/pdf/PDFFactory.java +++ b/src/main/java/org/apache/fop/pdf/PDFFactory.java @@ -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; } diff --git a/src/main/java/org/apache/fop/pdf/PDFFileAttachmentAnnotation.java b/src/main/java/org/apache/fop/pdf/PDFFileAttachmentAnnotation.java index 7969ab0..7297ab9 100644 --- a/src/main/java/org/apache/fop/pdf/PDFFileAttachmentAnnotation.java +++ b/src/main/java/org/apache/fop/pdf/PDFFileAttachmentAnnotation.java @@ -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" + diff --git a/src/main/java/org/apache/fop/pdf/PDFFileSpec.java b/src/main/java/org/apache/fop/pdf/PDFFileSpec.java index 618a166..4e35f51 100644 --- a/src/main/java/org/apache/fop/pdf/PDFFileSpec.java +++ b/src/main/java/org/apache/fop/pdf/PDFFileSpec.java @@ -24,6 +24,8 @@ */ public class PDFFileSpec extends PDFDictionary { + private String linkAsFileAnnotation = "false"; + /** * create a /FileSpec object. * @@ -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) { diff --git a/src/main/java/org/apache/fop/render/pdf/PDFRenderingUtil.java b/src/main/java/org/apache/fop/render/pdf/PDFRenderingUtil.java index 1e32277..94a85a2 100644 --- a/src/main/java/org/apache/fop/render/pdf/PDFRenderingUtil.java +++ b/src/main/java/org/apache/fop/render/pdf/PDFRenderingUtil.java @@ -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 diff --git a/src/main/java/org/apache/fop/render/pdf/extensions/PDFEmbeddedFileAttachment.java b/src/main/java/org/apache/fop/render/pdf/extensions/PDFEmbeddedFileAttachment.java index 3480cb8..c2d1971 100644 --- a/src/main/java/org/apache/fop/render/pdf/extensions/PDFEmbeddedFileAttachment.java +++ b/src/main/java/org/apache/fop/render/pdf/extensions/PDFEmbeddedFileAttachment.java @@ -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; @@ -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. @@ -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() { @@ -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); diff --git a/src/main/java/org/apache/fop/render/pdf/extensions/PDFEmbeddedFileElement.java b/src/main/java/org/apache/fop/render/pdf/extensions/PDFEmbeddedFileElement.java index aacfe93..565cc7d 100644 --- a/src/main/java/org/apache/fop/render/pdf/extensions/PDFEmbeddedFileElement.java +++ b/src/main/java/org/apache/fop/render/pdf/extensions/PDFEmbeddedFileElement.java @@ -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