使用pdfBox实现pdf转图片,解决中文方块乱码等问题
为什么要叫左木:
[code=java]
public static void testDrawLineText() throws Exception {
PDDocument document = new PDDocument();
PDPage page1 = new PDPage(PDRectangle.A4);
document.addPage(page1);
PDPageContentStream contentStream = new PDPageContentStream(document, page1);
OTFParser otfParser = new OTFParser(false, true);
OpenTypeFont otf = otfParser.parse(new File("D:/pdfbox/SourceHanSansCN-Heavy.otf"));
PDFont font = PDType0Font.load(document, otf, false);
String childContent = "测试啊泽11";
font.encode(childContent);
contentStream.beginText();
contentStream.setCharacterSpacing(0.5f);
contentStream.setFont(font, 15);
contentStream.showText(childContent);
contentStream.endText();
contentStream.close();
document.save("D:/pdfbox/testPdf.pdf");
document.close();
}
[/code]
|