the you would write PDSimpleFont font = PDTrueTypeFont.load … and use setFontDescriptor(PDFontDescriptorDictionary fontDescriptor).
http://pdfbox.apache.org/apidocs/org/apache/pdfbox/pdmodel/font/PDFontDescriptorDictionary.html The TTF Files are in Windows/Fonts. Maruan Sahyoun Am 21.02.2013 um 13:46 schrieb Christian Wulf <[email protected]>: > Thanks for your information. However, I read the tutorials and examples > containing your piece of code. These ones do not help, because I want to > set the fontName, fontFamily, bold, italic etc. which I cannot > dynamically set with your approach. The fontDescriptor cannot be changed > after instantiating a concrete PDFont. > > By the way: Where can I find the ttf files on my windows system or do I > have to download them from anywhere? > > Thanks, > Christian > > Am 21.02.2013 13:38, schrieb Maruan Sahyoun: >> well - let's assume you have a text in HTML with some styling in CSS. From >> there you would know the font description, size …. >> Now in order to represent that in PDF you need to draw a string with the >> correct font. This can either be done using one of the build in fonts or >> using an external font e.g. TrueType font. >> >> Quick sample >> 01 doc = new PDDocument(); >> 02 PDPage page = new PDPage(); >> 03 doc.addPage(page); >> 04 PDFont font = PDTrueTypeFont.loadTTF(doc, "Arial.ttf"); >> 05 PDPageContentStream contentStream = new PDPageContentStream(doc,page); >> 06 contentStream.beginText(); >> 07 contentStream.setFont(font, 12); >> 08 contentStream.moveTextPositionByAmount(100, 700); >> 09 contentStream.drawString("my sample text"); >> 10 contentStream.endText(); >> 11 contentStream.close(); >> 12 doc.save(file); >> Where the properties such as font name (line 04), font size (line 07), text >> position (line 08), text (line 09) … are based on you HTML/CSS >> >> Of course there are also alternative ways to generate PDF from HTML/CSS. My >> assumption here is that you have to do it directly yourself :-) >> >> Maruan Sahyoun >> >> Am 21.02.2013 um 13:24 schrieb Christian Wulf <[email protected]>: >> >>> Not directly. So, how could I use it in my situation? >>> >>> Am 21.02.2013 13:21, schrieb Maruan Sahyoun: >>>> you could use PDTrueTypeFont >>>> http://pdfbox.apache.org/apidocs/org/apache/pdfbox/pdmodel/font/PDTrueTypeFont.html. >>>> PDFont is 'only' a base class. >>>> >>>> Maruan Sahyoun >>>> >>>> Am 21.02.2013 um 13:09 schrieb Christian Wulf >>>> <[email protected]>: >>>> >>>>> Hello again, >>>>> >>>>> I currently develop a transformation from an HTML/CSS DOM to PDF. It >>>>> reads the css information of each element and transforms it to a visual >>>>> object within a PDF page. For this purpose, I need to create a PDFont >>>>> instance with the information of a java.awt.Font instance that I get >>>>> from the DOM. >>>>> >>>>> Kind regards, >>>>> Christian >>>>> >>>>> Am 21.02.2013 13:02, schrieb Maruan Sahyoun: >>>>>> Hi, >>>>>> >>>>>> could you explain a little bit what you are trying to achieve? Normally >>>>>> in PDFBox it's the other way around awt.Font instances are created from >>>>>> PDFont e.g. for rendering purposes. >>>>>> >>>>>> Kind regards >>>>>> >>>>>> Maruan Sahyoun >>>>>> >>>>>> Am 21.02.2013 um 11:06 schrieb Christian Wulf >>>>>> <[email protected]>: >>>>>> >>>>>>> Hello community, >>>>>>> >>>>>>> I need to get the PDFont instance that corresponds to a given >>>>>>> java.awt.Font instance including fontName, fontFamiliy, bold, italic >>>>>>> etc. Unfortunately, I could not find any way how to acceive this goal >>>>>>> with pdfbox. I have tried the following but stopped at the Dictionary >>>>>>> parameter because I do not know such construct: >>>>>>> >>>>>>> def fac= new PDFontFactory() >>>>>>> >>>>>>> fac.createFont(dic) >>>>>>> >>>>>>> >>>>>>> Could you help with this "transformation"? >>>>>>> >>>>>>> Thanks, >>>>>>> Christian >>>>>>> >>>>>>> -- >>>>>>> M.Sc. Christian Wulf >>>>>>> Research Assistant >>>>>>> >>>>>>> Software Engineering Group >>>>>>> Dept. Computer Science >>>>>>> Christian-Albrechts-Platz 4 >>>>>>> University of Kiel >>>>>>> 24118 Kiel, Germany >>>>>>> >>>>>>> Room: 1213 >>>>>>> Phone: +49 431 880 2776 >>>>>>> Fax: +49 431 880 7617 >>>>>>> Email: [email protected] >>>>>>> WWW: http://se.informatik.uni-kiel.de/ >>>>>>> >>>>> -- >>>>> M.Sc. Christian Wulf >>>>> Research Assistant >>>>> >>>>> Software Engineering Group >>>>> Dept. Computer Science >>>>> Christian-Albrechts-Platz 4 >>>>> University of Kiel >>>>> 24118 Kiel, Germany >>>>> >>>>> Room: 1213 >>>>> Phone: +49 431 880 2776 >>>>> Fax: +49 431 880 7617 >>>>> Email: [email protected] >>>>> WWW: http://se.informatik.uni-kiel.de/ >>>>> >>> -- >>> M.Sc. Christian Wulf >>> Research Assistant >>> >>> Software Engineering Group >>> Dept. Computer Science >>> Christian-Albrechts-Platz 4 >>> University of Kiel >>> 24118 Kiel, Germany >>> >>> Room: 1213 >>> Phone: +49 431 880 2776 >>> Fax: +49 431 880 7617 >>> Email: [email protected] >>> WWW: http://se.informatik.uni-kiel.de/ >>> >> > > -- > M.Sc. Christian Wulf > Research Assistant > > Software Engineering Group > Dept. Computer Science > Christian-Albrechts-Platz 4 > University of Kiel > 24118 Kiel, Germany > > Room: 1213 > Phone: +49 431 880 2776 > Fax: +49 431 880 7617 > Email: [email protected] > WWW: http://se.informatik.uni-kiel.de/ >

