Using iText, how can I apply css to my PDF document using CssResolver and CssFile?

前端 未结 4 2414
滥情空心
滥情空心 2021-02-20 14:00

Thanks for your help...

Problem

While converting an html table tag/snippet (which I have converted to string) into a PDF document...

I am able to

4条回答
  •  迷失自我
    2021-02-20 14:25

    For cssResolver you need to specify the absoulte path for the .css as shown below.

    HtmlPipelineContext htmlContext = new HtmlPipelineContext(null);
    
    htmlContext.setTagFactory(Tags.getHtmlTagProcessorFactory());
    
    CSSResolver cssResolver = XMLWorkerHelper.getInstance().getDefaultCssResolver(false);
    
    cssResolver.addCssFile("src\\template\\style.css",true);
    Pipeline pipeline = new CssResolverPipeline(cssResolver, new HtmlPipeline(htmlContext, new PdfWriterPipeline(document, writer)));
    
    XMLWorker worker = new XMLWorker(pipeline, true);
    XMLParser xmlParser = new XMLParser(worker);
    

提交回复
热议问题