I am doing html to pdf conversion
using iText.
I am already using HTMLWorker class (deprecated) having the following content code:
String htmlString = "<html><body> This is my Project <table width= '50%' border='0' align='left' cellpadding='0' cellspacing='0'><tr><td>{VERTICALTEXT}</td></tr></table></body></html>";
OutputStream file = new FileOutputStream(new File("C:\\Test.pdf"));
Document document = new Document();
PdfWriter.getInstance(document, file);
document.open();
HTMLWorker htmlWorker = new HTMLWorker(document);
htmlWorker.parse(new StringReader(htmlString ));
document.close();
file.close();
}
Now I want to replace {VERTICALTEXT}
dynamically with some string.
So I further added the code below:
PdfPTable table = null;
PdfPCell cell;
cell = new PdfPCell(new Phrase("My Vertical Text"));
cell.setRotation(90);
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
table.addCell(cell);
String verticalLoc = table.toString(); //this variable should hold the text "My Vertical Text" in 90 degree rotated form.
HashMap<String, String> map = new HashMap<String, String>();
map.put("VERTICALTEXT", verticalLoc);
html = new String(buffer);
for (HashMap.Entry<String, String> e : map.entrySet())
{
String value = e.getValue() != null ? e.getValue():"";
html = html.replace("{" + e.getKey() + "}", value);
}
htmlWorker.parse(new StringReader(htmlStr));
In the Output:
{VERTICALTEXT}
is replaced with com.itextpdf.text.pdf.PdfPTable@41d62bcO
Desired Output:
{VERTICALTEXT}
should be replaced with My Vertical Text
in a 90 degree rotated form.