You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Ivan Avdonin <de...@gmail.com> on 2015/06/16 16:40:45 UTC

pdfbox 2.0.0 one PDDocument for multiply using

Dear all,

I try use pdfbox 2.0.0 with embedded unicode fonts and found that font
loading works near 1000 ms.
font = PDType0Font.load(document, new
FileInputStream("fonts/Arial-Unicode-Regular.ttf"));
fontBold = PDType0Font.load(document, new
FileInputStream("fonts/Arial-Unicode-Bold.ttf"));

But, I need faster. I tried to create one PDDocument with fonts then save
it to byte[]. And when i need to create pdf, I load it from byte[]
document = PDDocument.load(new ByteArrayInputStream(DOCUMENT_TEMPLATE));

But I have a problem. First document is created fine, but next one gets
error:
Exception in thread "main" java.lang.NullPointerException
at org.apache.fontbox.ttf.TTFSubsetter.add(TTFSubsetter.java:106)
at org.apache.fontbox.ttf.TTFSubsetter.addAll(TTFSubsetter.java:123)
at
org.apache.pdfbox.pdmodel.font.TrueTypeEmbedder.subset(TrueTypeEmbedder.java:279)
at org.apache.pdfbox.pdmodel.font.PDType0Font.subset(PDType0Font.java:141)
at org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:983)

Could you suggest how i can improve speed of creating pdf with embedded
unicode fonts?

Thanks
-----
Best regards, Ivan Avdonin

Re: pdfbox 2.0.0 one PDDocument for multiply using

Posted by John Hewson <jo...@jahewson.com>.
> On 16 Jun 2015, at 07:40, Ivan Avdonin <de...@gmail.com> wrote:
> 
> Dear all,
> 
> I try use pdfbox 2.0.0 with embedded unicode fonts and found that font
> loading works near 1000 ms.
> font = PDType0Font.load(document, new
> FileInputStream("fonts/Arial-Unicode-Regular.ttf"));
> fontBold = PDType0Font.load(document, new
> FileInputStream("fonts/Arial-Unicode-Bold.ttf"));
> 
> But, I need faster. I tried to create one PDDocument with fonts then save
> it to byte[]. And when i need to create pdf, I load it from byte[]
> document = PDDocument.load(new ByteArrayInputStream(DOCUMENT_TEMPLATE));
> 
> But I have a problem. First document is created fine, but next one gets
> error:
> Exception in thread "main" java.lang.NullPointerException
> at org.apache.fontbox.ttf.TTFSubsetter.add(TTFSubsetter.java:106)
> at org.apache.fontbox.ttf.TTFSubsetter.addAll(TTFSubsetter.java:123)
> at
> org.apache.pdfbox.pdmodel.font.TrueTypeEmbedder.subset(TrueTypeEmbedder.java:279)
> at org.apache.pdfbox.pdmodel.font.PDType0Font.subset(PDType0Font.java:141)
> at org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:983)

You’re getting that error because you’re sharing the same PDType0Font instance across
multiple documents. You need to create a new PDType0Font for each document.

> Could you suggest how i can improve speed of creating pdf with embedded
> unicode fonts?

You could try wrapping the FileInputStream with a BufferedInputStream, that might help?
Maybe also look at using smaller font files, Arial Unicode is pretty large.

— John

> Thanks
> -----
> Best regards, Ivan Avdonin


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