如何在生成PDF时添加外部CSS? [英] How to add external CSS while generating PDF?

查看:257
本文介绍了如何在生成PDF时添加外部CSS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我正在使用以下代码在JSP文件中生成PDF:

Currently i am using following code to generate PDF in a JSP file:

response.setContentType("application/force-download");                                                          
response.setHeader("Content-Disposition", "attachment;filename=reports.pdf");                                                     
Document document = new Document();                                      
document.setPageSize(PageSize.A1);

PdfWriter writer = null;                                                      

writer = PdfWriter.getInstance(document, response.getOutputStream());                                         

document.open();                                                                                   

ByteArrayInputStream bis = new ByteArrayInputStream(htmlSource.toString().getBytes());                                                                                      

XMLWorkerHelper.getInstance().parseXHtml(writer, document, bis);                                                                   

document.close();     

这使我能够生成PDF。

With this am able to generate PDF.

但我想在生成PDF时添加CSS文件。

But i would like to add CSS file while generating PDF.

请帮助我......

Please Help me...

推荐答案

我不确定在java中如何使用但在c#中你可以通过以下代码添加外部样式表代码或语法: -

i am not sure in java how can you use but in c# you can add external style sheet code or syntax by this code:-

StyleSheet css = new StyleSheet();
    css.LoadTagStyle("body", "face", "Garamond");
    css.LoadTagStyle("body", "encoding", "Identity-H");
    css.LoadTagStyle("body", "size", "12pt");

可能会帮助你

问候,
vinit

Regards, vinit

这篇关于如何在生成PDF时添加外部CSS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆