我在该库中遇到一些问题,请帮助我,我已经尝试过使用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"));将加载字体,然后您可以照常使用drawString。

关于android - PDFbox此字体类型仅支持8位代码点,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42990347/

10-11 09:31
查看更多