Type 3 font

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

7th November 2015
admin-marketing

Switch code for this example

Logo.java
  1. /*
  2.  * Example written by Bruno Lowagie.
  3.  */
  4. package sandbox.fonts;
  5.  
  6. import com.itextpdf.text.BaseColor;
  7. import com.itextpdf.text.Document;
  8. import com.itextpdf.text.DocumentException;
  9. import com.itextpdf.text.Font;
  10. import com.itextpdf.text.Paragraph;
  11. import com.itextpdf.text.pdf.PdfContentByte;
  12. import com.itextpdf.text.pdf.PdfWriter;
  13. import com.itextpdf.text.pdf.Type3Font;
  14.  
  15. import java.io.File;
  16. import java.io.FileOutputStream;
  17. import java.io.IOException;
  18. import sandbox.WrapToTest;
  19.  
  20. @WrapToTest
  21. public class Logo {
  22.    
  23.     /** The resulting PDF file. */
  24.     public static final String DEST
  25.         = "results/fonts/itext_logo.pdf";
  26.  
  27.     /**
  28.      * Creates a PDF document.
  29.      * @param filename the path to the new PDF document
  30.      * @throws DocumentException
  31.      * @throws IOException
  32.      */
  33.     public void createPdf(String filename) throws IOException, DocumentException {
  34.         // step 1
  35.         Document document = new Document();
  36.         // step 2
  37.         PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename));
  38.         // step 3
  39.         document.open();
  40.         float linewidth = 125;
  41.         // step 4
  42.         Type3Font t3 = new Type3Font(writer, true);
  43.         PdfContentByte i = t3.defineGlyph('I', 700, 0, 0, 1200, 600);
  44.         i.setColorStroke(new BaseColor(0xf9, 0x9d, 0x25));
  45.         i.setLineWidth(linewidth);
  46.         i.setLineCap(PdfContentByte.LINE_CAP_ROUND);
  47.         i.moveTo(600, 36);
  48.         i.lineTo(600, 564);
  49.         i.stroke();
  50.         PdfContentByte t = t3.defineGlyph('T', 1170, 0, 0, 1200, 600);
  51.         t.setColorStroke(new BaseColor(0x08, 0x49, 0x75));
  52.         t.setLineWidth(linewidth);
  53.         t.setLineCap(PdfContentByte.LINE_CAP_ROUND);
  54.         t.moveTo(144, 564);
  55.         t.lineTo(1056, 564);
  56.         t.moveTo(600, 36);
  57.         t.lineTo(600, 564);
  58.         t.stroke();
  59.         PdfContentByte e = t3.defineGlyph('E', 1150, 0, 0, 1200, 600);
  60.         e.setColorStroke(new BaseColor(0xf8, 0x9b, 0x22));
  61.         e.setLineWidth(linewidth);
  62.         e.setLineCap(PdfContentByte.LINE_CAP_ROUND);
  63.         e.moveTo(144, 36);
  64.         e.lineTo(1056, 36);
  65.         e.moveTo(144, 300);
  66.         e.lineTo(1056, 300);
  67.         e.moveTo(144, 564);
  68.         e.lineTo(1056, 564);
  69.         e.stroke();
  70.         PdfContentByte x = t3.defineGlyph('X', 1160, 0, 0, 1200, 600);
  71.         x.setColorStroke(new BaseColor(0x10, 0x46, 0x75));
  72.         x.setLineWidth(linewidth);
  73.         x.setLineCap(PdfContentByte.LINE_CAP_ROUND);
  74.         x.moveTo(144, 36);
  75.         x.lineTo(1056, 564);
  76.         x.moveTo(144, 564);
  77.         x.lineTo(1056, 36);
  78.         x.stroke();
  79.  
  80.         Font font = new Font(t3, 20);
  81.         Paragraph p = new Paragraph("ITEXT", font);
  82.         document.add(p);
  83.         p = new Paragraph(20, "I\nT\nE\nX\nT", font);
  84.         document.add(p);
  85.         // step 5: we close the document
  86.         document.close();
  87.     }
  88.    
  89.     /**
  90.      * Main method.
  91.      *
  92.      * @param    args    no arguments needed
  93.      * @throws DocumentException
  94.      * @throws IOException
  95.      */
  96.     public static void main(String[] args) throws IOException, DocumentException {
  97.         File file = new File(DEST);
  98.         file.getParentFile().mkdirs();
  99.         new Logo().createPdf(DEST);
  100.     }
  101. }
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