|
Hi all. I’m trying to create a PDF document using iText 1.4.2. I would like to add a special footer at the end of document. I already addes the “Page x on y” stuff and it’s
working fine. My special footer also prints but on a blank page. If my document has only one page, everything’s ok. If
it has more than one page, the footer “creates” an extra page just
for it. I followed the recommendation saying that theses footer
things should be placed in the onEndPage event. In this document, I’m trying to create a table Here’s the code of the table : //An
object creating our standard table PDFStandardTable tablePoursuites =
new PDFStandardTable(100); tablePoursuites.setPadding(1);
tablePoursuites.setSpaceBetweenCells(0);
tablePoursuites.setCellsFitPage(true);
tablePoursuites.addColumn(7,PDFStandardTable.ALIGN_CENTER,"N°
doss."); tablePoursuites.addColumn(7,PDFStandardTable.ALIGN_CENTER,"N°
série"); tablePoursuites.addColumn(39,"Représentant
du créancier\nCréancier"); tablePoursuites.addColumn(8,PDFStandardTable.ALIGN_RIGHT,"Créance\nRésultat"); tablePoursuites.addColumn(8,PDFStandardTable.ALIGN_RIGHT,"Solde\nPerte"); tablePoursuites.addColumn(1,PDFStandardTable.ALIGN_RIGHT,"");
tablePoursuites.addColumn(30,"Etat\nRéférence créancier"); tablePoursuites.setLastHeaderRow(1);
tablePoursuites.prepareTableLines(); //Adds
a title to the table tablePoursuites.addColspanedLine(PDFStandardValues.boldItalicFont,
"Poursuites", Element.ALIGN_LEFT); //Adds the
headres tablePoursuites.addHeadersLine(PDFStandardValues.boldFontSmall); if
(virtualSituationBean.getDebtorRequisitionsListSize() == 0){ //Message
if nothing to display tablePoursuites.addColspanedLine(PDFStandardValues.normalFontSmall,
"Pas de poursuites.", Element.ALIGN_CENTER); }
else { //Adds th values for (SimpleVirtualCreditBean
current : virtualSituationBean.getDebtorRequisitionsList()) { tablePoursuites.addValuesLine(PDFStandardValues.normalFontSmall,
new String[]{current.getNumeroDossier(), current.getNumeroSerie(), current.getRepresentantCreancier(),
current.getCreance(), current.getSoldeRestant(), "",
current.getEtat()}); tablePoursuites.addValuesLine(PDFStandardValues.normalFontSmall,
new String[]{"", "", current.getCreancier(),
current.getResultat(), current.getPerte(), "", current.getReferenceCreancier()}); } //Adds the total
tablePoursuites.addTotalsLine(PDFStandardValues.boldFontSmall, new
String[]{"", "", "",
Tools.getBetragAsString(virtualSituationBean.getPoursuitesTotalCreance(),false,true),
Tools.getBetragAsString(virtualSituationBean.getPoursuitesTotalSoldeRestant(),false,true),
"", ""});
tablePoursuites.addTotalsLine(PDFStandardValues.boldFontSmall, new
String[]{"", "", "",
Tools.getBetragAsString(virtualSituationBean.getPoursuitesTotalResultat(),false,true),
Tools.getBetragAsString(virtualSituationBean.getPoursuitesTotalPerte(),false,true),
"", ""}); } document.add(tablePoursuites); Here’s the code for the events : public void
onOpenDocument(PdfWriter pdfWriter, Document document) { PdfContentByte
cb = pdfWriter.getDirectContent(); cb = pdfWriter.getDirectContent(); tpl = cb.createTemplate(50, 25); tpl.setBoundingBox(new Rectangle(0, 0, 50,
25)); try { helv = BaseFont.createFont("Helvetica",
BaseFont.WINANSI, false); } catch (DocumentException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } public void onEndPage(PdfWriter writer, Document
document) { PdfContentByte cb =
writer.getDirectContent(); try { cb.saveState(); PDFStandardLibrary.addLightHeader(document,
cb, helv); cb.restoreState(); } catch (DocumentException e) { e.printStackTrace(); } cb.saveState(); String text = "Page " +
writer.getPageNumber() + " sur "; float textSize = helv.getWidthPoint(text,
pageFontSize); float textBase = document.bottom() - 20; cb.beginText(); cb.setFontAndSize(helv, pageFontSize); cb.setTextMatrix(document.left(), textBase); cb.showText(text); cb.endText(); cb.addTemplate(tpl, document.left() +
textSize, textBase); cb.restoreState(); BaseFont bf =
BaseFont.createFont(BaseFont.HELVETICA_BOLDOBLIQUE, BaseFont.CP1252,
BaseFont.NOT_EMBEDDED); float fontSize =
PDFStandardValues.boldItalicFont.getCalculatedSize(); float imgOffset = 0; if (this.endOfPageImageName != null
&& !this.endOfPageImageName.equals("")){ Image img = Image.getInstance(Util.getImageAsByteArray(this.endOfPageImageName,
service.getFileContext(), GvuDebtEnforcementEnv.APP_NAME)); img.scalePercent(this.endOfPageImageScale); float imgWidth = (img.width() *
((float)this.endOfPageImageScale/(float)100)); float imgHeight = (img.height() *
((float)this.endOfPageImageScale/(float)100)); float x =
document.getPageSize().width() - document.rightMargin() - imgWidth; float y = document.bottomMargin() +
(bf.getAscentPoint(this.endOfPageText, fontSize) -
bf.getDescentPoint(this.endOfPageText, fontSize)); cb.saveState(); cb.addImage(img, imgWidth, 0, 0,
imgHeight, x, y); cb.restoreState(); } if (this.endOfPageText != null &&
!this.endOfPageText.equals("")){ cb.saveState(); cb.beginText(); cb.setFontAndSize(bf, fontSize);
cb.setColorFill(PDFStandardValues.boldItalicFont.color());
cb.showTextAligned(PdfContentByte.ALIGN_RIGHT,this.endOfPageText,document.getPageSize().width()-document.rightMargin(),document.bottomMargin()+imgOffset,0); cb.endText(); cb.restoreState(); } } public void onCloseDocument(PdfWriter pdfWriter,
Document document) { tpl.beginText(); tpl.setFontAndSize(helv, pageFontSize); tpl.setTextMatrix(0, 0); tpl.showText("" +
(pdfWriter.getPageNumber() - 1)); tpl.endText(); } Can someone help me ? Thank you. ------------------------------------------------------- Fabien Musolino Développeur Web (www.ne.ch) Service
du Traitement
de l'Information Faubourg du Lac 25 2000 Neuchâtel +41 32 889 84 21 ------------------------------------------------------- |
------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________ iText-questions mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/itext-questions
