pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From msahy...@apache.org
Subject svn commit: r1751213 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroForm.java
Date Mon, 04 Jul 2016 06:27:17 GMT
Author: msahyoun
Date: Mon Jul  4 06:27:17 2016
New Revision: 1751213

URL: http://svn.apache.org/viewvc?rev=1751213&view=rev
Log:
PDFBOX-3396: don't add a transformation if there is a XObject

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroForm.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroForm.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroForm.java?rev=1751213&r1=1751212&r2=1751213&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroForm.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroForm.java
Mon Jul  4 06:27:17 2016
@@ -45,6 +45,7 @@ import org.apache.pdfbox.pdmodel.fdf.FDF
 import org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject;
 import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation;
 import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationWidget;
+import org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceStream;
 import org.apache.pdfbox.util.Matrix;
 
 /**
@@ -248,7 +249,7 @@ public final class PDAcroForm implements
 
                     if (!isContentStreamWrapped)
                     {
-                        contentStream = new PDPageContentStream(document, page, AppendMode.APPEND,
true, true);
+                        contentStream = new PDPageContentStream(document, page, AppendMode.APPEND,
true);
                         isContentStreamWrapped = true;
                     }
                     else
@@ -256,11 +257,22 @@ public final class PDAcroForm implements
                         contentStream = new PDPageContentStream(document, page, AppendMode.APPEND,
true);
                     }
                     
-                    PDFormXObject fieldObject = new PDFormXObject(widget.getNormalAppearanceStream().getCOSObject());
+                    PDAppearanceStream appearanceStream = widget.getNormalAppearanceStream();
+                    
+                    PDFormXObject fieldObject = new PDFormXObject(appearanceStream.getCOSObject());
                     
-                    Matrix translationMatrix = Matrix.getTranslateInstance(widget.getRectangle().getLowerLeftX(),
widget.getRectangle().getLowerLeftY());
                     contentStream.saveGraphicsState();
-                    contentStream.transform(translationMatrix);
+                    
+                    // translate the appearance stream to the widget location if there is

+                    // not already a transformation in place
+                    boolean needsTransformation = isNeedsTransformation(appearanceStream);
+                    if (needsTransformation)
+                    {
+                        Matrix translationMatrix = Matrix.getTranslateInstance(widget.getRectangle().getLowerLeftX(),
+                                widget.getRectangle().getLowerLeftY());
+                        contentStream.transform(translationMatrix);
+                    }
+                    
                     contentStream.drawForm(fieldObject);
                     contentStream.restoreGraphicsState();
                     contentStream.close();
@@ -652,4 +664,22 @@ public final class PDAcroForm implements
     	}    	
     	return annotationToPageRef;
     }
+    
+    /**
+     * Check if there is a transformation needed to place the annotations content.
+     * 
+     * @param appearanceStream
+     * @return the need for a transformation.
+     */
+    private boolean isNeedsTransformation(PDAppearanceStream appearanceStream)
+    {
+        // Check if there is a XObject defined as this is an indication that there should
already be a transformation
+        // in place.
+        // TODO: A more reliable approach might be to parse the content stream
+        if (appearanceStream.getResources() != null && appearanceStream.getResources().getXObjectNames().iterator().hasNext())
+        {
+            return false;
+        }
+        return true;
+    }
 }



Mime
View raw message