更新时间:2023-02-08 22:09:17
您不再需要显式传递/添加CSS文件,pdfHTML(Html2Pdf是一段时间内的内部开发名称),可以选择链接到样式表中的样式表. HTML.如果您的CSS与HTML不在同一个文件夹中,则可能必须定义一个基本资源位置.
You no longer have to pass/add the CSS file explicitly, pdfHTML(Html2Pdf was the internal development name for a while), can pick up stylesheets linked in the HTML. You might optionally have to define a base resource location if your CSS is not located in the same folder as your HTML.
在您的HTML中,在标题中添加以下行
In your HTML, add the following line in the header
<link rel="stylesheet" type="text/css" href="bootstrap.css"/>
您想要将其添加到
File pdf = new File(pdfDest);
pdf.getParentFile().mkdirs();
PdfWriter writer = new PdfWriter(pdfDest);
PdfDocument pdfDoc = new PdfDocument(writer);
ConverterProperties converterProperties = new ConverterProperties().setBaseUri(resourceLoc);
HtmlConverter.convertToPdf(new FileInputStream(htmlSource), pdfDoc, converterProperties);
pdfDoc.close();