Xml parsing and itext

2019-06-08 01:22发布

问题:

Just wanted to know if it is possible to change the font,color,font size while parsing html to pdf using xmlWorker.parser Currently I am able to parse whatever I have given as the input.So I wanted to change the font,font size, font color etc if possible. Thank you

回答1:

You can create your own CSS style and add it to your HTML code. The CSS style will be applied according the priority given below where no 4 is the higher priority.

1)Browser default 2)External style sheet 3)Internal style sheet 4)Inline style

Example:

document.open();
String finall=  "<style>h1{color:orange;} </style><body><h1>This is a Demo</h1></body>";
InputStream is = new ByteArrayInputStream(finall.getBytes());
XMLWorkerHelper.getInstance().parseXHtml(pdfWriter,document, is);
document.close();

In the Example Orange color will be set to the header.