我无法从html的PDF中获取特殊字符。我尝试使用UTF-8阅读,Windows-1257,ISO-8859-13等。但是没有任何效果,相反,我只能得到空格。
所以问题是如何解决?
JAVA
String d1 = "<html><head></head><body>...ą...č...ę...ė...į...š...ų...ū...ž...Ą...Č...Ę...Ė...Į...Š...Ų...Ū...Ž...</body></html>";
OutputStream myFile = new FileOutputStream(new File("C:\\My\\pdf1.pdf"));
Document document = new Document();
document.addCreationDate();
document.setPageSize(PageSize.A4);
document.setMargins(36, 36, 36, 36);
document.setMarginMirroring(true);
PdfWriter writer = PdfWriter.getInstance(document, myFile);
document.open();
XMLWorkerHelper worker = XMLWorkerHelper.getInstance();
InputStream is;
//is = new ByteArrayInputStream(d1.getBytes(StandardCharsets.UTF_8));
is = new ByteArrayInputStream(d1.getBytes("UTF-8"));
String FONT = "C:\\My\\FreeSans.ttf";
XMLWorkerFontProvider fontImp = new XMLWorkerFontProvider(XMLWorkerFontProvider.DONTLOOKFORFONTS);
fontImp.register(FONT);
worker.parseXHtml(writer, document, is, Charset.forName("UTF-8"), fontImp);
document.close();
myFile.close();
答案 0 :(得分:0)
Topaco对,在我添加字符串“ body style ...”之后,一切正常!