pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Glen Hein <glen.h...@connexta.com>
Subject Re: NPE when calling TTFSubFont.addCharCode via PDPage.convertToImage
Date Tue, 15 Mar 2016 23:17:55 GMT
I removed my references to jempbox, and followed the migration guide. The 2.0.0-RC3 code creates
the thumbnail and doesn't generate any extraneous error messages. Yay!

Thanks for your help.

-Glen

________________________________________
From: Tilman Hausherr <THausherr@t-online.de>
Sent: Tuesday, March 15, 2016 3:08 PM
To: users@pdfbox.apache.org
Subject: Re: NPE when calling TTFSubFont.addCharCode via PDPage.convertToImage

Am 15.03.2016 um 22:53 schrieb Glen Hein:
> 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.

jempbox no longer exists. But if you want it, you can continue to use
the 1.8 version.

Tilman

>
> -Glen
>
> ________________________________________
> From: Tilman Hausherr <THausherr@t-online.de>
> Sent: Tuesday, March 15, 2016 2:45 PM
> To: users@pdfbox.apache.org
> 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: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>


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


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


Mime
View raw message