I need to know if someone can help me about this cool free PDF generator: iText using JAVA. My request is this: I've a string with html tags such as:
<bold>Hi everyone</bolddd>, my name is <italic>Maurice</italic>.
Is possible to "parse" my string and make the PDF with the correct output about the font (bold, italic, etc etc etc)??
Thanks in advance.
Try the below code...
String htmlString="<bold>Hi everyone</bolddd>, my name is <italic>Maurice</italic>";
ArrayList p=new ArrayList();
StringReader strReader = new StringReader(htmlString);
Document document = new Document(PageSize.A4, 20, 20, 20, 50);
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("filename.pdf"));
document.open();
-------
-------
p = HTMLWorker.parseToList(strReader, null);
Paragraph paragraph=new paragraph();
for (int k = 0; k < p.size(); ++k){
paragraph.add((com.lowagie.text.Element)p.get(k));
}
document.add(paragraph);
-------
-------
document.close();
Hope this helps...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.