在PDFBox 2.0.8中的字体UbuntuCondensed-Regular中没有U + 000A的字形

时间:2018-02-20 13:18:56

标签: java pdfbox

请参阅我遇到此问题的代码,我主要担心的是在设置字体后,我在contentStream.showText()中收到错误,所以任何人都可以帮我设置PDFBox的字体,这是支持的Ubuntu的?

public class PDpage
{
        public static void main(String args[]) throws IOException
        {
            PDDocument searchableDocument = new PDDocument();
            String str2 = "/home/grid/Desktop/A.pdf";
            try 
            {
                String str = "/home/grid/Downloads/ubuntu-font-family-0.83/Ubuntu-C.ttf";
                String str1 = "/home/grid/Desktop/a.txt";
                File f = new File(str1);
                String s = FileUtils.readFileToString(f);
                PDPage page2 = new PDPage();
                searchableDocument.addPage(page2);
                PDPageContentStream contentStream = new PDPageContentStream(searchableDocument , page2);
                PDFont font = PDType0Font.load(searchableDocument, new FileInputStream(str));
                contentStream.beginText();
                contentStream.setFont(font, 12);
                contentStream.newLineAtOffset(20,750);
                contentStream.showText(s); 
                contentStream.endText();
                contentStream.close();
            } 
            catch (IOException e) 
            {
                e.printStackTrace();
            }
            searchableDocument.save(str2);
            searchableDocument.close();
        }
}

代码在运行时显示以下错误:

Exception in thread "main" java.lang.IllegalArgumentException: No glyph for U+000A in font UbuntuCondensed-Regular
at org.apache.pdfbox.pdmodel.font.PDCIDFontType2.encode(PDCIDFontType2.java:404)
at org.apache.pdfbox.pdmodel.font.PDType0Font.encode(PDType0Font.java:342)
at org.apache.pdfbox.pdmodel.font.PDFont.encode(PDFont.java:323)
at org.apache.pdfbox.pdmodel.PDPageContentStream.showText(PDPageContentStream.java:418)
at com.purpose.all.Strip.PDpage.main(PDpage.java:45)

此代码如何与不能将标签和空格插入PDBox PDF文档的问题相似?

0 个答案:

没有答案