[
https://issues.apache.org/jira/browse/PDFBOX-2666?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Tilman Hausherr updated PDFBOX-2666:
------------------------------------
Affects Version/s: 1.8.10
1.8.9
> LayerUtility.wrapInSaveRestore creates invalid content if additional page
> content has been added in same session
> ----------------------------------------------------------------------------------------------------------------
>
> Key: PDFBOX-2666
> URL: https://issues.apache.org/jira/browse/PDFBOX-2666
> Project: PDFBox
> Issue Type: Bug
> Components: Utilities
> Affects Versions: 1.8.8, 1.8.9, 1.8.10
> Reporter: Michael Klink
> Labels: COSStreamArray, Contents, LayerUtility,,
> PDPageContentStream
>
> The {{LayerUtility}} method {{wrapInSaveRestore}} creates an invalid page
> *Contents* entry if applied to a {{PDPage}} to which right before an
> additional {{PDPageContentStream}} has been added.
> E.g.
> {code}
> PDDocument destinationPdfDoc = PDDocument.load(PDF_DEST);
> PDDocument externalPdf = PDDocument.load(PDF_LAYER_SOURCE);
> List<PDPage> destinationPages =
> destinationPdfDoc.getDocumentCatalog().getAllPages();
> PDPage destPage = destinationPages.get(0);
> // add additional content stream
> PDPageContentStream additionalStream = new
> PDPageContentStream(destinationPdfDoc, destPage, true, false, true);
> additionalStream.moveTo(100, 100);
> additionalStream.lineTo(200, 200);
> additionalStream.stroke();
> additionalStream.close();
> LayerUtility layerUtility = new LayerUtility(destinationPdfDoc);
> PDXObjectForm firstForm = layerUtility.importPageAsForm(externalPdf, 0);
> AffineTransform affineTransform = new AffineTransform();
> // call wrapInSaveRestore
> layerUtility.wrapInSaveRestore(destPage);
> layerUtility.appendFormAsLayer(destPage, firstForm, affineTransform,
> "external page");
> destinationPdfDoc.save(PDF_RESULT);
> destinationPdfDoc.close();
> externalPdf.close();
> {code}
> The resulting PDF contains a page like this:
> {noformat}
> 5 0 obj
> <<
> /Type /Page
> /Contents 8 0 R
> /Resources 9 0 R
> /MediaBox [0 0 595.2756 841.8898]
> /Parent 2 0 R
> >>
> 8 0 obj
> [10 0 R 11 0 R 12 0 R 13 0 R]
> endobj
> 11 0 obj
> [19 0 R 20 0 R 21 0 R]
> endobj
> {noformat}
> But *Contents* may only contain either a stream or an array of streams, but
> not an array of streams and arrays.
> This issue is due to {{LayerUtility.wrapInSaveRestore}} testing whether the
> *Contents* value is a stream or an array by
> {code}
> if (contents instanceof COSStream)
> {
> ...
> }
> else if( contents instanceof COSArray )
> {
> ...
> {code}
> but {{new PDPageContentStream(destinationPdfDoc, destPage, true, false,
> true)}} sets the *Contents* to
> {code}
> compoundStream = new COSStreamArray(newArray);
> ...
> sourcePage.setContents(new PDStream(compoundStream));
> {code}
> Thus, the *Contents* value is a {{COSStreamArray}} (which extends
> {{COSStream}}) instance which {{LayerUtility.wrapInSaveRestore}} recognizes
> as a stream but which actually represents an array of streams.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]