android - 从 html 为旧的 android 设备创建 pdf
问题描述
当我使用时itextg:5.5.10
,我无法将 html 代码放入我的 pdf 文件中,并且不存在xmlWorker
于库中,我的目标代码是
public void createPdf() throws IOException, DocumentException {
String str = "my html code";
File file = new File(Environment.getExternalStorageDirectory() + File.separator + "logo.pdf");
OutputStream fileOutputStream = new FileOutputStream(file);
Document document = new Document();
// step 2
PdfWriter writer = PdfWriter.getInstance(document, fileOutputStream);
// step 3
document.open();
// step 4
// CSS
CSSResolver cssResolver =
XMLWorkerHelper.getInstance().getDefaultCssResolver(true);
// HTML
HtmlPipelineContext htmlContext = new HtmlPipelineContext(null);
htmlContext.setTagFactory(Tags.getHtmlTagProcessorFactory());
htmlContext.setImageProvider(new Base64ImageProvider());
// Pipelines
PdfWriterPipeline pdf = new PdfWriterPipeline(document, writer);
HtmlPipeline html = new HtmlPipeline(htmlContext, pdf);
CssResolverPipeline css = new CssResolverPipeline(cssResolver, html);
// XML Worker
XMLWorker worker = new XMLWorker(css, true);
XMLParser p = new XMLParser(worker);
p.parse(new ByteArrayInputStream(str.getBytes()));
// step 5
document.close();
}
那没有解决CSSResolver
,XMLWorkerHelper
并且...在图书馆中。
解决方案
推荐阅读
- javascript - IntersectionObserver 工作向下滚动但不向上滚动
- c# - CORS 政策 - 对预检请求的响应
- c++ - 在 C++ 中重新排列数组中的元素
- javascript - 代码在整个网页上错放了文本
- reactjs - TextField 不必要的重新渲染
- c - c: 自定义 shell > 重定向停止使用 < 甚至不运行的代码
- discord.py - Discord.py 没有看到用户/成员角色的更新
- reactjs - 尝试使用 React 上传图像时出现 AWS S3 403 Forbitten 错误
- sql - 确定日志条目是否是产品的第一个条目
- mysql - Vapor 4 Fluent 创建模型不会将其保存到数据库中