You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Rosalind Douglas (JIRA)" <ji...@apache.org> on 2019/07/30 20:48:00 UTC

[jira] [Updated] (PDFBOX-4615) AppearanceGeneratorHelper.setAppearanceValue doesn't set the bounding box on the appearance stream correctly

     [ https://issues.apache.org/jira/browse/PDFBOX-4615?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Rosalind Douglas updated PDFBOX-4615:
-------------------------------------
    Description: 
Hello, thanks for all your effort with PDFBox. We use it heavily for parsing and flattening PDFs.

In the attached PDF "resetboundingbox.pdf", we programmatically set the value of the text fields, then call pdAcroForm.flattten(), which produces the flattened PDF "flattenedboundingbox.pdf." I would expect that the text would entirely fill the text box (see textbox with {color:#8eb021}green border{color} in "flattenedboundingbox.pdf") but the text does not. Instead, the filled text area obeys another box instead (see text area with {color:#d04437}red border{color} in "flattenedboundingbox.pdf").

We've traced the problem to AppearanceGeneratorHelper.setAppearanceValue, lines 200-210. As long as we always set the bounding box (line 243) like in AppearanceGeneratorHelper.prepareNormalAppearanceStream, regardless of the if/else at line 200, then the flattening works correctly:
{code:java}
/** * replace AppearanceGeneratorHelper lines 199-210 with: */ 
PDAppearanceStream appearanceStream = appearance != null && appearance.isStream() ? appearance.getAppearanceStream() : prepareNormalAppearanceStream(widget); 
// copied from lines 237-243 
int rotation = resolveRotation(widget);
PDRectangle rect = widget.getRectangle(); 
Matrix matrix = Matrix.getRotateInstance(Math.toRadians(rotation), 0, 0); 
Point2D.Float point2D = matrix.transformPoint(rect.getWidth(), rect.getHeight()); 
PDRectangle bbox = new PDRectangle(Math.abs((float) point2D.getX()), Math.abs((float) point2D.getY())); 
appearanceStream.setBBox(bbox); 

appearanceDict.setNormalAppearance(appearanceStream);
{code}
Something I'm not sure about: in method prepareNormalAppearanceStream, there is additional code for setting the matrix (lines 245-251), which we don't seem to need. Since it doesn't break anything, we just keep it too.

Thanks again for your help!

  was:
Hello, thanks for all your effort with PDFBox. We use it heavily for parsing and flattening PDFs.

In the attached PDF "resetboundingbox.pdf", we programmatically set the value of the text fields, then call pdAcroForm.flattten(), which produces the flattened PDF "flattenedboundingbox.pdf." I would expect that the text would entirely fill the text box (see textbox with green border in "flattenedboundingbox.pdf") but the text does not. Instead, the filled text area obeys another box instead (see text area with red border in "flattenedboundingbox.pdf").

We've traced the problem to AppearanceGeneratorHelper.setAppearanceValue, lines 200-210. As long as we always set the bounding box (line 243) like in AppearanceGeneratorHelper.prepareNormalAppearanceStream, regardless of the if/else at line 200, then the flattening works correctly:
{code:java}
/** * replace AppearanceGeneratorHelper lines 199-210 with: */ 
PDAppearanceStream appearanceStream = appearance != null && appearance.isStream() ? appearance.getAppearanceStream() : prepareNormalAppearanceStream(widget); 
// copied from lines 237-243 
int rotation = resolveRotation(widget);
PDRectangle rect = widget.getRectangle(); 
Matrix matrix = Matrix.getRotateInstance(Math.toRadians(rotation), 0, 0); 
Point2D.Float point2D = matrix.transformPoint(rect.getWidth(), rect.getHeight()); 
PDRectangle bbox = new PDRectangle(Math.abs((float) point2D.getX()), Math.abs((float) point2D.getY())); 
appearanceStream.setBBox(bbox); 

appearanceDict.setNormalAppearance(appearanceStream);
{code}
Something I'm not sure about: in method prepareNormalAppearanceStream, there is additional code for setting the matrix (lines 245-251), which we don't seem to need. Since it doesn't break anything, we just keep it too.

Thanks again for your help!


> AppearanceGeneratorHelper.setAppearanceValue doesn't set the bounding box on the appearance stream correctly
> ------------------------------------------------------------------------------------------------------------
>
>                 Key: PDFBOX-4615
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-4615
>             Project: PDFBox
>          Issue Type: Bug
>          Components: PDModel
>    Affects Versions: 2.0.16
>            Reporter: Rosalind Douglas
>            Priority: Major
>         Attachments: flattenedboundingbox.pdf, resetboundingbox.pdf
>
>
> Hello, thanks for all your effort with PDFBox. We use it heavily for parsing and flattening PDFs.
> In the attached PDF "resetboundingbox.pdf", we programmatically set the value of the text fields, then call pdAcroForm.flattten(), which produces the flattened PDF "flattenedboundingbox.pdf." I would expect that the text would entirely fill the text box (see textbox with {color:#8eb021}green border{color} in "flattenedboundingbox.pdf") but the text does not. Instead, the filled text area obeys another box instead (see text area with {color:#d04437}red border{color} in "flattenedboundingbox.pdf").
> We've traced the problem to AppearanceGeneratorHelper.setAppearanceValue, lines 200-210. As long as we always set the bounding box (line 243) like in AppearanceGeneratorHelper.prepareNormalAppearanceStream, regardless of the if/else at line 200, then the flattening works correctly:
> {code:java}
> /** * replace AppearanceGeneratorHelper lines 199-210 with: */ 
> PDAppearanceStream appearanceStream = appearance != null && appearance.isStream() ? appearance.getAppearanceStream() : prepareNormalAppearanceStream(widget); 
> // copied from lines 237-243 
> int rotation = resolveRotation(widget);
> PDRectangle rect = widget.getRectangle(); 
> Matrix matrix = Matrix.getRotateInstance(Math.toRadians(rotation), 0, 0); 
> Point2D.Float point2D = matrix.transformPoint(rect.getWidth(), rect.getHeight()); 
> PDRectangle bbox = new PDRectangle(Math.abs((float) point2D.getX()), Math.abs((float) point2D.getY())); 
> appearanceStream.setBBox(bbox); 
> appearanceDict.setNormalAppearance(appearanceStream);
> {code}
> Something I'm not sure about: in method prepareNormalAppearanceStream, there is additional code for setting the matrix (lines 245-251), which we don't seem to need. Since it doesn't break anything, we just keep it too.
> Thanks again for your help!



--
This message was sent by Atlassian JIRA
(v7.6.14#76016)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org