Oops, just noticed that jempbox was specified in my pom. Sorry, fixing that and 
I'll try the 2.0 code. Thanks again.

-Glen

________________________________________
From: Glen Hein
Sent: Tuesday, March 15, 2016 2:53 PM
To: [email protected]
Subject: Re: NPE when calling TTFSubFont.addCharCode via PDPage.convertToImage

I tried 2.0.0-RC3 
(http://mvnrepository.com/artifact/org.apache.pdfbox/pdfbox/2.0.0-RC3), but I 
got an maven error about a missing POM file on one of the dependencies. This is 
the error I get from maven:

Failed to collect dependencies at org.apache.pdfbox:jempbox:jar:2.0.0-RC3: 
Failed to read artifact descriptor for org.apache.pdfbox:jempbox:jar:2.0.0-RC3: 
Could not transfer artifact org.apache.pdfbox:jempbox:pom:2.0.0-RC3 from/to 
forgerock-snapshots-repository (http://maven.forgerock.org/repo/snapshots): 
Failed to transfer file: 
http://maven.forgerock.org/repo/snapshots/org/apache/pdfbox/jempbox/2.0.0-RC3/jempbox-2.0.0-RC3.pom.
 Return code is: 409 , ReasonPhrase:Conflict. -> [Help 1]

I can try to find the dependency manually and install it into my local repo.

-Glen

________________________________________
From: Tilman Hausherr <[email protected]>
Sent: Tuesday, March 15, 2016 2:45 PM
To: [email protected]
Subject: Re: NPE when calling TTFSubFont.addCharCode via PDPage.convertToImage

If possible, try the 2.0 version. Read the migration guide re:
converting to images.

Tilman

Am 15.03.2016 um 22:39 schrieb Glen Hein:
> Hello,
>
>
> I'm trying to create a thumbail of a PDF and I'm getting a bunch of NPE 
> stacktraces when I call PDPage.convertToImage. This only occurs with certain 
> PDFs. The NPE is being thrown from TTFSubFont.addCharCode. The NPEs are being 
> logged (99 separate but identical stacktraces), but not passed up to my 
> calling code. The resulting image is blank (all white). This makes it 
> difficult for the calling code to detect the error condition. Is this a known 
> problem? Is there a work-around so the calling code can detect the error?
>
>
> Let me know if you want the actual PDF, and the preferred way to post it to 
> the list.
>
>
> This is how I'm calling the code:
>
>
> private byte[] generatePdfThumbnail(PDDocument pdfDocument) throws 
> IOException {
>      PDPage page = (PDPage) pdfDocument.getDocumentCatalog()
>              .getAllPages()
>              .get(0);
>
>      BufferedImage image = page.convertToImage(BufferedImage.TYPE_INT_RGB, 
> RESOLUTION_DPI);
>      int largestDimension = Math.max(image.getHeight(), image.getWidth());
>      float scalingFactor = IMAGE_HEIGHTWIDTH / largestDimension;
>      int scaledHeight = (int) (image.getHeight() * scalingFactor);
>      int scaledWidth = (int) (image.getWidth() * scalingFactor);
>
>      BufferedImage scaledImage = new BufferedImage(scaledWidth,
>              scaledHeight,
>              BufferedImage.TYPE_INT_RGB);
>      Graphics2D graphics = scaledImage.createGraphics();
>      graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
>              RenderingHints.VALUE_INTERPOLATION_BILINEAR);
>      graphics.drawImage(image, 0, 0, scaledWidth, scaledHeight, null);
>      graphics.dispose();
>
>      try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
>          ImageIOUtil.writeImage(scaledImage,
>                  FORMAT_NAME,
>                  outputStream,
>                  RESOLUTION_DPI,
>                  IMAGE_QUALITY);
>          return outputStream.toByteArray();
>      }http://mvnrepository.com/artifact/org.apache.pdfbox/pdfbox/2.0.0-RC3
> }
>
> Here is the stacktrace I'm seeing:
>
>
> Mar 15, 2016 1:48:12 PM org.apache.pdfbox.util.PDFStreamEngine processOperator
> WARNING: java.lang.NullPointerException
> java.lang.NullPointerException
>          at org.apache.fontbox.ttf.TTFSubFont.addCharCode(TTFSubFont.java:106)
>          at org.apache.fontbox.ttf.TTFSubFont.<init>(TTFSubFont.java:95)
>          at 
> org.apache.pdfbox.pdmodel.font.PDTrueTypeFont.rebuildTTF(PDTrueTypeFont.java:550)
>          at 
> org.apache.pdfbox.pdmodel.font.PDTrueTypeFont.getawtFont(PDTrueTypeFont.java:478)
>          at 
> org.apache.pdfbox.pdmodel.font.PDSimpleFont.drawString(PDSimpleFont.java:110)
>          at 
> org.apache.pdfbox.pdfviewer.PageDrawer.processTextPosition(PageDrawer.java:260)
>          at 
> org.apache.pdfbox.util.PDFStreamEngine.processEncodedText(PDFStreamEngine.java:504)
>          at org.apache.pdfbox.util.operator.ShowText.process(ShowText.java:56)
>          at 
> org.apache.pdfbox.util.PDFStreamEngine.processOperator(PDFStreamEngine.java:562)
>          at 
> org.apache.pdfbox.util.PDFStreamEngine.processSubStream(PDFStreamEngine.java:269)
>          at 
> org.apache.pdfbox.util.PDFStreamEngine.processSubStream(PDFStreamEngine.java:236)
>          at 
> org.apache.pdfbox.util.PDFStreamEngine.processStream(PDFStreamEngine.java:216)
>          at 
> org.apache.pdfbox.pdfviewer.PageDrawer.drawPage(PageDrawer.java:139)
>          at org.apache.pdfbox.pdmodel.PDPage.convertToImage(PDPage.java:801)
>          at 
> ddf.catalog.transformer.input.pdf.PdfInputTransformer.generatePdfThumbnail(PdfInputTransformer.java:170)
>          at 
> ddf.catalog.transformer.input.pdf.PdfInputTransformer.generatePdfThumbnail(PdfInputTransformer.java:162)
>          ...
>
>
> Thanks in advance,
>
> Glen
>
>
>
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to