Author: ssteiner Date: Fri Aug 21 14:25:37 2020 New Revision: 1881059 URL: http://svn.apache.org/viewvc?rev=1881059&view=rev Log: FOP-2965: Keep streams with DCT compression
Modified: xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/PDFCloner.java xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/PDFBoxAdapterTestCase.java Modified: xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/PDFCloner.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/PDFCloner.java?rev=1881059&r1=1881058&r2=1881059&view=diff ============================================================================== --- xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/PDFCloner.java (original) +++ xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/PDFCloner.java Fri Aug 21 14:25:37 2020 @@ -42,6 +42,7 @@ import org.apache.pdfbox.cos.COSString; import org.apache.pdfbox.pdmodel.common.COSObjectable; import org.apache.pdfbox.pdmodel.common.PDStream; +import org.apache.fop.pdf.DCTFilter; import org.apache.fop.pdf.PDFArray; import org.apache.fop.pdf.PDFDictionary; import org.apache.fop.pdf.PDFDocument; @@ -174,7 +175,12 @@ public class PDFCloner { private Object readCOSStream(COSStream originalStream, Object keyBase) throws IOException { InputStream in; Set filter; - if (adapter.pdfDoc.isEncryptionActive() + PDFStream stream = new PDFStream(); + if (adapter.pdfDoc.isEncryptionActive() && originalStream.getItem(COSName.FILTER) == COSName.DCT_DECODE) { + stream.getFilterList().addFilter(new DCTFilter()); + in = originalStream.getFilteredStream(); + filter = Collections.EMPTY_SET; + } else if (adapter.pdfDoc.isEncryptionActive() || (originalStream.containsKey(COSName.DECODE_PARMS) && !originalStream.containsKey(COSName.FILTER))) { in = originalStream.getUnfilteredStream(); filter = adapter.FILTER_FILTER; @@ -183,7 +189,7 @@ public class PDFCloner { in = originalStream.getFilteredStream(); filter = Collections.EMPTY_SET; } - PDFStream stream = new PDFStream(); + OutputStream out = stream.getBufferOutputStream(); if (originalStream.getItem(COSName.SUBTYPE) == COSName.FORM && adapter.uniqueName != null) { PDFWriter writer = new PDFWriter(adapter.uniqueName, adapter.currentMCID); Modified: xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/PDFBoxAdapterTestCase.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/PDFBoxAdapterTestCase.java?rev=1881059&r1=1881058&r2=1881059&view=diff ============================================================================== --- xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/PDFBoxAdapterTestCase.java (original) +++ xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/PDFBoxAdapterTestCase.java Fri Aug 21 14:25:37 2020 @@ -75,6 +75,7 @@ import org.apache.fop.pdf.PDFAnnotList; import org.apache.fop.pdf.PDFArray; import org.apache.fop.pdf.PDFDictionary; import org.apache.fop.pdf.PDFDocument; +import org.apache.fop.pdf.PDFEncryptionParams; import org.apache.fop.pdf.PDFFilterList; import org.apache.fop.pdf.PDFFormXObject; import org.apache.fop.pdf.PDFGState; @@ -497,6 +498,17 @@ public class PDFBoxAdapterTestCase { } } + private void loadPage(PDFDocument pdfdoc, String src) throws IOException { + PDFPage pdfpage = getPDFPage(pdfdoc); + pdfdoc.assignObjectNumber(pdfpage); + pdfpage.setDocument(pdfdoc); + PDFBoxAdapter adapter = new PDFBoxAdapter(pdfpage, new HashMap(), new HashMap<Integer, PDFArray>()); + PDDocument doc = PDDocument.load(new File(src)); + PDPage page = doc.getPage(0); + adapter.createStreamFromPDFBoxPage(doc, page, "key", new AffineTransform(), null, new Rectangle()); + doc.close(); + } + @Test public void testPDFBoxImageHandler() throws Exception { ImageInfo imgi = new ImageInfo("a", "b"); @@ -682,4 +694,14 @@ public class PDFBoxAdapterTestCase { Assert.assertTrue(os.toString("UTF-8").contains("/F15106079 12 Tf")); doc.close(); } + + @Test + public void testDCTEncryption() throws IOException { + PDFDocument pdfdoc = new PDFDocument(""); + pdfdoc.setEncryption(new PDFEncryptionParams()); + loadPage(pdfdoc, IMAGE); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + pdfdoc.output(bos); + Assert.assertTrue(bos.toString("UTF-8").contains("/Filter /DCTDecode")); + } } --------------------------------------------------------------------- To unsubscribe, e-mail: fop-commits-unsubscr...@xmlgraphics.apache.org For additional commands, e-mail: fop-commits-h...@xmlgraphics.apache.org