HELVETICA 无法解析或不是字段

A. *_*ary 1 java fonts pdfbox

我正在遵循在线教程。我正在使用 Eclipse 中的 PDFBox,并且在加载库中的字体时遇到问题。我已将所有 9 个 jar 加载到我的外部库中,不同的字体给了我相同的“无法解析或不是字段”。

import java.io.IOException;  
import org.apache.pdfbox.pdmodel.*;
import org.apache.pdfbox.pdmodel.font.PDType1Font;
import org.apache.pdfbox.pdmodel.font.PDFont;

public class PCSRR {
    
    public static void main(String[] args)throws IOException {
         PDDocument doc = new PDDocument();   
         PDPage blankPage = new PDPage();  
         doc.addPage( blankPage );  
         
         PDPage page = doc.getPage(1);  
         PDPageContentStream contentStream = new PDPageContentStream(doc, page);  
         
         //Begin the Content stream   
         contentStream.beginText();   
         contentStream.setFont(PDType1Font.HELVETICA , 14);
         contentStream.newLineAtOffset(20, 450);  
            String text = "Hi!!! This is the first sample PDF document.";  
         contentStream.showText(text);        
         contentStream.endText();  
            System.out.println("New Text Content is added in the PDF Document.");  
         contentStream.close();  
         
         doc.save("C:\\Users\\Aaron\\Desktop\\pdfbox\\practice.pdf");  
            System.out.println("PDF created"); 
         doc.close();  
    }
}
Run Code Online (Sandbox Code Playgroud)

外部罐子

小智 5

请改用这行代码。

 contentStream.setFont(new PDType1Font(Standard14Fonts.FontName.HELVETICA), 14);
Run Code Online (Sandbox Code Playgroud)