> On 16 Jun 2015, at 07:40, Ivan Avdonin <[email protected]> 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: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to