gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 19:18:13 24 4
gpt4 key购买 nike

我在使用这个库时遇到了一些问题,请帮助我,我尝试过使用 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")); 将加载字体,然后你可以像往常一样绘制字符串。

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com