diff options
author | Simon Steiner <ssteiner@apache.org> | 2023-03-30 07:45:01 +0100 |
---|---|---|
committer | Simon Steiner <ssteiner@apache.org> | 2023-03-30 07:45:01 +0100 |
commit | 45f68e349e3f870fee5d4604fcc8115938484c52 (patch) | |
tree | 6aa0d98d4e1bdaf161d1bd36c7764531014b59c7 | |
parent | 8641fc6f0befc627895c1d54703186f4e17ee939 (diff) | |
download | xmlgraphics-fop-45f68e349e3f870fee5d4604fcc8115938484c52.tar.gz xmlgraphics-fop-45f68e349e3f870fee5d4604fcc8115938484c52.zip |
FOP-3125: NPE when using broken link and PDF 1.5
4 files changed, 68 insertions, 3 deletions
diff --git a/fop-core/src/main/java/org/apache/fop/render/pdf/PDFDocumentHandler.java b/fop-core/src/main/java/org/apache/fop/render/pdf/PDFDocumentHandler.java index ae2053061..09eb12c54 100644 --- a/fop-core/src/main/java/org/apache/fop/render/pdf/PDFDocumentHandler.java +++ b/fop-core/src/main/java/org/apache/fop/render/pdf/PDFDocumentHandler.java @@ -183,6 +183,7 @@ public class PDFDocumentHandler extends AbstractBinaryWritingIFDocumentHandler { /** {@inheritDoc} */ public void endDocument() throws IFException { + documentNavigationHandler.registerIncompleteActions(); pdfDoc.getResources().addFonts(pdfDoc, fontInfo); try { if (pdfDoc.isLinearizationEnabled()) { diff --git a/fop-core/src/main/java/org/apache/fop/render/pdf/PDFDocumentNavigationHandler.java b/fop-core/src/main/java/org/apache/fop/render/pdf/PDFDocumentNavigationHandler.java index 005c82a6f..552139980 100644 --- a/fop-core/src/main/java/org/apache/fop/render/pdf/PDFDocumentNavigationHandler.java +++ b/fop-core/src/main/java/org/apache/fop/render/pdf/PDFDocumentNavigationHandler.java @@ -29,6 +29,7 @@ import org.apache.fop.pdf.PDFDocument; import org.apache.fop.pdf.PDFFactory; import org.apache.fop.pdf.PDFGoTo; import org.apache.fop.pdf.PDFLink; +import org.apache.fop.pdf.PDFObject; import org.apache.fop.pdf.PDFOutline; import org.apache.fop.pdf.PDFReference; import org.apache.fop.pdf.PDFStructElem; @@ -214,4 +215,9 @@ public class PDFDocumentNavigationHandler implements IFDocumentNavigationHandler return action.getID(); } + public void registerIncompleteActions() { + for (Object action : incompleteActions.values()) { + getPDFDoc().addObject((PDFObject) action); + } + } } diff --git a/fop-core/src/test/java/org/apache/fop/render/extensions/DocumentNavigationHandlerTestCase.java b/fop-core/src/test/java/org/apache/fop/render/extensions/DocumentNavigationHandlerTestCase.java index 1b8efd112..0578d27e7 100644 --- a/fop-core/src/test/java/org/apache/fop/render/extensions/DocumentNavigationHandlerTestCase.java +++ b/fop-core/src/test/java/org/apache/fop/render/extensions/DocumentNavigationHandlerTestCase.java @@ -109,13 +109,14 @@ public class DocumentNavigationHandlerTestCase { @Test public void testGotoXYMergedIF() throws Exception { InputStream ifXml = getClass().getResourceAsStream("link.if.xml"); - ByteArrayOutputStream pdf = iFToPDF(ifXml); + ByteArrayOutputStream pdf = iFToPDF(ifXml, "<fop/>"); Assert.assertTrue(pdf.toString().contains("/S /GoTo")); } - private ByteArrayOutputStream iFToPDF(InputStream is) throws Exception { + private ByteArrayOutputStream iFToPDF(InputStream is, String fopxconf) throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); - FOUserAgent userAgent = FopFactory.newInstance(new File(".").toURI()).newFOUserAgent(); + FOUserAgent userAgent = FopFactory.newInstance(new File(".").toURI(), + new ByteArrayInputStream(fopxconf.getBytes())).newFOUserAgent(); Transformer transformer = TransformerFactory.newInstance().newTransformer(); Source src = new StreamSource(is); IFDocumentHandler documentHandler @@ -255,4 +256,19 @@ public class DocumentNavigationHandlerTestCase { GoToXYAction a = (GoToXYAction) b.getAction(); Assert.assertEquals(a.getPageIndex(), 0); } + + @Test + public void testGotoXYMissingDestIF() throws Exception { + InputStream ifXml = getClass().getResourceAsStream("linkmissingdest.if.xml"); + String fopxconf = "<fop version=\"1.0\">\n" + + " <accessibility>true</accessibility>\n" + + " <renderers>\n" + + " <renderer mime=\"application/pdf\">\n" + + " <version>1.5</version>\n" + + " </renderer>\n" + + " </renderers>\n" + + "</fop>"; + ByteArrayOutputStream pdf = iFToPDF(ifXml, fopxconf); + Assert.assertTrue(pdf.toString().contains("/S /GoTo")); + } } diff --git a/fop-core/src/test/resources/org/apache/fop/render/extensions/linkmissingdest.if.xml b/fop-core/src/test/resources/org/apache/fop/render/extensions/linkmissingdest.if.xml new file mode 100644 index 000000000..f2e6eacb0 --- /dev/null +++ b/fop-core/src/test/resources/org/apache/fop/render/extensions/linkmissingdest.if.xml @@ -0,0 +1,42 @@ +<?xml version="1.0" encoding="UTF-8"?> +<document xmlns="http://xmlgraphics.apache.org/fop/intermediate" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:nav="http://xmlgraphics.apache.org/fop/intermediate/document-navigation" xmlns:foi="http://xmlgraphics.apache.org/fop/internal"> +<header> +<locale xml:lang="en"/> +<x:xmpmeta xmlns:x="adobe:ns:meta/"> +<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> +<rdf:Description xmlns:dc="http://purl.org/dc/elements/1.1/" rdf:about=""> +<dc:creator>creator</dc:creator> +<dc:title>Document title</dc:title> +</rdf:Description> +</rdf:RDF> +</x:xmpmeta> +</header> +<page-sequence xml:lang="en" xml:space="preserve"> +<structure-tree xmlns:fox="http://xmlgraphics.apache.org/fop/extensions"> +<fo:flow xmlns:fo="http://www.w3.org/1999/XSL/Format" flow-name="xsl-region-body"> +<fo:block> +<marked-content foi:struct-id="0"/> +<fo:basic-link fox:alt-text="" foi:struct-id="1"> +<marked-content foi:struct-id="2" foi:struct-ref="1"/> +</fo:basic-link> +<marked-content foi:struct-id="3"/> +</fo:block> +</fo:flow> +</structure-tree> +<page index="0" name="1" page-master-name="FirstPage" width="612000" height="792000"> +<page-header/> +<content> +<viewport transform="translate(54000,108000)" width="504000" height="630000"> +<font family="any" style="normal" weight="400" variant="normal" size="12000" color="#000000"/> +<text x="0" y="9996" foi:struct-ref="2">test</text> +</viewport> +</content> +<page-trailer> +<nav:link rect="54000 109800 16668 10800"> +<nav:goto-xy id="1" page-index="-1" x="0" y="0"/> +</nav:link> +</page-trailer> +</page> +</page-sequence> +<trailer/> +</document> |