0
我已经进口PDFBOX-2.0.4.jar,fontbox-2.0.4.jar和共享记录-1.1.1.jar到Eclipse开普勒。该程序运行在win10上。 控制台打印大量此类警告pdfbox2.0.4将PDF转换与中国为PNG
org.apache.pdfbox.pdmodel.font.PDCIDFontType2 <init>
WARNING: Using fallback font ArialUnicodeMS for CID-keyed TrueType font KaiTi_GB2312.
我不能访问与整个内容的图像文件。我该如何解决它? 我的代码是这样的:
public class PdfboxTest {
private static final String filePath = "xxx";
private static final String outputFilePath = "xxx";
public static void change(File inputFile, File outputFolder) throws IOException {
String totalFileName = inputFile.getName();
String fileName = totalFileName.substring(0,totalFileName.lastIndexOf("."));
PDDocument doc = null;
try {
doc = PDDocument.load(inputFile);
PDFRenderer pdfRenderer = new PDFRenderer(doc);
int pageCounter = 0;
for(PDPage page : doc.getPages())
{
BufferedImage bim = pdfRenderer.renderImageWithDPI(pageCounter, 300, ImageType.RGB);
ImageIOUtil.writeImage(bim, outputFilePath + "\\" + fileName + (pageCounter++) +".png", 300);
}
doc.close();
} finally {
if (doc != null) {
doc.close();
}
}
}
public static void main(String[] args) {
File inputFile = new File(filePath);
File outputFolder = new File(outputFilePath);
if(!outputFolder.exists()){
outputFolder.mkdirs();
}
try {
change(inputFile, outputFolder);
} catch (IOException e) {
e.printStackTrace();
}
}
}
尝试安装缺少的字体,例如'KaiTi_GB2312',这是来自没有嵌入字体的PDF文件。 Re'我无法访问整个内容的图像文件'你是什么意思,这是一个权限问题,还是你的意思是图像中缺少中文文本? –
感谢您的编辑建议和问题建议。我通过安装字体KaiTi_GB2312解决了这个问题。现在我可以通过pdf获得整个内容的图像。 – dragic