本文整理汇总了Java中com.openhtmltopdf.DOMBuilder类的典型用法代码示例。如果您正苦于以下问题:Java DOMBuilder类的具体用法?Java DOMBuilder怎么用?Java DOMBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DOMBuilder类属于com.openhtmltopdf包,在下文中一共展示了DOMBuilder类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: html5ParseDocument
import com.openhtmltopdf.DOMBuilder; //导入依赖的package包/类
private org.w3c.dom.Document html5ParseDocument(String urlStr, int timeoutMs) throws IOException {
URL url = new URL(urlStr);
org.jsoup.nodes.Document doc;
if (url.getProtocol().equalsIgnoreCase("file")) {
doc = Jsoup.parse(new File(url.getPath()), "UTF-8");
} else {
doc = Jsoup.parse(url, timeoutMs);
}
return DOMBuilder.jsoup2DOM(doc);
}
示例2: prepareItextRenderer
import com.openhtmltopdf.DOMBuilder; //导入依赖的package包/类
public static PdfBoxRenderer prepareItextRenderer(String page) {
PdfRendererBuilder builder = new PdfRendererBuilder();
builder.withW3cDocument(DOMBuilder.jsoup2DOM(Jsoup.parse(page)), "");
PdfBoxRenderer renderer = builder.buildPdfRenderer();
try (InputStream is = new ClassPathResource("/alfio/font/DejaVuSansMono.ttf").getInputStream()) {
renderer.getFontResolver().addFont(() -> is, "DejaVu Sans Mono", null, null, false);
} catch(IOException e) {
log.warn("error while loading DejaVuSansMono.ttf font", e);
}
renderer.layout();
return renderer;
}