You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ms...@apache.org on 2016/07/04 06:36:16 UTC
svn commit: r1751214 -
/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroForm.java
Author: msahyoun
Date: Mon Jul 4 06:36:16 2016
New Revision: 1751214
URL: http://svn.apache.org/viewvc?rev=1751214&view=rev
Log:
PDFBOX-3396: don't add a transformation if there is a XObject
Modified:
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroForm.java
Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroForm.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroForm.java?rev=1751214&r1=1751213&r2=1751214&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroForm.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroForm.java Mon Jul 4 06:36:16 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;
+ }
}