Czech example

This is a code example of iText PDF, discover more.

31st May 2016
admin-marketing

Switch code for this example

CzechExample.java
  1. /*
  2.  
  3.     This file is part of the iText (R) project.
  4.     Copyright (c) 1998-2016 iText Group NV
  5.  
  6. */
  7.  
  8. /**
  9.  * Example written by Bruno Lowagie.
  10.  */
  11. package com.itextpdf.samples.sandbox.fonts;
  12.  
  13. import com.itextpdf.kernel.font.PdfFont;
  14. import com.itextpdf.kernel.font.PdfFontFactory;
  15. import com.itextpdf.kernel.pdf.PdfDocument;
  16. import com.itextpdf.kernel.pdf.PdfWriter;
  17. import com.itextpdf.layout.Document;
  18. import com.itextpdf.layout.element.Paragraph;
  19. import com.itextpdf.samples.GenericTest;
  20. import com.itextpdf.test.annotations.type.SampleTest;
  21.  
  22. import org.junit.experimental.categories.Category;
  23.  
  24. import java.io.File;
  25.  
  26. @Category(SampleTest.class)
  27. public class CzechExample extends GenericTest {
  28.     public static final String DEST = "./target/test/resources/sandbox/fonts/czech_example.pdf";
  29.     public static final String FONT = "./src/test/resources/font/FreeSans.ttf";
  30.  
  31.     public static void main(String[] args) throws Exception {
  32.         File file = new File(DEST);
  33.         file.getParentFile().mkdirs();
  34.         new CzechExample().manipulatePdf(DEST);
  35.     }
  36.  
  37.     @Override
  38.     protected void manipulatePdf(String dest) throws Exception {
  39.         PdfDocument pdfDoc = new PdfDocument(new PdfWriter(DEST));
  40.         Document doc = new Document(pdfDoc);
  41.         PdfFont f1 = PdfFontFactory.createFont(FONT, "Cp1250", true);
  42.         Paragraph p1 = new Paragraph("Testing of letters \u010c,\u0106,\u0160,\u017d,\u0110").setFont(f1);
  43.         doc.add(p1);
  44.         PdfFont f2 = PdfFontFactory.createFont(FONT, "Identity-H", true);
  45.         Paragraph p2 = new Paragraph("Testing of letters \u010c,\u0106,\u0160,\u017d,\u0110").setFont(f2);
  46.         doc.add(p2);
  47.         doc.close();
  48.     }
  49. }
Contact

Still have questions? 

We're happy to answer your questions. Reach out to us and we'll get back to you shortly.

Contact us
Stay updated

Join 11,000+ subscribers and become an iText PDF expert by staying up to date with our new products, updates, tips, technical solutions and happenings.

Subscribe Now