I have replaced itext-2.1.0.jar with openpdf-1.3.30.jar because of the securities risks present in itext. I'm getting the below error when pdf is getting generated:
java.lang.ClassCastException: java.lang.String cannot be cast to com.lowagie.text.Element
Below is my code which I think is causing this issue:
float[] columnWidths = { 2, 2, 8 };
PdfPTable table = new PdfPTable(columnWidths);
table.setSpacingBefore(40);
table.setWidthPercentage(100);
PdfPCell c1 = new PdfPCell(new Phrase(logtime, font));
c1.setFixedHeight(17);
c1.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(c1);
c1 = new PdfPCell(new Phrase(event, font));
c1.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(c1);
c1 = new PdfPCell(new Phrase(description, font));
c1.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(c1);
table.setHeaderRows(1);
when i searched the internet i got this (https://github.com/LibrePDF/OpenPDF/issues/274) not sure if this is my case.
Can anyone please tell me how to fix this issue?
My pdf looks like this :
----Sample Output --------
-x-x-x-x Some info present here -x-x-x-x-x-
| Column A | Column B |
|---|---|
| Cell 1 | Cell 2 |
| Cell 3 | Cell 4 |
-x-x-x-x End of Pdf -x-x-x-x-x
Note :- Number of columns are fixed and rows are dynamic
I tried hard coding the Element.ALIGN_CENTER but it did not work then i got to know the issue is in Phrase class of openpdf jar