I'm currently trying to build a little webtool and tried to add a logo to a PDF using the preProcessor in DataExporter (Primefaces). I have set up a server where the logo is stored.
Now when I try to export the DataTable into a PDFI keep getting this error message:
com.lowagie.text.Document cannot be cast to com.itextpdf.text.Document
Thats the bean that contains the preProcessor method
public void preProcessPDF (Object document) throws IOException, BadElementException, DocumentException
{
Document pdf = (Document) document;
ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext();
String logo = servletContext.getRealPath("") + File.separator + "http:" + File.separator + File.separator +"192.168.1.34:8080" + File.separator
+ "Bilder" + File.separator + "ubs.jpg";
pdf.add(Image.getInstance(logo));
}
That is the xhtml file :
<h:commandButton value="Als PDF exportieren">
<!-- <h:outputText value="Als PDF exportieren" />-->
<p:dataExporter type="pdf" target="modulbewertung"
fileName="zusammenfassung_modulbewertung"
preProcessor="#{handleEvents.preProcessPDF}"/>
</h:commandButton>