2010-01-07 5 views
1

iText를 사용하여 PDF에 Helvetica 글꼴을 포함시키는 방법은 무엇입니까? 이다iText를 사용하여 PDF에 Helvetica 글꼴을 포함시키는 방법은 무엇입니까?

BaseFont helvetica = BaseFont.createFont(BaseFont.HELVETICA, 
     BaseFont.CP1252, BaseFont.EMBEDDED); 
Font font = new Font(helvetica, 20, Font.BOLD); 

, 이것은 false를 반환합니다 :

작동하지 않습니다 다음 나는 트루 타입의 createFont() 메서드에 매개 변수로 자신을 파일을 제공하는 경우

font.getBaseFont().isEmbedded() 

임베딩 작동합니다.

답변

2

예, 정의 된 글꼴 포함은 작동하지 않습니다.
작동하지 않습니다.
iText, 글꼴을 포함하려면 글꼴 리소스에 대한 액세스 권한이 있어야합니다. 정의 된 글꼴은 PDF 판독기에서 제공하므로 PDF 작성 프로세스 중에는 라이브러리에서 사용할 수 없습니다.

또한 각 PDF 리더는이 글꼴을 제공해야하지만이 글꼴에 대한 라이센스 방법을 자유롭게 선택할 수 있습니다. 라이센스는 PDF 파일을 표시하는 것을 제외하고는 최종 사용에 대한 사용을 금지 할 수 있습니다.

3

소스 코드를 파고 들었는데 iText가 특정 글꼴에 대해 BaseFont.EMBEDDED 플래그를 명시 적으로 무시하고 Helvetica가 그 중 하나 인 것으로 보입니다.

Helvetica에 글꼴 파일 (예 : TrueType .ttf)을 제공하면 포함이 작동하는 것 같습니다.

1

PDF 사양은 PDF 뷰어에서 사용할 수 있어야하므로 포함 할 필요가없는 8 가지 글꼴을 정의합니다. Helvetica는이 중 하나입니다.

+1

내 문제는 내가 그 8 렌더링 차이를 방지하기 위해 포함 PDF 파일에 사용 * 모든 * 글꼴을 포함 할 필요가 있다고했다. –

+3

PDF/A 규격에는 표준 PDF 글꼴을 비롯한 모든 글꼴 포함이 필요합니다. – rwong

1

이 프로그램은 itext가 가지고있는 모든 글꼴 스타일을 추가하는 데 도움이됩니다.

public class FontStyle{ 
public static void main(String[] args) { 

    // creation of the document with a certain size and certain margins 
    // may want to use PageSize.LETTER instead 
    Document document = new Document(PageSize.A4, 50, 50, 50, 50); 
    try { 
     // creation of the different writers 
     PdfWriter writer = PdfWriter.getInstance(document, 
       new FileOutputStream("SupportedFontsStyle.pdf")); 

     final Chunk NEWLINE = new ChunkPF("\n"); 
     document.open(); 
     Phrase phrase = new Phrase(); 

     LineSeparator lineSeperator = new LineSeparator(); 
     final Font font_h1_normal = FontFactory.getFont("Courier",8F, Font.NORMAL); 
     phrase.add(new Chunk("Courier", font_h1_normal)); 
     phrase.add(ChunkPF.NEWLINE); 
     final Font font_h2_normal = FontFactory.getFont("Courier-Bold", 8F,Font.BOLD); 
     phrase.add(new Chunk("Courier-Bold ", font_h2_normal)); 
     phrase.add(ChunkPF.NEWLINE); 
     final Font font_h3_normal = FontFactory.getFont("Courier-Oblique",8F, Font.NORMAL); 
     phrase.add(new Chunk("Courier-Oblique ", font_h3_normal)); 
     phrase.add(ChunkPF.NEWLINE); 
     final Font font_h4_normal = FontFactory.getFont("Courier-BoldOblique", 8F,Font.BOLD); 
     phrase.add(new Chunk("Courier-BoldOblique", font_h4_normal)); 
     phrase.add(ChunkPF.NEWLINE); 
     final Font font_h5_normal = FontFactory.getFont("Helvetica",8F, Font.NORMAL); 
     phrase.add(new Chunk("Helvetica ", font_h5_normal)); 
     phrase.add(ChunkPF.NEWLINE); 
     final Font font_h6_normal = FontFactory.getFont("Helvetica-Bold", 8F,Font.BOLD); 
     phrase.add(new Chunk("Helvetica-Bold ", font_h6_normal)); 
     phrase.add(ChunkPF.NEWLINE); 
     final Font font_h7_normal = FontFactory.getFont("Helvetica-BoldOblique",8F, Font.BOLD); 
     phrase.add(new Chunk("Helvetica-BoldOblique", font_h7_normal)); 
     phrase.add(ChunkPF.NEWLINE); 
     final Font font_h8_normal = FontFactory.getFont("Symbol", 8F,Font.NORMAL); 
     phrase.add(new Chunk("Symbol", font_h8_normal)); 
     phrase.add(ChunkPF.NEWLINE); 
     final Font font_h9_normal = FontFactory.getFont("Times-Bold",8F, Font.BOLD); 
     phrase.add(new Chunk("Times-Bold ", font_h9_normal)); 
     phrase.add(ChunkPF.NEWLINE); 
     final Font font_h10_normal = FontFactory.getFont("Times", 8F,Font.NORMAL); 
     phrase.add(new Chunk("Times ", font_h10_normal)); 
     phrase.add(ChunkPF.NEWLINE); 
     final Font font_h12_normal = FontFactory.getFont("Times-BoldItalic", 8F,Font.BOLDITALIC); 
     phrase.add(new Chunk("Times-BoldItalic ", font_h12_normal)); 
     phrase.add(ChunkPF.NEWLINE);    
     final Font font_h13_normal = FontFactory.getFont("Times-Italic",8F, Font.ITALIC); 
     phrase.add(new Chunk("Times-Italic ", font_h13_normal)); 
     phrase.add(ChunkPF.NEWLINE); 
     final Font font_h14_normal = FontFactory.getFont("Times-Roman", 8F,Font.NORMAL); 
     phrase.add(new Chunk("Times-Roman ", font_h14_normal)); 
     phrase.add(ChunkPF.NEWLINE); 
     final Font font_h15_normal = FontFactory.getFont("ZapfDingbats",8F, Font.NORMAL); 
     phrase.add(new Chunk("ZapfDingbats ", font_h15_normal)); 
     phrase.add(ChunkPF.NEWLINE);   

     document.add(phrase); 

     document.close(); 

    } catch (Exception ex) { 
     System.err.println(ex.getMessage()); 
    } 
} 

}

+0

이것은 질문에 관한 모든 것이 아닙니다. – mkl

관련 문제