pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Juan Carlos Castilla <juancarlos.casti...@datisa.es>
Subject Error when using monospaced Fonts
Date Fri, 05 Apr 2013 11:26:30 GMT
Hi, I need to load some Ubuntu fonts in a PDF but I'm having problems when
trying to load monospaced ones. Using pdfbox-1.8.0, I wrote this snippet:

--------------------------------------------------------------------------------------------
import java.io.IOException;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.edit.PDPageContentStream;
import org.apache.pdfbox.pdmodel.font.PDFont;
import org.apache.pdfbox.pdmodel.font.PDTrueTypeFont;

public class PDFTest
{

    public static void main (String [] args) throws IOException
    {
        PDDocument document = null;
        try
        {
            document = new PDDocument ();
            PDPage page = new PDPage ();
            document.addPage (page);
            PDFont font = PDTrueTypeFont.loadTTF (document,
                                                  "D:\\UbuntuMono-R.ttf");

            PDPageContentStream contentStream = new PDPageContentStream (

document,

page);
            contentStream.beginText ();
            contentStream.setFont (font, 12);
            contentStream.moveTextPositionByAmount (100, 700);
            contentStream.drawString ("Hello World");
            contentStream.endText ();
            contentStream.close ();
            document.save ("d:\\Hello World.pdf");
            document.close ();
        }
        catch (Exception e)
        {
            e.printStackTrace ();
        }
    }
}
--------------------------------------------------------------------------------------------

And here is the error I'm getting:

--------------------------------------------------------------------------------------------
java.lang.ArrayIndexOutOfBoundsException: 5
    at
org.apache.pdfbox.pdmodel.font.PDTrueTypeFont.loadDescriptorDictionary(PDTrueTypeFont.java:409)
    at
org.apache.pdfbox.pdmodel.font.PDTrueTypeFont.loadTTF(PDTrueTypeFont.java:201)
    at
org.apache.pdfbox.pdmodel.font.PDTrueTypeFont.loadTTF(PDTrueTypeFont.java:177)
    at
org.apache.pdfbox.pdmodel.font.PDTrueTypeFont.loadTTF(PDTrueTypeFont.java:158)
    at
org.apache.pdfbox.pdmodel.font.PDTrueTypeFont.loadTTF(PDTrueTypeFont.java:145)
    at
org.apache.pdfbox.pdmodel.font.PDTrueTypeFont.loadTTF(PDTrueTypeFont.java:132)
    at es.datisa.informes.test.PDF.PDFTest.main(PDFTest.java:21)
--------------------------------------------------------------------------------------------

Trying with other monospaced (like DejaVuSansMono.ttf from windows fonts)
shows the same error. If I try with another Ubuntu Font (not mono)
everything is ok...

Any idea or suggestion?

Thanks!

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message