Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to create a PDF document from languages of Unicode char set regarding using third party Fonts
    primarykey
    data
    text
    <p>I'm using <a href="http://pdfbox.apache.org/" rel="nofollow">PDFBox</a> and <a href="http://itextpdf.com" rel="nofollow">iText</a> to create a simple (just paragraphs) pdf document from various languages. Something like :</p> <p><strong>pdfBox</strong>:</p> <pre><code>private static void createPdfBoxDocument(File from, File to) { PDDocument document = null; try { document = new TextToPDF().createPDFFromText(new FileReader(from)); document.save(new FileOutputStream(to)); } finally { if (document != null) document.close(); } } private void createPdfBoxDoc() throws IOException, FileNotFoundException, COSVisitorException { PDDocument document = new PDDocument(); PDPage page = new PDPage(); document.addPage(page); PDPageContentStream contentStream = new PDPageContentStream(document, page); PDType1Font font = PDType1Font.TIMES_ROMAN; contentStream.setFont(font, 12); contentStream.beginText(); contentStream.moveTextPositionByAmount(100, 400); contentStream.drawString("š"); contentStream.endText(); contentStream.close(); document.save("test.pdf"); document.close(); } </code></pre> <p><strong>itext</strong>:</p> <pre><code>private static Font blackFont = new Font(Font.FontFamily.COURIER, 12, Font.NORMAL, BaseColor.BLACK); private static void createITextDocument(File from, File to) { Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(to)); document.open(); addContent(document, getParagraphs(from)); document.close(); } private static void addContent(Document document, List&lt;String&gt; paragraphs) { for (int i = 0; i &lt; paragraphs.size(); i++) { document.add(new Paragraph(paragraphs.get(i), blackFont)); } } </code></pre> <p>The input files are encoded in UTF-8 and some languages of Unicode char set, like Russian alphabet etc., are not rendered properly in pdf. The Fonts in both libraries don't support Unicode charset I suppose and I can't find any documentation on how to add and use third party fonts. Could please anybody help me out with an example ?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload