List of usage examples for com.lowagie.text.pdf FontMapper FontMapper
FontMapper
From source file:questions.graphics2D.ArabicText.java
public static void main(String[] args) { Document document = new Document(PageSize.A4); try {// w ww . j a va 2s. c o m PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT)); document.open(); String text1 = "\u0634\u0627\u062f\u062c\u0645\u0647\u0648\u0631"; String text2 = "\u0634"; java.awt.Font font = new java.awt.Font("arial", 0, 12); PdfContentByte cb = writer.getDirectContent(); java.awt.Graphics2D g2Shapes = cb.createGraphicsShapes(PageSize.A4.getWidth(), PageSize.A4.getHeight()); g2Shapes.setFont(font); g2Shapes.drawString("text1, expected to render RTL", 50, 100); g2Shapes.drawString(text1, 50, 120); g2Shapes.drawString("text2, expected to match right-most glyph above", 50, 140); g2Shapes.drawString(text2, 50, 160); g2Shapes.dispose(); ColumnText text = new ColumnText(cb); Font f = new Font( BaseFont.createFont("c://windows/fonts/arialuni.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED), 12); text.setSimpleColumn(50, 620, 545, 50); text.setRunDirection(PdfWriter.RUN_DIRECTION_RTL); text.setText(new Phrase(text1, f)); text.go(); text.setText(new Phrase(text2, f)); text.go(); FontMapper arialuni = new FontMapper() { public BaseFont awtToPdf(java.awt.Font font) { try { return BaseFont.createFont("c:/windows/fonts/arialuni.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); } catch (DocumentException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; } public java.awt.Font pdfToAwt(BaseFont font, int size) { return null; } }; java.awt.Graphics2D g = cb.createGraphics(PageSize.A4.getWidth(), PageSize.A4.getHeight(), arialuni); g.setFont(null); g.drawString("text1, not expected to render RTL", 50, 180); g.drawString(text1, 50, 200); g.drawString("text2, not expected to match right-most glyph above", 50, 220); g.drawString(text2, 50, 240); g.drawString("to your right you see what it SHOULD look like:", 50, 260); g.drawString("If it doesn't, the problem is in the JDK, it's not an iText problem.", 50, 280); g.dispose(); document.close(); } catch (Exception de) { de.printStackTrace(); } }
From source file:questions.graphics2D.SwingForceArialUni.java
public static void main(String[] args) { Document document = new Document(new Rectangle(210, 25)); try {//from w w w . j a va 2 s. c o m PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT)); document.open(); PdfContentByte cb = writer.getDirectContent(); FontMapper arialuni = new FontMapper() { public BaseFont awtToPdf(Font font) { try { return BaseFont.createFont("c:/windows/fonts/arialuni.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); } catch (DocumentException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; } public Font pdfToAwt(BaseFont font, int size) { return null; } }; Graphics2D g2 = cb.createGraphics(200, 50, arialuni); g2.setFont(null); g2.drawString("Greek mu: \u03bc - \u039c; degree symbol: \u00b0", 0, 40); g2.dispose(); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } // step 5: we close the document document.close(); }