IText + Custom component + ClassNotFoundException
sriramsudheer Apr 16, 2008 7:58 AMpackage xyz.components; import java.io.IOException; import java.io.Serializable; import javax.faces.context.FacesContext; import org.jboss.seam.annotations.In; import org.jboss.seam.log.Log; import org.jboss.seam.pdf.ui.ITextComponent; import org.jboss.seam.pdf.ui.UIDocument; import com.lowagie.text.DocumentException; import com.lowagie.text.Image; import com.lowagie.text.ImgTemplate; import com.lowagie.text.pdf.BarcodeEAN; import com.lowagie.text.pdf.BaseFont; import com.lowagie.text.pdf.PdfContentByte; import com.lowagie.text.pdf.PdfTemplate; import com.lowagie.text.pdf.PdfWriter; public class UIPdfLabel extends ITextComponent implements Serializable{ // @In Log log; public UIPdfLabel() { } @Override public void createITextObject(FacesContext context) { int x=10; int y=50; final UIDocument doc = (UIDocument) findITextParent(getParent(), UIDocument.class); if (doc != null) { final PdfWriter writer = (PdfWriter) doc.getWriter(); final PdfContentByte cb = writer.getDirectContent(); BaseFont descriptionFont = null; BaseFont apn_wareHouseFont = null; BaseFont supplierFont = null; BaseFont sellFont = null; BaseFont typeFont = null; BaseFont barcodeFont = null; try { descriptionFont = BaseFont.createFont(BaseFont.TIMES_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); apn_wareHouseFont = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); supplierFont = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); sellFont = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); typeFont = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); //barcodeFont = BaseFont.createFont("msi1.afm", BaseFont.WINANSI, BaseFont.EMBEDDED); } catch (DocumentException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } cb.beginText(); cb.setFontAndSize(descriptionFont, 14); cb.setTextMatrix(x, y); cb.showText("Centrom Tab 600MG 60TABS"); cb.endText(); cb.beginText(); cb.setFontAndSize(apn_wareHouseFont, 8); cb.setTextMatrix(x, y-8); cb.showText("0433769499 T"); cb.endText(); cb.beginText(); cb.setFontAndSize(sellFont, 36); cb.setTextMatrix(x+120, y-34); cb.showText("$12.34"); cb.endText(); BarcodeEAN barcodeEan = new BarcodeEAN(); barcodeEan.setCode("9780201615883"); barcodeEan.setCodeType(BarcodeEAN.EAN13); cb.concatCTM(1, 0, 0, 1, x, y-42); barcodeEan.placeBarcode(cb, null, null); PdfTemplate template = cb.createTemplate(x,y); /*try { template.addImage(image); } catch (DocumentException e1) { // TODO Auto-generated catch block e1.printStackTrace(); }*/ // Note: in a production system, exceptions should be // handled in a better way try { component = new ImgTemplate(template); } catch(Exception e) { System.out.println("Testing PDF Label"); System.out.println(e.getMessage()); } } } private Image component = null; @Override public void handleAdd(Object arg0) { throw new RuntimeException("No children allowed"); } @Override public void removeITextObject() { component = null; } /** This must return a com.lowagie.text.Element object, * or else it will throw a IllegalArgumentException("cannot add " + o) */ @Override public Object getITextObject() { return component; } }
facesConfig.xml:
<?xml version="1.0" encoding="UTF-8"?> <faces-config version="1.2" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"> <component> <component-type>xyz.UIPdfLabel</component-type> <component-class>xyz.UIPdfLabel</component-class> </component> <application> <view-handler>com.sun.facelets.FaceletViewHandler</view-handler> <locale-config> <default-locale>en</default-locale> <supported-locale>bg</supported-locale> <supported-locale>de</supported-locale> <supported-locale>en</supported-locale> <supported-locale>fr</supported-locale> <supported-locale>tr</supported-locale> </locale-config> </application> </faces-config>
and taglib.xml is
<?xml version="1.0"?> <!DOCTYPE facelet-taglib PUBLIC "-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN" "facelet-taglib_1_0.dtd"> <facelet-taglib> <namespace>http://xyz/products/dvComponents</namespace> <tag> <tag-name>pdfLabel</tag-name> <component> <component-type>xyz.UIPdfLabel</component-type> </component> </tag> </facelet-taglib>
and I am Getting CLassNotFound Exception could any one help what i am missing
Thank You In Advance
<p:document type="PDF" pageSize="A4" title="barcode" margins="1 1 1 1" xmlns="http://www.w3.org/1999/xhtml" xmlns:s="http://jboss.com/products/seam/taglib" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:rich="http://richfaces.org/rich" xmlns:dvComponent="http://xyz/products/dvComponents" xmlns:p="http://jboss.com/products/seam/pdf" template="layout/shelfTemplate.xhtml"> <dvComponent:pdfLabel> </dvComponent:pdfLabel> </p:document>