jsf - Im trying to add a logo to a pdf file but theres an error message "com.lowagie.text.Document cannot be cast to com.itextpdf.text.Document" -
i'm trying build little webtool , tried add logo pdf using preprocessor in dataexporter (primefaces). have set server logo stored.
now when try export datatable pdfi keep getting error message:
com.lowagie.text.document cannot cast com.itextpdf.text.document
thats bean contains 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 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>
com.lowagie.text.document cannot cast com.itextpdf.text.document
this error message means you're trying cast object of type com.lowagie.text.document object of type com.itextpdf.text.document, while object isn't instance of @ all. that's happening in below line:
document pdf = (document) document; you need make sure import declaration document below:
import com.lowagie.text.document; and not other one. if can't import it, verify if you're using right version of itext. make sure don't have multiple different versioned itext libraries too.
unrelated concrete problem, should never ever use getrealpath(). rather use getresource() or getresourceasstream(). see what servletcontext.getrealpath("/") mean , when should use it. further, don't need fiddle around file.separator compose url.
Comments
Post a Comment