[jira] [Commented] (PDFBOX-4631) NPE due to bounding box not being set on PDAppearanceStream

2019-08-16 Thread Tilman Hausherr (JIRA)


[ 
https://issues.apache.org/jira/browse/PDFBOX-4631?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16909189#comment-16909189
 ] 

Tilman Hausherr commented on PDFBOX-4631:
-

[~sjoblomj] please retry with this new version and check that your result file 
is what you'd expect.

> NPE due to bounding box not being set on PDAppearanceStream
> ---
>
> Key: PDFBOX-4631
> URL: https://issues.apache.org/jira/browse/PDFBOX-4631
> Project: PDFBox
>  Issue Type: Bug
>  Components: AcroForm
>Affects Versions: 2.0.16
> Environment: Windows 10
>Reporter: sjoblomj
>Priority: Major
> Fix For: 2.0.17, 3.0.0 PDFBox
>
> Attachments: PdfBoxTest.java, bidragsoknad_strange-content.pdf
>
>
> PDFBox 2.0.16 as well as the current SNAPSNOT version crashes with a 
> NullPointerException. Attached is a small test that triggers the NPE, as well 
> as the PDF.
> The stack trace:
> {code:java}
> java.lang.NullPointerException
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.applyPadding(AppearanceGeneratorHelper.java:816)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.insertGeneratedCombAppearance(AppearanceGeneratorHelper.java:611)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.insertGeneratedAppearance(AppearanceGeneratorHelper.java:505)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.setAppearanceContent(AppearanceGeneratorHelper.java:374)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.setAppearanceValue(AppearanceGeneratorHelper.java:223)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.PDTextField.constructAppearances(PDTextField.java:264)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.PDTerminalField.applyChange(PDTerminalField.java:228)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.PDTextField.setValue(PDTextField.java:219)
>     at PdfBoxTest.reformatFields(PdfBoxTest.java:67)
>     at PdfBoxTest.flattenDocument(PdfBoxTest.java:52)
>     at PdfBoxTest.flatten(PdfBoxTest.java:42)
>     at PdfBoxTest.fileWithStrangeContent(PdfBoxTest.java:27){code}
>  
> The origin of the error seems to be in 
> {{AppearanceGeneratorHelper.setAppearanceValue()}}. A PDAppearanceStream is 
> created, but a bounding box is only set for it if this is false: {{if 
> (appearance != null && appearance.isStream())}}. In my case, the conditional 
> is true, and PDFBox takes a path where no bounding box gets set.
> The following could be a solution, but I'm not very fluent in the inner 
> workings of PDFs, and it's not directly obvious from looking at the code that 
> this is a good approach.
> {code:java}
> diff --git 
> a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
>  
> b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
> index dc2825d4c..a82236069 100644
> --- 
> a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
> +++ 
> b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
> @@ -201,6 +201,7 @@ class AppearanceGeneratorHelper
>  if (appearance != null && appearance.isStream())
>  {
>  appearanceStream = appearance.getAppearanceStream();
> +setBoundingBoxOnAppearanceStream(widget, 
> appearanceStream);
>  }
>  else
>  {
> @@ -235,15 +236,9 @@ class AppearanceGeneratorHelper
>  // Calculate the entries for the bounding box and the transformation 
> matrix
>  // settings for the appearance stream
> -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());
> +setBoundingBoxOnAppearanceStream(widget, appearanceStream);
> -PDRectangle bbox = new PDRectangle(Math.abs((float) point2D.getX()), 
> Math.abs((float) point2D.getY()));
> -appearanceStream.setBBox(bbox);
> -
> -AffineTransform at = calculateMatrix(bbox, rotation);
> +AffineTransform at = calculateMatrix(appearanceStream.getBBox(), 
> resolveRotation(widget));
>  if (!at.isIdentity())
>  {
>  appearanceStream.setMatrix(at);
> @@ -252,7 +247,17 @@ class AppearanceGeneratorHelper
>  appearanceStream.setResources(new PDResources());
>  return appearanceStream;
>  }
> -
> +
> +private void setBoundingBoxOnAppearanceStream(PDAnnotationWidget widget, 

[jira] [Commented] (PDFBOX-4631) NPE due to bounding box not being set on PDAppearanceStream

2019-08-16 Thread ASF subversion and git services (JIRA)


[ 
https://issues.apache.org/jira/browse/PDFBOX-4631?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16909188#comment-16909188
 ] 

ASF subversion and git services commented on PDFBOX-4631:
-

Commit 1865323 from Tilman Hausherr in branch 'pdfbox/trunk'
[ https://svn.apache.org/r1865323 ]

PDFBOX-4631: avoid NPE

> NPE due to bounding box not being set on PDAppearanceStream
> ---
>
> Key: PDFBOX-4631
> URL: https://issues.apache.org/jira/browse/PDFBOX-4631
> Project: PDFBox
>  Issue Type: Bug
>  Components: AcroForm
>Affects Versions: 2.0.16
> Environment: Windows 10
>Reporter: sjoblomj
>Priority: Major
> Fix For: 2.0.17, 3.0.0 PDFBox
>
> Attachments: PdfBoxTest.java, bidragsoknad_strange-content.pdf
>
>
> PDFBox 2.0.16 as well as the current SNAPSNOT version crashes with a 
> NullPointerException. Attached is a small test that triggers the NPE, as well 
> as the PDF.
> The stack trace:
> {code:java}
> java.lang.NullPointerException
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.applyPadding(AppearanceGeneratorHelper.java:816)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.insertGeneratedCombAppearance(AppearanceGeneratorHelper.java:611)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.insertGeneratedAppearance(AppearanceGeneratorHelper.java:505)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.setAppearanceContent(AppearanceGeneratorHelper.java:374)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.setAppearanceValue(AppearanceGeneratorHelper.java:223)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.PDTextField.constructAppearances(PDTextField.java:264)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.PDTerminalField.applyChange(PDTerminalField.java:228)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.PDTextField.setValue(PDTextField.java:219)
>     at PdfBoxTest.reformatFields(PdfBoxTest.java:67)
>     at PdfBoxTest.flattenDocument(PdfBoxTest.java:52)
>     at PdfBoxTest.flatten(PdfBoxTest.java:42)
>     at PdfBoxTest.fileWithStrangeContent(PdfBoxTest.java:27){code}
>  
> The origin of the error seems to be in 
> {{AppearanceGeneratorHelper.setAppearanceValue()}}. A PDAppearanceStream is 
> created, but a bounding box is only set for it if this is false: {{if 
> (appearance != null && appearance.isStream())}}. In my case, the conditional 
> is true, and PDFBox takes a path where no bounding box gets set.
> The following could be a solution, but I'm not very fluent in the inner 
> workings of PDFs, and it's not directly obvious from looking at the code that 
> this is a good approach.
> {code:java}
> diff --git 
> a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
>  
> b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
> index dc2825d4c..a82236069 100644
> --- 
> a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
> +++ 
> b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
> @@ -201,6 +201,7 @@ class AppearanceGeneratorHelper
>  if (appearance != null && appearance.isStream())
>  {
>  appearanceStream = appearance.getAppearanceStream();
> +setBoundingBoxOnAppearanceStream(widget, 
> appearanceStream);
>  }
>  else
>  {
> @@ -235,15 +236,9 @@ class AppearanceGeneratorHelper
>  // Calculate the entries for the bounding box and the transformation 
> matrix
>  // settings for the appearance stream
> -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());
> +setBoundingBoxOnAppearanceStream(widget, appearanceStream);
> -PDRectangle bbox = new PDRectangle(Math.abs((float) point2D.getX()), 
> Math.abs((float) point2D.getY()));
> -appearanceStream.setBBox(bbox);
> -
> -AffineTransform at = calculateMatrix(bbox, rotation);
> +AffineTransform at = calculateMatrix(appearanceStream.getBBox(), 
> resolveRotation(widget));
>  if (!at.isIdentity())
>  {
>  appearanceStream.setMatrix(at);
> @@ -252,7 +247,17 @@ class AppearanceGeneratorHelper
>  appearanceStream.setResources(new PDResources());
>  return appearanceStream;
>  }
> -
> +
> +private void 

[jira] [Commented] (PDFBOX-4631) NPE due to bounding box not being set on PDAppearanceStream

2019-08-16 Thread ASF subversion and git services (JIRA)


[ 
https://issues.apache.org/jira/browse/PDFBOX-4631?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16909185#comment-16909185
 ] 

ASF subversion and git services commented on PDFBOX-4631:
-

Commit 1865320 from Tilman Hausherr in branch 'pdfbox/branches/issue4569'
[ https://svn.apache.org/r1865320 ]

PDFBOX-4631: avoid NPE

> NPE due to bounding box not being set on PDAppearanceStream
> ---
>
> Key: PDFBOX-4631
> URL: https://issues.apache.org/jira/browse/PDFBOX-4631
> Project: PDFBox
>  Issue Type: Bug
>  Components: AcroForm
>Affects Versions: 2.0.16
> Environment: Windows 10
>Reporter: sjoblomj
>Priority: Major
> Fix For: 2.0.17, 3.0.0 PDFBox
>
> Attachments: PdfBoxTest.java, bidragsoknad_strange-content.pdf
>
>
> PDFBox 2.0.16 as well as the current SNAPSNOT version crashes with a 
> NullPointerException. Attached is a small test that triggers the NPE, as well 
> as the PDF.
> The stack trace:
> {code:java}
> java.lang.NullPointerException
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.applyPadding(AppearanceGeneratorHelper.java:816)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.insertGeneratedCombAppearance(AppearanceGeneratorHelper.java:611)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.insertGeneratedAppearance(AppearanceGeneratorHelper.java:505)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.setAppearanceContent(AppearanceGeneratorHelper.java:374)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.setAppearanceValue(AppearanceGeneratorHelper.java:223)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.PDTextField.constructAppearances(PDTextField.java:264)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.PDTerminalField.applyChange(PDTerminalField.java:228)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.PDTextField.setValue(PDTextField.java:219)
>     at PdfBoxTest.reformatFields(PdfBoxTest.java:67)
>     at PdfBoxTest.flattenDocument(PdfBoxTest.java:52)
>     at PdfBoxTest.flatten(PdfBoxTest.java:42)
>     at PdfBoxTest.fileWithStrangeContent(PdfBoxTest.java:27){code}
>  
> The origin of the error seems to be in 
> {{AppearanceGeneratorHelper.setAppearanceValue()}}. A PDAppearanceStream is 
> created, but a bounding box is only set for it if this is false: {{if 
> (appearance != null && appearance.isStream())}}. In my case, the conditional 
> is true, and PDFBox takes a path where no bounding box gets set.
> The following could be a solution, but I'm not very fluent in the inner 
> workings of PDFs, and it's not directly obvious from looking at the code that 
> this is a good approach.
> {code:java}
> diff --git 
> a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
>  
> b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
> index dc2825d4c..a82236069 100644
> --- 
> a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
> +++ 
> b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
> @@ -201,6 +201,7 @@ class AppearanceGeneratorHelper
>  if (appearance != null && appearance.isStream())
>  {
>  appearanceStream = appearance.getAppearanceStream();
> +setBoundingBoxOnAppearanceStream(widget, 
> appearanceStream);
>  }
>  else
>  {
> @@ -235,15 +236,9 @@ class AppearanceGeneratorHelper
>  // Calculate the entries for the bounding box and the transformation 
> matrix
>  // settings for the appearance stream
> -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());
> +setBoundingBoxOnAppearanceStream(widget, appearanceStream);
> -PDRectangle bbox = new PDRectangle(Math.abs((float) point2D.getX()), 
> Math.abs((float) point2D.getY()));
> -appearanceStream.setBBox(bbox);
> -
> -AffineTransform at = calculateMatrix(bbox, rotation);
> +AffineTransform at = calculateMatrix(appearanceStream.getBBox(), 
> resolveRotation(widget));
>  if (!at.isIdentity())
>  {
>  appearanceStream.setMatrix(at);
> @@ -252,7 +247,17 @@ class AppearanceGeneratorHelper
>  appearanceStream.setResources(new PDResources());
>  return appearanceStream;
>  }
> -
> +
> +private 

[jira] [Commented] (PDFBOX-4631) NPE due to bounding box not being set on PDAppearanceStream

2019-08-16 Thread ASF subversion and git services (JIRA)


[ 
https://issues.apache.org/jira/browse/PDFBOX-4631?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16909187#comment-16909187
 ] 

ASF subversion and git services commented on PDFBOX-4631:
-

Commit 1865322 from Tilman Hausherr in branch 'pdfbox/branches/2.0'
[ https://svn.apache.org/r1865322 ]

PDFBOX-4631: avoid NPE

> NPE due to bounding box not being set on PDAppearanceStream
> ---
>
> Key: PDFBOX-4631
> URL: https://issues.apache.org/jira/browse/PDFBOX-4631
> Project: PDFBox
>  Issue Type: Bug
>  Components: AcroForm
>Affects Versions: 2.0.16
> Environment: Windows 10
>Reporter: sjoblomj
>Priority: Major
> Fix For: 2.0.17, 3.0.0 PDFBox
>
> Attachments: PdfBoxTest.java, bidragsoknad_strange-content.pdf
>
>
> PDFBox 2.0.16 as well as the current SNAPSNOT version crashes with a 
> NullPointerException. Attached is a small test that triggers the NPE, as well 
> as the PDF.
> The stack trace:
> {code:java}
> java.lang.NullPointerException
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.applyPadding(AppearanceGeneratorHelper.java:816)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.insertGeneratedCombAppearance(AppearanceGeneratorHelper.java:611)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.insertGeneratedAppearance(AppearanceGeneratorHelper.java:505)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.setAppearanceContent(AppearanceGeneratorHelper.java:374)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.setAppearanceValue(AppearanceGeneratorHelper.java:223)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.PDTextField.constructAppearances(PDTextField.java:264)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.PDTerminalField.applyChange(PDTerminalField.java:228)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.PDTextField.setValue(PDTextField.java:219)
>     at PdfBoxTest.reformatFields(PdfBoxTest.java:67)
>     at PdfBoxTest.flattenDocument(PdfBoxTest.java:52)
>     at PdfBoxTest.flatten(PdfBoxTest.java:42)
>     at PdfBoxTest.fileWithStrangeContent(PdfBoxTest.java:27){code}
>  
> The origin of the error seems to be in 
> {{AppearanceGeneratorHelper.setAppearanceValue()}}. A PDAppearanceStream is 
> created, but a bounding box is only set for it if this is false: {{if 
> (appearance != null && appearance.isStream())}}. In my case, the conditional 
> is true, and PDFBox takes a path where no bounding box gets set.
> The following could be a solution, but I'm not very fluent in the inner 
> workings of PDFs, and it's not directly obvious from looking at the code that 
> this is a good approach.
> {code:java}
> diff --git 
> a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
>  
> b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
> index dc2825d4c..a82236069 100644
> --- 
> a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
> +++ 
> b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
> @@ -201,6 +201,7 @@ class AppearanceGeneratorHelper
>  if (appearance != null && appearance.isStream())
>  {
>  appearanceStream = appearance.getAppearanceStream();
> +setBoundingBoxOnAppearanceStream(widget, 
> appearanceStream);
>  }
>  else
>  {
> @@ -235,15 +236,9 @@ class AppearanceGeneratorHelper
>  // Calculate the entries for the bounding box and the transformation 
> matrix
>  // settings for the appearance stream
> -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());
> +setBoundingBoxOnAppearanceStream(widget, appearanceStream);
> -PDRectangle bbox = new PDRectangle(Math.abs((float) point2D.getX()), 
> Math.abs((float) point2D.getY()));
> -appearanceStream.setBBox(bbox);
> -
> -AffineTransform at = calculateMatrix(bbox, rotation);
> +AffineTransform at = calculateMatrix(appearanceStream.getBBox(), 
> resolveRotation(widget));
>  if (!at.isIdentity())
>  {
>  appearanceStream.setMatrix(at);
> @@ -252,7 +247,17 @@ class AppearanceGeneratorHelper
>  appearanceStream.setResources(new PDResources());
>  return appearanceStream;
>  }
> -
> +
> +private void 

[jira] [Commented] (PDFBOX-4631) NPE due to bounding box not being set on PDAppearanceStream

2019-08-16 Thread ASF subversion and git services (JIRA)


[ 
https://issues.apache.org/jira/browse/PDFBOX-4631?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16909186#comment-16909186
 ] 

ASF subversion and git services commented on PDFBOX-4631:
-

Commit 1865321 from Tilman Hausherr in branch 'pdfbox/branches/issue45'
[ https://svn.apache.org/r1865321 ]

PDFBOX-4631: avoid NPE

> NPE due to bounding box not being set on PDAppearanceStream
> ---
>
> Key: PDFBOX-4631
> URL: https://issues.apache.org/jira/browse/PDFBOX-4631
> Project: PDFBox
>  Issue Type: Bug
>  Components: AcroForm
>Affects Versions: 2.0.16
> Environment: Windows 10
>Reporter: sjoblomj
>Priority: Major
> Fix For: 2.0.17, 3.0.0 PDFBox
>
> Attachments: PdfBoxTest.java, bidragsoknad_strange-content.pdf
>
>
> PDFBox 2.0.16 as well as the current SNAPSNOT version crashes with a 
> NullPointerException. Attached is a small test that triggers the NPE, as well 
> as the PDF.
> The stack trace:
> {code:java}
> java.lang.NullPointerException
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.applyPadding(AppearanceGeneratorHelper.java:816)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.insertGeneratedCombAppearance(AppearanceGeneratorHelper.java:611)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.insertGeneratedAppearance(AppearanceGeneratorHelper.java:505)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.setAppearanceContent(AppearanceGeneratorHelper.java:374)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.setAppearanceValue(AppearanceGeneratorHelper.java:223)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.PDTextField.constructAppearances(PDTextField.java:264)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.PDTerminalField.applyChange(PDTerminalField.java:228)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.PDTextField.setValue(PDTextField.java:219)
>     at PdfBoxTest.reformatFields(PdfBoxTest.java:67)
>     at PdfBoxTest.flattenDocument(PdfBoxTest.java:52)
>     at PdfBoxTest.flatten(PdfBoxTest.java:42)
>     at PdfBoxTest.fileWithStrangeContent(PdfBoxTest.java:27){code}
>  
> The origin of the error seems to be in 
> {{AppearanceGeneratorHelper.setAppearanceValue()}}. A PDAppearanceStream is 
> created, but a bounding box is only set for it if this is false: {{if 
> (appearance != null && appearance.isStream())}}. In my case, the conditional 
> is true, and PDFBox takes a path where no bounding box gets set.
> The following could be a solution, but I'm not very fluent in the inner 
> workings of PDFs, and it's not directly obvious from looking at the code that 
> this is a good approach.
> {code:java}
> diff --git 
> a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
>  
> b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
> index dc2825d4c..a82236069 100644
> --- 
> a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
> +++ 
> b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
> @@ -201,6 +201,7 @@ class AppearanceGeneratorHelper
>  if (appearance != null && appearance.isStream())
>  {
>  appearanceStream = appearance.getAppearanceStream();
> +setBoundingBoxOnAppearanceStream(widget, 
> appearanceStream);
>  }
>  else
>  {
> @@ -235,15 +236,9 @@ class AppearanceGeneratorHelper
>  // Calculate the entries for the bounding box and the transformation 
> matrix
>  // settings for the appearance stream
> -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());
> +setBoundingBoxOnAppearanceStream(widget, appearanceStream);
> -PDRectangle bbox = new PDRectangle(Math.abs((float) point2D.getX()), 
> Math.abs((float) point2D.getY()));
> -appearanceStream.setBBox(bbox);
> -
> -AffineTransform at = calculateMatrix(bbox, rotation);
> +AffineTransform at = calculateMatrix(appearanceStream.getBBox(), 
> resolveRotation(widget));
>  if (!at.isIdentity())
>  {
>  appearanceStream.setMatrix(at);
> @@ -252,7 +247,17 @@ class AppearanceGeneratorHelper
>  appearanceStream.setResources(new PDResources());
>  return appearanceStream;
>  }
> -
> +
> +private 

[jira] [Commented] (PDFBOX-4631) NPE due to bounding box not being set on PDAppearanceStream

2019-08-16 Thread ASF subversion and git services (JIRA)


[ 
https://issues.apache.org/jira/browse/PDFBOX-4631?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16909181#comment-16909181
 ] 

ASF subversion and git services commented on PDFBOX-4631:
-

Commit 1865317 from Tilman Hausherr in branch 'pdfbox/branches/2.0'
[ https://svn.apache.org/r1865317 ]

PDFBOX-4631: avoid NPE

> NPE due to bounding box not being set on PDAppearanceStream
> ---
>
> Key: PDFBOX-4631
> URL: https://issues.apache.org/jira/browse/PDFBOX-4631
> Project: PDFBox
>  Issue Type: Bug
>  Components: AcroForm
>Affects Versions: 2.0.16
> Environment: Windows 10
>Reporter: sjoblomj
>Priority: Major
> Fix For: 2.0.17, 3.0.0 PDFBox
>
> Attachments: PdfBoxTest.java, bidragsoknad_strange-content.pdf
>
>
> PDFBox 2.0.16 as well as the current SNAPSNOT version crashes with a 
> NullPointerException. Attached is a small test that triggers the NPE, as well 
> as the PDF.
> The stack trace:
> {code:java}
> java.lang.NullPointerException
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.applyPadding(AppearanceGeneratorHelper.java:816)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.insertGeneratedCombAppearance(AppearanceGeneratorHelper.java:611)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.insertGeneratedAppearance(AppearanceGeneratorHelper.java:505)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.setAppearanceContent(AppearanceGeneratorHelper.java:374)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.setAppearanceValue(AppearanceGeneratorHelper.java:223)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.PDTextField.constructAppearances(PDTextField.java:264)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.PDTerminalField.applyChange(PDTerminalField.java:228)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.PDTextField.setValue(PDTextField.java:219)
>     at PdfBoxTest.reformatFields(PdfBoxTest.java:67)
>     at PdfBoxTest.flattenDocument(PdfBoxTest.java:52)
>     at PdfBoxTest.flatten(PdfBoxTest.java:42)
>     at PdfBoxTest.fileWithStrangeContent(PdfBoxTest.java:27){code}
>  
> The origin of the error seems to be in 
> {{AppearanceGeneratorHelper.setAppearanceValue()}}. A PDAppearanceStream is 
> created, but a bounding box is only set for it if this is false: {{if 
> (appearance != null && appearance.isStream())}}. In my case, the conditional 
> is true, and PDFBox takes a path where no bounding box gets set.
> The following could be a solution, but I'm not very fluent in the inner 
> workings of PDFs, and it's not directly obvious from looking at the code that 
> this is a good approach.
> {code:java}
> diff --git 
> a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
>  
> b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
> index dc2825d4c..a82236069 100644
> --- 
> a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
> +++ 
> b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
> @@ -201,6 +201,7 @@ class AppearanceGeneratorHelper
>  if (appearance != null && appearance.isStream())
>  {
>  appearanceStream = appearance.getAppearanceStream();
> +setBoundingBoxOnAppearanceStream(widget, 
> appearanceStream);
>  }
>  else
>  {
> @@ -235,15 +236,9 @@ class AppearanceGeneratorHelper
>  // Calculate the entries for the bounding box and the transformation 
> matrix
>  // settings for the appearance stream
> -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());
> +setBoundingBoxOnAppearanceStream(widget, appearanceStream);
> -PDRectangle bbox = new PDRectangle(Math.abs((float) point2D.getX()), 
> Math.abs((float) point2D.getY()));
> -appearanceStream.setBBox(bbox);
> -
> -AffineTransform at = calculateMatrix(bbox, rotation);
> +AffineTransform at = calculateMatrix(appearanceStream.getBBox(), 
> resolveRotation(widget));
>  if (!at.isIdentity())
>  {
>  appearanceStream.setMatrix(at);
> @@ -252,7 +247,17 @@ class AppearanceGeneratorHelper
>  appearanceStream.setResources(new PDResources());
>  return appearanceStream;
>  }
> -
> +
> +private void 

[jira] [Commented] (PDFBOX-4631) NPE due to bounding box not being set on PDAppearanceStream

2019-08-16 Thread ASF subversion and git services (JIRA)


[ 
https://issues.apache.org/jira/browse/PDFBOX-4631?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16909180#comment-16909180
 ] 

ASF subversion and git services commented on PDFBOX-4631:
-

Commit 1865316 from Tilman Hausherr in branch 'pdfbox/branches/issue4569'
[ https://svn.apache.org/r1865316 ]

PDFBOX-4631: avoid NPE

> NPE due to bounding box not being set on PDAppearanceStream
> ---
>
> Key: PDFBOX-4631
> URL: https://issues.apache.org/jira/browse/PDFBOX-4631
> Project: PDFBox
>  Issue Type: Bug
>  Components: AcroForm
>Affects Versions: 2.0.16
> Environment: Windows 10
>Reporter: sjoblomj
>Priority: Major
> Fix For: 2.0.17, 3.0.0 PDFBox
>
> Attachments: PdfBoxTest.java, bidragsoknad_strange-content.pdf
>
>
> PDFBox 2.0.16 as well as the current SNAPSNOT version crashes with a 
> NullPointerException. Attached is a small test that triggers the NPE, as well 
> as the PDF.
> The stack trace:
> {code:java}
> java.lang.NullPointerException
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.applyPadding(AppearanceGeneratorHelper.java:816)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.insertGeneratedCombAppearance(AppearanceGeneratorHelper.java:611)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.insertGeneratedAppearance(AppearanceGeneratorHelper.java:505)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.setAppearanceContent(AppearanceGeneratorHelper.java:374)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.setAppearanceValue(AppearanceGeneratorHelper.java:223)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.PDTextField.constructAppearances(PDTextField.java:264)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.PDTerminalField.applyChange(PDTerminalField.java:228)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.PDTextField.setValue(PDTextField.java:219)
>     at PdfBoxTest.reformatFields(PdfBoxTest.java:67)
>     at PdfBoxTest.flattenDocument(PdfBoxTest.java:52)
>     at PdfBoxTest.flatten(PdfBoxTest.java:42)
>     at PdfBoxTest.fileWithStrangeContent(PdfBoxTest.java:27){code}
>  
> The origin of the error seems to be in 
> {{AppearanceGeneratorHelper.setAppearanceValue()}}. A PDAppearanceStream is 
> created, but a bounding box is only set for it if this is false: {{if 
> (appearance != null && appearance.isStream())}}. In my case, the conditional 
> is true, and PDFBox takes a path where no bounding box gets set.
> The following could be a solution, but I'm not very fluent in the inner 
> workings of PDFs, and it's not directly obvious from looking at the code that 
> this is a good approach.
> {code:java}
> diff --git 
> a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
>  
> b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
> index dc2825d4c..a82236069 100644
> --- 
> a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
> +++ 
> b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
> @@ -201,6 +201,7 @@ class AppearanceGeneratorHelper
>  if (appearance != null && appearance.isStream())
>  {
>  appearanceStream = appearance.getAppearanceStream();
> +setBoundingBoxOnAppearanceStream(widget, 
> appearanceStream);
>  }
>  else
>  {
> @@ -235,15 +236,9 @@ class AppearanceGeneratorHelper
>  // Calculate the entries for the bounding box and the transformation 
> matrix
>  // settings for the appearance stream
> -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());
> +setBoundingBoxOnAppearanceStream(widget, appearanceStream);
> -PDRectangle bbox = new PDRectangle(Math.abs((float) point2D.getX()), 
> Math.abs((float) point2D.getY()));
> -appearanceStream.setBBox(bbox);
> -
> -AffineTransform at = calculateMatrix(bbox, rotation);
> +AffineTransform at = calculateMatrix(appearanceStream.getBBox(), 
> resolveRotation(widget));
>  if (!at.isIdentity())
>  {
>  appearanceStream.setMatrix(at);
> @@ -252,7 +247,17 @@ class AppearanceGeneratorHelper
>  appearanceStream.setResources(new PDResources());
>  return appearanceStream;
>  }
> -
> +
> +private 

[jira] [Commented] (PDFBOX-4631) NPE due to bounding box not being set on PDAppearanceStream

2019-08-16 Thread ASF subversion and git services (JIRA)


[ 
https://issues.apache.org/jira/browse/PDFBOX-4631?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16909182#comment-16909182
 ] 

ASF subversion and git services commented on PDFBOX-4631:
-

Commit 1865318 from Tilman Hausherr in branch 'pdfbox/trunk'
[ https://svn.apache.org/r1865318 ]

PDFBOX-4631: avoid NPE

> NPE due to bounding box not being set on PDAppearanceStream
> ---
>
> Key: PDFBOX-4631
> URL: https://issues.apache.org/jira/browse/PDFBOX-4631
> Project: PDFBox
>  Issue Type: Bug
>  Components: AcroForm
>Affects Versions: 2.0.16
> Environment: Windows 10
>Reporter: sjoblomj
>Priority: Major
> Fix For: 2.0.17, 3.0.0 PDFBox
>
> Attachments: PdfBoxTest.java, bidragsoknad_strange-content.pdf
>
>
> PDFBox 2.0.16 as well as the current SNAPSNOT version crashes with a 
> NullPointerException. Attached is a small test that triggers the NPE, as well 
> as the PDF.
> The stack trace:
> {code:java}
> java.lang.NullPointerException
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.applyPadding(AppearanceGeneratorHelper.java:816)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.insertGeneratedCombAppearance(AppearanceGeneratorHelper.java:611)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.insertGeneratedAppearance(AppearanceGeneratorHelper.java:505)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.setAppearanceContent(AppearanceGeneratorHelper.java:374)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.setAppearanceValue(AppearanceGeneratorHelper.java:223)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.PDTextField.constructAppearances(PDTextField.java:264)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.PDTerminalField.applyChange(PDTerminalField.java:228)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.PDTextField.setValue(PDTextField.java:219)
>     at PdfBoxTest.reformatFields(PdfBoxTest.java:67)
>     at PdfBoxTest.flattenDocument(PdfBoxTest.java:52)
>     at PdfBoxTest.flatten(PdfBoxTest.java:42)
>     at PdfBoxTest.fileWithStrangeContent(PdfBoxTest.java:27){code}
>  
> The origin of the error seems to be in 
> {{AppearanceGeneratorHelper.setAppearanceValue()}}. A PDAppearanceStream is 
> created, but a bounding box is only set for it if this is false: {{if 
> (appearance != null && appearance.isStream())}}. In my case, the conditional 
> is true, and PDFBox takes a path where no bounding box gets set.
> The following could be a solution, but I'm not very fluent in the inner 
> workings of PDFs, and it's not directly obvious from looking at the code that 
> this is a good approach.
> {code:java}
> diff --git 
> a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
>  
> b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
> index dc2825d4c..a82236069 100644
> --- 
> a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
> +++ 
> b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
> @@ -201,6 +201,7 @@ class AppearanceGeneratorHelper
>  if (appearance != null && appearance.isStream())
>  {
>  appearanceStream = appearance.getAppearanceStream();
> +setBoundingBoxOnAppearanceStream(widget, 
> appearanceStream);
>  }
>  else
>  {
> @@ -235,15 +236,9 @@ class AppearanceGeneratorHelper
>  // Calculate the entries for the bounding box and the transformation 
> matrix
>  // settings for the appearance stream
> -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());
> +setBoundingBoxOnAppearanceStream(widget, appearanceStream);
> -PDRectangle bbox = new PDRectangle(Math.abs((float) point2D.getX()), 
> Math.abs((float) point2D.getY()));
> -appearanceStream.setBBox(bbox);
> -
> -AffineTransform at = calculateMatrix(bbox, rotation);
> +AffineTransform at = calculateMatrix(appearanceStream.getBBox(), 
> resolveRotation(widget));
>  if (!at.isIdentity())
>  {
>  appearanceStream.setMatrix(at);
> @@ -252,7 +247,17 @@ class AppearanceGeneratorHelper
>  appearanceStream.setResources(new PDResources());
>  return appearanceStream;
>  }
> -
> +
> +private void 

[jira] [Commented] (PDFBOX-4631) NPE due to bounding box not being set on PDAppearanceStream

2019-08-16 Thread ASF subversion and git services (JIRA)


[ 
https://issues.apache.org/jira/browse/PDFBOX-4631?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16909183#comment-16909183
 ] 

ASF subversion and git services commented on PDFBOX-4631:
-

Commit 1865319 from Tilman Hausherr in branch 'pdfbox/branches/issue45'
[ https://svn.apache.org/r1865319 ]

PDFBOX-4631: avoid NPE

> NPE due to bounding box not being set on PDAppearanceStream
> ---
>
> Key: PDFBOX-4631
> URL: https://issues.apache.org/jira/browse/PDFBOX-4631
> Project: PDFBox
>  Issue Type: Bug
>  Components: AcroForm
>Affects Versions: 2.0.16
> Environment: Windows 10
>Reporter: sjoblomj
>Priority: Major
> Fix For: 2.0.17, 3.0.0 PDFBox
>
> Attachments: PdfBoxTest.java, bidragsoknad_strange-content.pdf
>
>
> PDFBox 2.0.16 as well as the current SNAPSNOT version crashes with a 
> NullPointerException. Attached is a small test that triggers the NPE, as well 
> as the PDF.
> The stack trace:
> {code:java}
> java.lang.NullPointerException
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.applyPadding(AppearanceGeneratorHelper.java:816)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.insertGeneratedCombAppearance(AppearanceGeneratorHelper.java:611)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.insertGeneratedAppearance(AppearanceGeneratorHelper.java:505)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.setAppearanceContent(AppearanceGeneratorHelper.java:374)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.setAppearanceValue(AppearanceGeneratorHelper.java:223)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.PDTextField.constructAppearances(PDTextField.java:264)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.PDTerminalField.applyChange(PDTerminalField.java:228)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.PDTextField.setValue(PDTextField.java:219)
>     at PdfBoxTest.reformatFields(PdfBoxTest.java:67)
>     at PdfBoxTest.flattenDocument(PdfBoxTest.java:52)
>     at PdfBoxTest.flatten(PdfBoxTest.java:42)
>     at PdfBoxTest.fileWithStrangeContent(PdfBoxTest.java:27){code}
>  
> The origin of the error seems to be in 
> {{AppearanceGeneratorHelper.setAppearanceValue()}}. A PDAppearanceStream is 
> created, but a bounding box is only set for it if this is false: {{if 
> (appearance != null && appearance.isStream())}}. In my case, the conditional 
> is true, and PDFBox takes a path where no bounding box gets set.
> The following could be a solution, but I'm not very fluent in the inner 
> workings of PDFs, and it's not directly obvious from looking at the code that 
> this is a good approach.
> {code:java}
> diff --git 
> a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
>  
> b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
> index dc2825d4c..a82236069 100644
> --- 
> a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
> +++ 
> b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
> @@ -201,6 +201,7 @@ class AppearanceGeneratorHelper
>  if (appearance != null && appearance.isStream())
>  {
>  appearanceStream = appearance.getAppearanceStream();
> +setBoundingBoxOnAppearanceStream(widget, 
> appearanceStream);
>  }
>  else
>  {
> @@ -235,15 +236,9 @@ class AppearanceGeneratorHelper
>  // Calculate the entries for the bounding box and the transformation 
> matrix
>  // settings for the appearance stream
> -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());
> +setBoundingBoxOnAppearanceStream(widget, appearanceStream);
> -PDRectangle bbox = new PDRectangle(Math.abs((float) point2D.getX()), 
> Math.abs((float) point2D.getY()));
> -appearanceStream.setBBox(bbox);
> -
> -AffineTransform at = calculateMatrix(bbox, rotation);
> +AffineTransform at = calculateMatrix(appearanceStream.getBBox(), 
> resolveRotation(widget));
>  if (!at.isIdentity())
>  {
>  appearanceStream.setMatrix(at);
> @@ -252,7 +247,17 @@ class AppearanceGeneratorHelper
>  appearanceStream.setResources(new PDResources());
>  return appearanceStream;
>  }
> -
> +
> +private 

[jira] [Commented] (PDFBOX-4631) NPE due to bounding box not being set on PDAppearanceStream

2019-08-16 Thread Tilman Hausherr (JIRA)


[ 
https://issues.apache.org/jira/browse/PDFBOX-4631?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16908795#comment-16908795
 ] 

Tilman Hausherr commented on PDFBOX-4631:
-

No, the change isn't what I was thinking, the check was meant to be at another 
place, near {{if (appearance != null && appearance.isStream())}}.

The other one can be solved similarly, i.e. add a check to {{if 
(!annotation.isInvisible() && !annotation.isHidden() && 
annotation.getNormalAppearanceStream() != null)}}. I'll test that later.

> NPE due to bounding box not being set on PDAppearanceStream
> ---
>
> Key: PDFBOX-4631
> URL: https://issues.apache.org/jira/browse/PDFBOX-4631
> Project: PDFBox
>  Issue Type: Bug
>  Components: AcroForm
>Affects Versions: 2.0.16
> Environment: Windows 10
>Reporter: sjoblomj
>Priority: Major
> Fix For: 2.0.17, 3.0.0 PDFBox
>
> Attachments: PdfBoxTest.java, bidragsoknad_strange-content.pdf
>
>
> PDFBox 2.0.16 as well as the current SNAPSNOT version crashes with a 
> NullPointerException. Attached is a small test that triggers the NPE, as well 
> as the PDF.
> The stack trace:
> {code:java}
> java.lang.NullPointerException
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.applyPadding(AppearanceGeneratorHelper.java:816)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.insertGeneratedCombAppearance(AppearanceGeneratorHelper.java:611)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.insertGeneratedAppearance(AppearanceGeneratorHelper.java:505)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.setAppearanceContent(AppearanceGeneratorHelper.java:374)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.setAppearanceValue(AppearanceGeneratorHelper.java:223)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.PDTextField.constructAppearances(PDTextField.java:264)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.PDTerminalField.applyChange(PDTerminalField.java:228)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.PDTextField.setValue(PDTextField.java:219)
>     at PdfBoxTest.reformatFields(PdfBoxTest.java:67)
>     at PdfBoxTest.flattenDocument(PdfBoxTest.java:52)
>     at PdfBoxTest.flatten(PdfBoxTest.java:42)
>     at PdfBoxTest.fileWithStrangeContent(PdfBoxTest.java:27){code}
>  
> The origin of the error seems to be in 
> {{AppearanceGeneratorHelper.setAppearanceValue()}}. A PDAppearanceStream is 
> created, but a bounding box is only set for it if this is false: {{if 
> (appearance != null && appearance.isStream())}}. In my case, the conditional 
> is true, and PDFBox takes a path where no bounding box gets set.
> The following could be a solution, but I'm not very fluent in the inner 
> workings of PDFs, and it's not directly obvious from looking at the code that 
> this is a good approach.
> {code:java}
> diff --git 
> a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
>  
> b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
> index dc2825d4c..a82236069 100644
> --- 
> a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
> +++ 
> b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
> @@ -201,6 +201,7 @@ class AppearanceGeneratorHelper
>  if (appearance != null && appearance.isStream())
>  {
>  appearanceStream = appearance.getAppearanceStream();
> +setBoundingBoxOnAppearanceStream(widget, 
> appearanceStream);
>  }
>  else
>  {
> @@ -235,15 +236,9 @@ class AppearanceGeneratorHelper
>  // Calculate the entries for the bounding box and the transformation 
> matrix
>  // settings for the appearance stream
> -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());
> +setBoundingBoxOnAppearanceStream(widget, appearanceStream);
> -PDRectangle bbox = new PDRectangle(Math.abs((float) point2D.getX()), 
> Math.abs((float) point2D.getY()));
> -appearanceStream.setBBox(bbox);
> -
> -AffineTransform at = calculateMatrix(bbox, rotation);
> +AffineTransform at = calculateMatrix(appearanceStream.getBBox(), 
> resolveRotation(widget));
>  if (!at.isIdentity())
>  {
>  appearanceStream.setMatrix(at);
> @@ 

[jira] [Commented] (PDFBOX-4631) NPE due to bounding box not being set on PDAppearanceStream

2019-08-15 Thread sjoblomj (JIRA)


[ 
https://issues.apache.org/jira/browse/PDFBOX-4631?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16908035#comment-16908035
 ] 

sjoblomj commented on PDFBOX-4631:
--

[~tilman]: Yeah, its "fodselsnummer2" that causes this. So your suggestion is 
to this, or did I missunderstand?
{code:java}
diff --git 
a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
 
b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
index dc2825d4c..986fbd351 100644
--- 
a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
+++ 
b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
@@ -598,7 +598,10 @@ class AppearanceGeneratorHelper
 private void insertGeneratedCombAppearance(PDAppearanceContentStream 
contents, PDAppearanceStream appearanceStream,
 PDFont font, float fontSize) throws IOException
 {
-
+    if (appearanceStream.getBBox() == null) {
+    return;
+    }
+
 // TODO:    Currently the quadding is not taken into account
 //  so the comb is always filled from left to right.

{code}

If so, there seems to be more code that assumes that there is a bounding box. 
If I try with the code above, I get a new NullPointerException:
{code}
java.lang.NullPointerException
at 
org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm.resolveNeedsScaling(PDAcroForm.java:808)
at 
org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm.flatten(PDAcroForm.java:334)
at 
org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm.flatten(PDAcroForm.java:248)
at PdfBoxTest.flattenDocument(PdfBoxTest.java:53)
at PdfBoxTest.flatten(PdfBoxTest.java:42)
at PdfBoxTest.fileWithStrangeContent(PdfBoxTest.java:27)
{code}

> NPE due to bounding box not being set on PDAppearanceStream
> ---
>
> Key: PDFBOX-4631
> URL: https://issues.apache.org/jira/browse/PDFBOX-4631
> Project: PDFBox
>  Issue Type: Bug
>  Components: AcroForm
>Affects Versions: 2.0.16
> Environment: Windows 10
>Reporter: sjoblomj
>Priority: Major
> Fix For: 2.0.17, 3.0.0 PDFBox
>
> Attachments: PdfBoxTest.java, bidragsoknad_strange-content.pdf
>
>
> PDFBox 2.0.16 as well as the current SNAPSNOT version crashes with a 
> NullPointerException. Attached is a small test that triggers the NPE, as well 
> as the PDF.
> The stack trace:
> {code:java}
> java.lang.NullPointerException
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.applyPadding(AppearanceGeneratorHelper.java:816)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.insertGeneratedCombAppearance(AppearanceGeneratorHelper.java:611)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.insertGeneratedAppearance(AppearanceGeneratorHelper.java:505)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.setAppearanceContent(AppearanceGeneratorHelper.java:374)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.setAppearanceValue(AppearanceGeneratorHelper.java:223)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.PDTextField.constructAppearances(PDTextField.java:264)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.PDTerminalField.applyChange(PDTerminalField.java:228)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.PDTextField.setValue(PDTextField.java:219)
>     at PdfBoxTest.reformatFields(PdfBoxTest.java:67)
>     at PdfBoxTest.flattenDocument(PdfBoxTest.java:52)
>     at PdfBoxTest.flatten(PdfBoxTest.java:42)
>     at PdfBoxTest.fileWithStrangeContent(PdfBoxTest.java:27){code}
>  
> The origin of the error seems to be in 
> {{AppearanceGeneratorHelper.setAppearanceValue()}}. A PDAppearanceStream is 
> created, but a bounding box is only set for it if this is false: {{if 
> (appearance != null && appearance.isStream())}}. In my case, the conditional 
> is true, and PDFBox takes a path where no bounding box gets set.
> The following could be a solution, but I'm not very fluent in the inner 
> workings of PDFs, and it's not directly obvious from looking at the code that 
> this is a good approach.
> {code:java}
> diff --git 
> a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
>  
> b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
> index dc2825d4c..a82236069 100644
> --- 
> a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
> +++ 
> b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
> @@ 

[jira] [Commented] (PDFBOX-4631) NPE due to bounding box not being set on PDAppearanceStream

2019-08-14 Thread Tilman Hausherr (JIRA)


[ 
https://issues.apache.org/jira/browse/PDFBOX-4631?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16907498#comment-16907498
 ] 

Tilman Hausherr commented on PDFBOX-4631:
-

It is happening in the field "fodselsnummer2" at 
{{Root/AcroForm/Fields/[21]/AP/N}}. My idea would be to just check whether 
there is a BBox. And if there isn't, treat it as if there is no 
appearanceStream.

> NPE due to bounding box not being set on PDAppearanceStream
> ---
>
> Key: PDFBOX-4631
> URL: https://issues.apache.org/jira/browse/PDFBOX-4631
> Project: PDFBox
>  Issue Type: Bug
>Affects Versions: 2.0.16
> Environment: Windows 10
>Reporter: sjoblomj
>Priority: Major
> Attachments: PdfBoxTest.java, bidragsoknad_strange-content.pdf
>
>
> PDFBox 2.0.16 as well as the current SNAPSNOT version crashes with a 
> NullPointerException. Attached is a small test that triggers the NPE, as well 
> as the PDF.
> The stack trace:
> {code:java}
> java.lang.NullPointerException
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.applyPadding(AppearanceGeneratorHelper.java:816)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.insertGeneratedCombAppearance(AppearanceGeneratorHelper.java:611)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.insertGeneratedAppearance(AppearanceGeneratorHelper.java:505)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.setAppearanceContent(AppearanceGeneratorHelper.java:374)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.setAppearanceValue(AppearanceGeneratorHelper.java:223)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.PDTextField.constructAppearances(PDTextField.java:264)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.PDTerminalField.applyChange(PDTerminalField.java:228)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.PDTextField.setValue(PDTextField.java:219)
>     at PdfBoxTest.reformatFields(PdfBoxTest.java:67)
>     at PdfBoxTest.flattenDocument(PdfBoxTest.java:52)
>     at PdfBoxTest.flatten(PdfBoxTest.java:42)
>     at PdfBoxTest.fileWithStrangeContent(PdfBoxTest.java:27){code}
>  
> The origin of the error seems to be in 
> {{AppearanceGeneratorHelper.setAppearanceValue()}}. A PDAppearanceStream is 
> created, but a bounding box is only set for it if this is false: {{if 
> (appearance != null && appearance.isStream())}}. In my case, the conditional 
> is true, and PDFBox takes a path where no bounding box gets set.
> The following could be a solution, but I'm not very fluent in the inner 
> workings of PDFs, and it's not directly obvious from looking at the code that 
> this is a good approach.
> {code:java}
> diff --git 
> a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
>  
> b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
> index dc2825d4c..a82236069 100644
> --- 
> a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
> +++ 
> b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
> @@ -201,6 +201,7 @@ class AppearanceGeneratorHelper
>  if (appearance != null && appearance.isStream())
>  {
>  appearanceStream = appearance.getAppearanceStream();
> +setBoundingBoxOnAppearanceStream(widget, 
> appearanceStream);
>  }
>  else
>  {
> @@ -235,15 +236,9 @@ class AppearanceGeneratorHelper
>  // Calculate the entries for the bounding box and the transformation 
> matrix
>  // settings for the appearance stream
> -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());
> +setBoundingBoxOnAppearanceStream(widget, appearanceStream);
> -PDRectangle bbox = new PDRectangle(Math.abs((float) point2D.getX()), 
> Math.abs((float) point2D.getY()));
> -appearanceStream.setBBox(bbox);
> -
> -AffineTransform at = calculateMatrix(bbox, rotation);
> +AffineTransform at = calculateMatrix(appearanceStream.getBBox(), 
> resolveRotation(widget));
>  if (!at.isIdentity())
>  {
>  appearanceStream.setMatrix(at);
> @@ -252,7 +247,17 @@ class AppearanceGeneratorHelper
>  appearanceStream.setResources(new PDResources());
>  return appearanceStream;
>  }
> -
> +
> +private void 

[jira] [Commented] (PDFBOX-4631) NPE due to bounding box not being set on PDAppearanceStream

2019-08-14 Thread Michael Klink (JIRA)


[ 
https://issues.apache.org/jira/browse/PDFBOX-4631?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16907318#comment-16907318
 ] 

Michael Klink commented on PDFBOX-4631:
---

The bounding box of an appearance does not necessarily have the lower left as 
0,0, and it also doesn't have to have the same dimensions as the annotation.

Thus, I would not try and repair such a broken appearance but instead ignore it.

In particular, though, a fix *must not* override existing *BBox* entries!

> NPE due to bounding box not being set on PDAppearanceStream
> ---
>
> Key: PDFBOX-4631
> URL: https://issues.apache.org/jira/browse/PDFBOX-4631
> Project: PDFBox
>  Issue Type: Bug
>Affects Versions: 2.0.16
> Environment: Windows 10
>Reporter: sjoblomj
>Priority: Major
> Attachments: PdfBoxTest.java, bidragsoknad_strange-content.pdf
>
>
> PDFBox 2.0.16 as well as the current SNAPSNOT version crashes with a 
> NullPointerException. Attached is a small test that triggers the NPE, as well 
> as the PDF.
> The stack trace:
> {code:java}
> java.lang.NullPointerException
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.applyPadding(AppearanceGeneratorHelper.java:816)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.insertGeneratedCombAppearance(AppearanceGeneratorHelper.java:611)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.insertGeneratedAppearance(AppearanceGeneratorHelper.java:505)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.setAppearanceContent(AppearanceGeneratorHelper.java:374)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.AppearanceGeneratorHelper.setAppearanceValue(AppearanceGeneratorHelper.java:223)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.PDTextField.constructAppearances(PDTextField.java:264)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.PDTerminalField.applyChange(PDTerminalField.java:228)
>     at 
> org.apache.pdfbox.pdmodel.interactive.form.PDTextField.setValue(PDTextField.java:219)
>     at PdfBoxTest.reformatFields(PdfBoxTest.java:67)
>     at PdfBoxTest.flattenDocument(PdfBoxTest.java:52)
>     at PdfBoxTest.flatten(PdfBoxTest.java:42)
>     at PdfBoxTest.fileWithStrangeContent(PdfBoxTest.java:27){code}
>  
> The origin of the error seems to be in 
> {{AppearanceGeneratorHelper.setAppearanceValue()}}. A PDAppearanceStream is 
> created, but a bounding box is only set for it if this is false: {{if 
> (appearance != null && appearance.isStream())}}. In my case, the conditional 
> is true, and PDFBox takes a path where no bounding box gets set.
> The following could be a solution, but I'm not very fluent in the inner 
> workings of PDFs, and it's not directly obvious from looking at the code that 
> this is a good approach.
> {code:java}
> diff --git 
> a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
>  
> b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
> index dc2825d4c..a82236069 100644
> --- 
> a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
> +++ 
> b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
> @@ -201,6 +201,7 @@ class AppearanceGeneratorHelper
>  if (appearance != null && appearance.isStream())
>  {
>  appearanceStream = appearance.getAppearanceStream();
> +setBoundingBoxOnAppearanceStream(widget, 
> appearanceStream);
>  }
>  else
>  {
> @@ -235,15 +236,9 @@ class AppearanceGeneratorHelper
>  // Calculate the entries for the bounding box and the transformation 
> matrix
>  // settings for the appearance stream
> -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());
> +setBoundingBoxOnAppearanceStream(widget, appearanceStream);
> -PDRectangle bbox = new PDRectangle(Math.abs((float) point2D.getX()), 
> Math.abs((float) point2D.getY()));
> -appearanceStream.setBBox(bbox);
> -
> -AffineTransform at = calculateMatrix(bbox, rotation);
> +AffineTransform at = calculateMatrix(appearanceStream.getBBox(), 
> resolveRotation(widget));
>  if (!at.isIdentity())
>  {
>  appearanceStream.setMatrix(at);
> @@ -252,7 +247,17 @@ class AppearanceGeneratorHelper
>  appearanceStream.setResources(new PDResources());
>