How can I to repeat the logo on all pages of a PDF File

UI Components for JSF
Post Reply
Ivampire
Posts: 2
Joined: 08 Jun 2013, 00:48

27 Mar 2015, 23:03

Hello, How can I to repeat the logo on all pages of a PDF with preProcessPDF?

Hola a todos, quisiera saber como puedo repetir el logo en todas las paginas al crear con el p:dataExporter preProcessPDF un archivo pdf??

My code is the next:
Mi código es el siguiente:

----Vista---
<h:commandLink>
<h:graphicImage value="../images/downloadPdf.png" height="70" width="85" />
<p:dataExporter type="pdf" target="idDataTable" fileName="Archivo PDF" pageOnly="false"
preProcessor="#{bean.preProcessPDF}"/>
</h:commandLink>
-------------

----- BEAN ---------

public void preProcessPDF(Object document) throws DocumentException, BadElementException, MalformedURLException, IOException {
Document pdf = (Document) document;
pdf.setPageSize(PageSize.LEGAL.rotate());
pdf.setMargins(-0.10f, 0.0f, 30.5f, 1.5f);


if (!pdf.isOpen()) {
pdf.open();
ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext();
String logo = servletContext.getRealPath("") + File.separator + "comun" + File.separator + "images" + File.separator + "topImage.png";
System.out.println("logo: " + logo);
pdf.add(Image.getInstance(logo));
}
}
-----------------------------------------------


thank you very much for your help!!!
Muchas gracias por su ayuda.. saludos

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

28 Mar 2015, 10:40

By looking at the iText api and see how to create headers/footers

User avatar
sudheer
PrimeFaces Core Developer
Posts: 4345
Joined: 16 Oct 2011, 19:19
Location: Singapore

28 Mar 2015, 11:15

This requirement is not related to Primefaces but related to iText library only.You can try to add logo in the header section or follow any solutions from iText library side.
Author,Speaker
https://twitter.com/sudheerjonna
Github: https://github.com/sudheerj
Website http://sudheerjonna.com/

___________________
Sudheer Jonna

sergiool
Posts: 13
Joined: 29 Mar 2012, 11:28
Location: Cd. Sahagún; Hidalgo. México

28 Mar 2015, 12:26

Consulta estos sitios.
Check out these sites.


http://itextpdf.com/book/chapter.php?id=2

http://stackoverflow.com/questions/1120 ... text-5-2-1

http://stackoverflow.com/questions/1721 ... extlibrary

Espero te sean útiles.
I hope you find them useful.
Last edited by sergiool on 29 Mar 2015, 01:50, edited 1 time in total.
Primefaces 5.1
Mojarra 2.2.9
Glassfish 3.1.2
Wildfly 8.1
Ubuntu 14
Netbeans 8.0.1

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

28 Mar 2015, 15:44

English please...

Ivampire
Posts: 2
Joined: 08 Jun 2013, 00:48

30 Mar 2015, 18:25

*************SOLVED*************

English:
Thank you all for your support, your comments were very helpful finally got it, here I leave my solution, maybe someone needs it someday

P.D. Sorry for my bad English!!!

Español:
Gracias a todos por su ayuda, sus comentarios fueron de gran ayuda, finalmente lo conseguí, dejo mi código de referencia por si en el futuro alguien lo necesita.

//******************BEAN********************
import com.itextpdf.text.Element;
import com.lowagie.text.BadElementException;
import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.HeaderFooter;
import com.lowagie.text.Image;
import com.lowagie.text.PageSize;
import com.lowagie.text.Phrase;
import com.lowagie.text.Rectangle;
import java.io.File;
import javax.faces.context.FacesContext;
import java.net.MalformedURLException;




public void preProcessPDF(Object document) throws DocumentException, BadElementException, MalformedURLException, IOException {
Document pdf = (Document) document;
pdf.setPageSize(PageSize.LEGAL.rotate());
pdf.setMargins(-50.10f, -50.10f, 80.5f, 50.5f);

ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext();
Image logo = Image.getInstance(servletContext.getRealPath("") + File.separator + "comun" + File.separator + "images" + File.separator + "headerImage.png");
logo.setAlignment(Image.MIDDLE);
logo.scaleAbsoluteHeight(20);
logo.scaleAbsoluteWidth(20);
logo.scalePercent(100);
Chunk chunk = new Chunk(logo, 0, -30);
HeaderFooter header = new HeaderFooter(new Phrase(chunk), false);
header.setAlignment(Element.ALIGN_CENTER);
header.setBorder(Rectangle.NO_BORDER);
pdf.setHeader(header);

if (!pdf.isOpen()) {
pdf.open();
}
}
//**********************************************************************

//***********************PRIME FACES********************
<h:commandLink>
<h:graphicImage value=/images/downloadPdf.png" height="70" width="85" />
<p:dataExporter type="pdf" target="id_List_table" fileName="Listado X" pageOnly="false"
preProcessor="#{bean.preProcessPDF}"/>
</h:commandLink>

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 30 guests