首页 > 解决方案 > 从 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();
}

那没有解决CSSResolverXMLWorkerHelper并且...在图书馆中。

标签: androidpdfitext

解决方案


推荐阅读