You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by "Erik Scholtz, ArgonSoft GmbH" <es...@argonsoft.de> on 2010/07/20 18:57:55 UTC

Problem with multiple fonts in a newly created document

Hi,

at the moment I'm trying to build a new pdf file with pdfbox (Vers. 
1.2.1 / JVM 1.6.0) from the scratch. Unfortunatly, I'm getting errors 
when trying to embed fonts: The generated document does not look correct 
under "Apple Preview", when opening with "Acrobat" an error ("value for 
/Widths is wrong") is shown, but the look of the file is as expected [1].

I tried with several TTFs - all time the same error. I think the fonts 
are ok and it must be a mistake by my own.
Can anyone please point me an example where to see how multiple TTFs are 
used correctly?

Here is the code I'm using:

------------------------------------------------------------------------
PDDocument document = new PDDocument();
PDPage page = new PDPage(PDPage.PAGE_SIZE_A4);
document.addPage( page );

PDTrueTypeFont fontBold = PDTrueTypeFont.loadTTF(document, 
"DroidSans-Bold.ttf");
PDTrueTypeFont fontRegular = PDTrueTypeFont.loadTTF(document, 
"DroidSans.ttf");

PDPageContentStream contentStream = new PDPageContentStream(document, page);
contentStream.drawLine(18, 747, 580, 747);

contentStream.setFont(fontRegular, 14);
contentStream.beginText();
contentStream.setTextTranslation(20, 750);
contentStream.drawString("Ihr Vorteil durch");

contentStream.setFont(fontBold, 12);
contentStream.setTextTranslation(20, 725);
contentStream.drawString("Pers\u00F6nliche Berechnung f\u00FCr:");

contentStream.setTextTranslation(20, 710);
contentStream.drawString("Bernd Mustermann");

contentStream.endText();
contentStream.close();

document.save(file);
document.close();
------------------------------------------------------------------------

Thanks for all your help,
Greetings,
Erik


[1] http://blog.elitecoderz.net/wp-content/uploads/screen.png

Re: Problem with multiple fonts in a newly created document

Posted by "Erik Scholtz, ArgonSoft GmbH" <es...@argonsoft.de>.
Some additional informations:

I opened the generated PDF with Illustrator. There I could see, that the 
Kerning of each character is set to another value. By setting the 
kerning to 0 and saving the file again, the file looks quite perfect and 
the errors are gone. The fonts seem to be embedded correctly.

I'll try to find out about the differences in the file and will report.

So long,
Erik

On 20.07.10 18:57, Erik Scholtz, ArgonSoft GmbH wrote:
> Hi,
>
> at the moment I'm trying to build a new pdf file with pdfbox (Vers.
> 1.2.1 / JVM 1.6.0) from the scratch. Unfortunatly, I'm getting errors
> when trying to embed fonts: The generated document does not look correct
> under "Apple Preview", when opening with "Acrobat" an error ("value for
> /Widths is wrong") is shown, but the look of the file is as expected [1].
>
> I tried with several TTFs - all time the same error. I think the fonts
> are ok and it must be a mistake by my own.
> Can anyone please point me an example where to see how multiple TTFs are
> used correctly?
>
> Here is the code I'm using:
>
> ------------------------------------------------------------------------
> PDDocument document = new PDDocument();
> PDPage page = new PDPage(PDPage.PAGE_SIZE_A4);
> document.addPage( page );
>
> PDTrueTypeFont fontBold = PDTrueTypeFont.loadTTF(document,
> "DroidSans-Bold.ttf");
> PDTrueTypeFont fontRegular = PDTrueTypeFont.loadTTF(document,
> "DroidSans.ttf");
>
> PDPageContentStream contentStream = new PDPageContentStream(document,
> page);
> contentStream.drawLine(18, 747, 580, 747);
>
> contentStream.setFont(fontRegular, 14);
> contentStream.beginText();
> contentStream.setTextTranslation(20, 750);
> contentStream.drawString("Ihr Vorteil durch");
>
> contentStream.setFont(fontBold, 12);
> contentStream.setTextTranslation(20, 725);
> contentStream.drawString("Pers\u00F6nliche Berechnung f\u00FCr:");
>
> contentStream.setTextTranslation(20, 710);
> contentStream.drawString("Bernd Mustermann");
>
> contentStream.endText();
> contentStream.close();
>
> document.save(file);
> document.close();
> ------------------------------------------------------------------------
>
> Thanks for all your help,
> Greetings,
> Erik
>
>
> [1] http://blog.elitecoderz.net/wp-content/uploads/screen.png