-
1. Re: How do I position text in pdf absolutly?
specialagent.specialagentx.web.de Aug 30, 2010 1:27 PM (in response to hurzeler)Hi,
I need this information also. Is there any way to integrate iText manually into Seam? Without Facelets? I do have a PDF creating class, which I really like to reuse.
Thank you.
-
2. Re: How do I position text in pdf absolutly?
specialagent.specialagentx.web.de Aug 30, 2010 1:57 PM (in response to hurzeler)Hi,
I found a dirty solution for this! You must use your iText natively with the PdfContentByte. Do this you should
- inherit UIDocument from Seam, which does the PDF magic for you.
- overwrite method encodeEnd(..)
- get the PdfContentByte with super.getPdfContent();
- use iText natively
- use another binding in your facelets pageHere is an example for my quick'n'dirty solution:
...
import org.jboss.seam.annotations.Name;
import org.jboss.seam.pdf.ui.UIDocument;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPTable;
@Name("myuidoc")
public class PDF extends UIDocument {
@Override
public void encodeEnd(FacesContext arg0) throws IOException {
PdfContentByte cb = super.getPdfContent();
PdfPTable invoiceMetaDataTable = new PdfPTable(2);
invoiceMetaDataTable.getDefaultCell().setBorder(PdfPCell.NO_BORDER);
invoiceMetaDataTable.addCell("Datum:");
invoiceMetaDataTable.addCell(new Date().toString());
invoiceMetaDataTable.addCell("Steuer Nr.:");
invoiceMetaDataTable.addCell("XXXXXXX");
invoiceMetaDataTable.addCell("Rechnungs Nr.:");
invoiceMetaDataTable.addCell("659");
invoiceMetaDataTable.setTotalWidth(200.0f);
PdfPTable invoiceMetaDataTable0 = new PdfPTable(1);
invoiceMetaDataTable0.setTotalWidth(200.0f);
invoiceMetaDataTable0.getDefaultCell().setBorderWidth(1.5f);
invoiceMetaDataTable0.addCell(invoiceMetaDataTable);
invoiceMetaDataTable0.writeSelectedRows(0, 3, 350, 600, cb);
super.encodeEnd(arg0);
}
}Facelts:
<p:document xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://jboss.com/products/seam/pdf"
title="Invoice"
keywords="invoice, rechnung"
subject="Invoice"
binding="#{myuidoc}">Hope this helped!
-
3. Re: How do I position text in pdf absolutly?
specialagent.specialagentx.web.de Aug 30, 2010 1:59 PM (in response to hurzeler)Ok.... where is the preview button? :)
Here is an example for my quick'n'dirty solution:
... import org.jboss.seam.annotations.Name; import org.jboss.seam.pdf.ui.UIDocument; import com.lowagie.text.pdf.PdfContentByte; import com.lowagie.text.pdf.PdfPCell; import com.lowagie.text.pdf.PdfPTable; @Name("myuidoc") public class PDF extends UIDocument { @Override public void encodeEnd(FacesContext arg0) throws IOException { PdfContentByte cb = super.getPdfContent(); PdfPTable invoiceMetaDataTable = new PdfPTable(2); invoiceMetaDataTable.getDefaultCell().setBorder(PdfPCell.NO_BORDER); invoiceMetaDataTable.addCell("Datum:"); invoiceMetaDataTable.addCell(new Date().toString()); invoiceMetaDataTable.addCell("Steuer Nr.:"); invoiceMetaDataTable.addCell("XXXXXXX"); invoiceMetaDataTable.addCell("Rechnungs Nr.:"); invoiceMetaDataTable.addCell("659"); invoiceMetaDataTable.setTotalWidth(200.0f); PdfPTable invoiceMetaDataTable0 = new PdfPTable(1); invoiceMetaDataTable0.setTotalWidth(200.0f); invoiceMetaDataTable0.getDefaultCell().setBorderWidth(1.5f); invoiceMetaDataTable0.addCell(invoiceMetaDataTable); invoiceMetaDataTable0.writeSelectedRows(0, 3, 350, 600, cb); super.encodeEnd(arg0); } }
Facelts:
<p:document xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core" xmlns:p="http://jboss.com/products/seam/pdf" title="Invoice" keywords="invoice, rechnung" subject="Invoice" binding="#{myuidoc}">
Hope this helped!