Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Wed Aug 10, 2022 7:50 am

I have faced with an Exception with saveAsImage function to convert image from pdf.
My code:
Code: Select all
PdfDocument pdf = new PdfDocument();
pdf.loadFromBytes(pdfBytes);
BufferedImage bufferedImage = pdf.saveAsImage(0, PdfImageType.Bitmap,1000,1000).getSubimage(125,3277,2699,991);


Error:
Code: Select all
java.lang.NullPointerException
        at sun.awt.FontConfiguration.getVersion(FontConfiguration.java:1264)
        at sun.awt.FontConfiguration.readFontConfigFile(FontConfiguration.java:219)
        at sun.awt.FontConfiguration.init(FontConfiguration.java:107)
        at sun.awt.X11FontManager.createFontConfiguration(X11FontManager.java:774)
        at sun.font.SunFontManager$2.run(SunFontManager.java:431)
        at java.security.AccessController.doPrivileged(Native Method)
        at sun.font.SunFontManager.<init>(SunFontManager.java:376)
        at sun.awt.FcFontManager.<init>(FcFontManager.java:35)
        at sun.awt.X11FontManager.<init>(X11FontManager.java:57)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at java.lang.Class.newInstance(Class.java:442)
        at sun.font.FontManagerFactory$1.run(FontManagerFactory.java:83)
        at java.security.AccessController.doPrivileged(Native Method)
        at sun.font.FontManagerFactory.getInstance(FontManagerFactory.java:74)
        at java.awt.Font.getFont2D(Font.java:491)
        at java.awt.Font.access$000(Font.java:224)
        at java.awt.Font$FontAccessImpl.getFont2D(Font.java:228)
        at sun.font.FontUtilities.getFont2D(FontUtilities.java:180)
        at sun.java2d.SunGraphics2D.checkFontInfo(SunGraphics2D.java:670)
        at sun.java2d.SunGraphics2D.getFontInfo(SunGraphics2D.java:831)
        at sun.java2d.SurfaceData.getTextPipe(SurfaceData.java:754)
        at sun.java2d.SurfaceData.validatePipe(SurfaceData.java:652)
        at sun.java2d.SunGraphics2D.validatePipe(SunGraphics2D.java:447)
        at sun.java2d.pipe.ValidatePipe.validate(ValidatePipe.java:55)
        at sun.java2d.pipe.ValidatePipe.fill(ValidatePipe.java:159)
        at sun.java2d.SunGraphics2D.fill(SunGraphics2D.java:2525)
        at com.spire.pdf.packages.sprdav.spr┮⅙(Unknown Source)
        at com.spire.pdf.packages.sprdav.spr┱⅘(Unknown Source)
        at com.spire.pdf.packages.sprdav.spr┾⅙(Unknown Source)
        at com.spire.pdf.packages.sprdav.spr◑⅘(Unknown Source)
        at com.spire.pdf.packages.sprdav.spr╓⅘(Unknown Source)
        at com.spire.pdf.packages.sprdav.spr▏⅘(Unknown Source)
        at com.spire.pdf.packages.sprdav.spr┒⅙(Unknown Source)
        at com.spire.pdf.packages.sprxxn.spr╁╸(Unknown Source)
        at com.spire.pdf.PdfDocumentBase.spr┼∭(Unknown Source)
        at com.spire.pdf.PdfDocumentBase.spr▒∭(Unknown Source)
        at com.spire.pdf.PdfDocument.spr▏╽(Unknown Source)
        at com.spire.pdf.PdfDocument.saveAsImage(Unknown Source)


How can I solve this issue?

jkl_0610
 
Posts: 4
Joined: Sat Jul 30, 2022 4:03 am

Wed Aug 10, 2022 9:57 am

Hello,

Thanks for your inquiry.

This exception should be related to a specific PDF file. Could you please provide us the PDF file which caused this exception so we can reproduce the issue? You can upload it here or send it to us via email (support@e-iceblue.com). Thanks in advance for your assistance.
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Wed Aug 10, 2022 2:18 pm

Andy.Zhou wrote:Hello,

Thanks for your inquiry.

This exception should be related to a specific PDF file. Could you please provide us the PDF file which caused this exception so we can reproduce the issue? You can upload it here or send it to us via email (support@e-iceblue.com). Thanks in advance for your assistance.


I sent you an email.

jkl_0610
 
Posts: 4
Joined: Sat Jul 30, 2022 4:03 am

Thu Aug 11, 2022 3:34 am

Hi,

Thanks for your sharing.

I tested your pdf files on a docker container but did not reproduce the exception. Based on the exception information you provided, we guess that this may be caused by the lack of some fonts in the docker container. By parsing your PDF files (see the screenshot), we found that there are font call instructions. So we guess the missing font is "Helvetica-Bold". It is recommended that you download all fonts in the Helvetica font family and copy them into the docker container (/usr/share/fonts) and then test again.
Also, the latest version of Spire.Pdf For Java is 8.8.0. If the version you are using is not the latest version, please upgrade and try again. If the exception persists, please provide us the dockerfile you are using. Thanks for your assistance.
741EF0F2-9122-44dd-8493-B1A640F8444D.png
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Thu Aug 11, 2022 6:34 am

Andy.Zhou wrote:Hi,

Thanks for your sharing.

I tested your pdf files on a docker container but did not reproduce the exception. Based on the exception information you provided, we guess that this may be caused by the lack of some fonts in the docker container. By parsing your PDF files (see the screenshot), we found that there are font call instructions. So we guess the missing font is "Helvetica-Bold". It is recommended that you download all fonts in the Helvetica font family and copy them into the docker container (/usr/share/fonts) and then test again.
Also, the latest version of Spire.Pdf For Java is 8.8.0. If the version you are using is not the latest version, please upgrade and try again. If the exception persists, please provide us the dockerfile you are using. Thanks for your assistance.
741EF0F2-9122-44dd-8493-B1A640F8444D.png


Very useful. Thanks a lot <3

jkl_0610
 
Posts: 4
Joined: Sat Jul 30, 2022 4:03 am

Thu Aug 11, 2022 9:54 am

You are welcome! Hope it helps you. :D
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Return to Spire.PDF