2014-01-10 136 views

回答

0

您可以使用自定義字體來使用iText編寫您的PDF。

  1. 你必須讓你正在尋找的自定義字體(我想這是你的是指:http://www.dafont.com/kg-primary-dots.font
  2. 我試着寫一個快速和骯髒的代碼來創建自定義行在PDF字體:

重要提示:請檢查並確認自定義字體的最終用戶協議被用於個人和商業目的

代碼:

public static void main(String[] args) { 

     Document document = new Document(); 
     try { 
      PdfWriter.getInstance(document, new FileOutputStream(
        "C:/users/XY/desktop/XY/Dotted.pdf")); 

      document.open(); 

      String text = "The test file for Kids"; 
      Font font = new Font(BaseFont.createFont("C:/Workspace/kg_primary_dots/KGPrimaryDotsLined.ttf", 
        BaseFont.IDENTITY_H, BaseFont.EMBEDDED), 72, Font.NORMAL); 

      Paragraph para = new Paragraph(text, font); 

      document.add(para); 
     } catch (DocumentException de) { 
      System.err.println(de.getMessage()); 
     } catch (IOException ioe) { 
      System.err.println(ioe.getMessage()); 
     } 

     document.close(); 
    } 

輸出:

enter image description here

+1

它爲我工作。謝謝你。 – STK

相關問題