PDFbox 此字体类型仅支持 8 位代码点

PDFbox This font type only supports 8-bit code points

我在使用这个库时遇到了一些问题,请帮助我,我已经尝试使用 roboto 和 arial ttf 但它不起作用,我正在尝试在 PDF 中编写 Sigma Σ 符号并以异常结束,我需要知道我是否需要对此进行编码,我该怎么做,在此先感谢

public void drawTable(PDPage page, PDPageContentStream contentStream,
                      float y, float margin,
                      String[][] content) throws IOException {
    final int rows = content.length;
    final int cols = content[0].length;
    final float rowHeight = 20f;
    final float tableWidth = page.getBBox().getWidth()-(2*margin);
    final float tableHeight = rowHeight * rows;
    final float colWidth = tableWidth/(float)cols;
    final float cellMargin=5f;

    //draw the rows
    float nexty = y ;
    for (int i = 0; i <= rows; i++) {
        contentStream.drawLine(margin,nexty,margin+tableWidth,nexty);
        nexty-= rowHeight;
    }

    //draw the columns
    float nextx = margin;
    for (int i = 0; i <= cols; i++) {
        contentStream.drawLine(nextx,y,nextx,y-tableHeight);
        nextx += colWidth;
    }


    //now add the text
    contentStream.setFont(PDType1Font.COURIER,12);
    PDTrueTypeFont robotoRegular = PDTrueTypeFont.loadTTF(document, getActivity().getAssets().open("arial.ttf"));
    robotoRegular.encode("WinAnsiEncoding");
    PDTrueTypeFont robotBold = PDTrueTypeFont.loadTTF(document, getActivity().getAssets().open("ariblk.ttf"));
    robotBold.encode("WinAnsiEncoding");
    float textx = margin+cellMargin;
    float texty = y-15;
    for(int i = 0; i < content.length; i++){
        for(int j = 0 ; j < content[i].length; j++){
            String text = content[i][j];
            contentStream.beginText();
            if (j==0){
                contentStream.setFont(robotBold,12);
            }else {
                contentStream.setFont(robotoRegular,12);
            }
//                byte[] commands = "Σ".getBytes();
//                commands[1] = (byte) 128;
//                contentStream.appendRawCommands(commands);
            contentStream.moveTextPositionByAmount(textx,texty);
            contentStream.drawString(text);
            contentStream.endText();
            textx += colWidth;
        }
        texty-=rowHeight;
        textx = margin+cellMargin;
    }
}

我已经测试过,使用 LiberationSans 作为字体将允许您对 sigma 符号进行编码。

PDFont liberationSans = PDType0Font.load(document, getActivity().getAssets().open("com/tom_roush/pdfbox/resources/ttf/LiberationSans-Regular.ttf"));会载入字体,然后就可以像往常一样绘制字符串了。