我正在使用 htmlworker(itext 库)将 html 文档转换为 pdf,如下所示
String path = "temp.pdf";
PdfWriter pdfWriter = null;
// create a new document
Document document = new Document();
pdfWriter = PdfWriter.getInstance(document, new FileOutputStream(
path));
document.open();
HTMLWorker htmlWorker = new HTMLWorker(document);
String str = "";
StringBuilder contentBuilder = new StringBuilder();
BufferedReader in = null;
try {
in = new BufferedReader(new FileReader("temp1.html"));
while ((str = in.readLine()) != null) {
contentBuilder.append(str);
}
} catch (IOException e) {
System.out.print("HTML file close problem:" + e.getMessage());
} finally {
in.close();
}
String content = contentBuilder.toString();
htmlWorker.parse(new StringReader(content));
document.close();
现在我的问题是我能够使用上面的代码将 html 转换为 pdf。但如果我的 html 页面包含table标记,它将创建相同大小的td。如何在生成的 pdf 中设置td标签的宽度?提前致谢