1

I am currently stuck on the following problem: Generating a document with PDFBox I would like to include the box-generating characters, preferably of Courier New. For those of you, who shouldn't know what the bgcs are, here is a picture of them:

BGFs

In my Java-Class I currently got the following lines.

contentStream.setFont(PDTrueTypeFont.loadTTF(doc, "pdf_content/cour.ttf") , 12);
contentStream.beginText();
contentStream.drawString("┼┌┐└┘│─┘├┤┬┴┼");
contentStream.endText();

Unfortunately, as one can see in the output, they result in some weird characters and not the desired bars.

Weird output in the PDF

Did anyone encounter the same problem or has any solution to this problem? I might also mention that printing characters like german "Umlaute" ("äöüß") works fine.

Thanks in advance!

schneiti
  • 428
  • 1
  • 8
  • 22
  • It is a bug, essentially the same as with the € (EURO) symbol, cf [this answer](http://stackoverflow.com/a/22274334/1729265). Essentially you need a replacement for the `PDPageContentStream` method `drawString`. – mkl Aug 11 '14 at 14:21
  • thanks! good to know this is a bug, apache didn't show anything about that.. – schneiti Aug 11 '14 at 14:34
  • Check that your IDE is set to UTF-8 (editor _and_ comnpiler). Could test it with `"\u2500\u2502\u250c..."` or read the codes in those "[]" char blocks. – Joop Eggen Aug 12 '14 at 13:05

1 Answers1

0

By exporting the subset of the needed characters to a new font and mapping them to unicode 0041 to 004e and 0061 to 006e enables you to work with these characters using keys A-Z and a-n. PDFBox enables you to include the font externally by using the following code:

contentStream.setFont( PDTrueTypeFont.loadTTF(doc, "pdf_content/bgcs.ttf"), 12);

Since I have been searching for a free and although working program to edit existing fonts, I found that fontforge and Type Light both seem to understand working with character mappings (tested with Type Light, since fontforge is more of the linux/unix application hard to embed in Windows 8.1).

Hope this helps anybody stumbling over this bug of the drawString method.

schneiti
  • 428
  • 1
  • 8
  • 22