xmlgraphics-fop-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Konstantin Preißer <verlag.preis...@t-online.de>
Subject Generating a PDF by drawing to PDFDocumentGraphics2D
Date Tue, 07 Feb 2012 12:20:06 GMT
Hi all,

I'm sorry if this is the wrong place for my question.

I was seaching for a way to dynamically generate a PDF in Java code by drawing to a Graphics2D
object. When I googled this, I found Apache FOP 1.0 which has a org.apache.fop.svg.PDFDocumentGraphics2D
class (derived from Graphics2D), which seems to support dynamically generating a PDF by drawing
to it.

E.g., I use code like this to generate a PDF and write it to an OutputStream (using Java 1.7):

    PDFDocumentGraphics2D g = new PDFDocumentGraphics2D(false, out, 842, 595);

    g.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext());

    g.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 12));
    g.drawLine(10, 10, 100, 100);
    g.drawString("Hi!", 30, 30);

    g.nextPage(); // switch to next page

    g.drawString("This is the 2nd page.", 30, 30);


This seems to be working really well, using the integrated PDF Fonts.

However, I now have the problem that these integrated fonts seem not to support Unicode characters,
e.g. if I use

g.drawString("\u263a", 30, 30);

then the Character is substituted by a "#" and a warning is printed:

Feb 07, 2012 1:10:11 PM org.apache.fop.fonts.Typeface warnMissingGlyph
Warnung: Glyph 9786 (0x263a, smileface) not available in font Helvetica

So, I was searching for a way to embed a TTF font in the PDF. However, I wasn't successful
finding information about it, as it seems the FOP documentation and examples are only about
XSL-FO (which I don't know much about, as I only need to generate PDFs by drawing to a Graphics2D),
but using a PDFDocumentGraphics2D seems not to be well-documented. So I'm not sure if this
is even an intended way to use FOP, or if there are other/better solutions to generate a PDF
by drawing to a Graphics2D object in Java.

My questions are:
Is using FOP for generating a PDF by drawing to a Graphics2D a recommended way?
Is it possible to embed TTF fonts when drawing to a PDFDocumentGraphics2D object? If yes,


Best Regards,
Konstantin Preißer

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

View raw message