You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by ss...@apache.org on 2020/06/11 08:28:31 UTC

svn commit: r1878741 - in /xmlgraphics/fop-pdf-images/trunk: src/java/org/apache/fop/render/pdf/pdfbox/PDFBoxAdapter.java test/java/org/apache/fop/render/pdf/PDFBoxAdapterTestCase.java

Author: ssteiner
Date: Thu Jun 11 08:28:31 2020
New Revision: 1878741

URL: http://svn.apache.org/viewvc?rev=1878741&view=rev
Log:
FOP-2944: Only add annotations in root as input pdf does

Modified:
    xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/PDFBoxAdapter.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/PDFBoxAdapter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/PDFBoxAdapter.java?rev=1878741&r1=1878740&r2=1878741&view=diff
==============================================================================
--- xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/PDFBoxAdapter.java (original)
+++ xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/PDFBoxAdapter.java Thu Jun 11 08:28:31 2020
@@ -654,7 +654,7 @@ public class PDFBoxAdapter {
             throw new IOException("Illegal PDF. Page not part of parent page node.");
         }
 
-        Set<COSObject> fields = copyAnnotations(page);
+        Set<COSObject> fields = copyAnnotations(page, srcAcroForm);
 
         boolean formAlreadyCopied = getCachedClone(srcAcroForm) != null;
         PDFRoot catalog = this.pdfDoc.getRoot();
@@ -690,7 +690,7 @@ public class PDFBoxAdapter {
         }
     }
 
-    private Set<COSObject> copyAnnotations(PDPage page) throws IOException {
+    private Set<COSObject> copyAnnotations(PDPage page, PDAcroForm srcAcroForm) throws IOException {
         COSArray annots = (COSArray) page.getCOSObject().getDictionaryObject(COSName.ANNOTS);
         Set<COSObject> fields = Collections.emptySet();
         if (annots != null) {
@@ -700,9 +700,7 @@ public class PDFBoxAdapter {
                 exclude.add(COSName.P);
                 if (annot1 instanceof COSObject) {
                     COSObject annot = (COSObject) annot1;
-                    getField(annot, fields);
-
-
+                    getField(annot, fields, srcAcroForm);
                     if (((COSDictionary) annot.getObject()).getItem(COSName.STRUCT_PARENT) != null) {
                         exclude.add(COSName.PARENT);
                     }
@@ -731,14 +729,21 @@ public class PDFBoxAdapter {
         }
     }
 
-    private COSDictionary getField(COSObject fieldObject, Set<COSObject> fields) {
+    private COSDictionary getField(COSObject fieldObject, Set<COSObject> fields, PDAcroForm srcAcroForm) {
         COSDictionary field = (COSDictionary) fieldObject.getObject();
         COSObject parent;
         while ((parent = getParent(field)) != null) {
             fieldObject = parent;
             field = (COSDictionary) fieldObject.getObject();
         }
-        fields.add(fieldObject);
+        if (srcAcroForm != null) {
+            COSArray srcFields = (COSArray) srcAcroForm.getCOSObject().getDictionaryObject(COSName.FIELDS);
+            if (srcFields.toList().contains(fieldObject)) {
+                fields.add(fieldObject);
+            }
+        } else {
+            fields.add(fieldObject);
+        }
         return field;
     }
 

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=1878741&r1=1878740&r2=1878741&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 Thu Jun 11 08:28:31 2020
@@ -300,6 +300,27 @@ public class PDFBoxAdapterTestCase {
     }
 
     @Test
+    public void testAnnotFields() throws Exception {
+        PDFDocument pdfdoc = new PDFDocument("");
+        PDFPage pdfpage = getPDFPage(pdfdoc);
+        pdfpage.setDocument(pdfdoc);
+        pdfpage.setObjectNumber(1);
+        PDFBoxAdapter adapter = new PDFBoxAdapter(pdfpage, new HashMap(), new HashMap<Integer, PDFArray>());
+        PDDocument doc = PDDocument.load(new File(ACCESSIBLERADIOBUTTONS));
+        COSArray fields = (COSArray)
+                doc.getDocumentCatalog().getAcroForm().getCOSObject().getDictionaryObject(COSName.FIELDS);
+        fields.remove(0);
+        PDPage page = doc.getPage(0);
+        AffineTransform at = new AffineTransform();
+        Rectangle r = new Rectangle(0, 1650, 842000, 595000);
+        adapter.createStreamFromPDFBoxPage(doc, page, "key", at, null, r);
+        ByteArrayOutputStream os = new ByteArrayOutputStream();
+        pdfdoc.outputTrailer(os);
+        Assert.assertTrue(os.toString("UTF-8").contains("/Fields []"));
+        doc.close();
+    }
+
+    @Test
     public void testLink() throws Exception {
         PDFDocument pdfdoc = new PDFDocument("");
         PDFPage pdfpage = getPDFPage(pdfdoc);



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org