Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

primefaces p:dataexporter encoding for pdf

<h:commandLink>  
     Link
     <p:dataExporter type="pdf" encoding="iso-8859-1" target="tablePorCategoria" preProcessor="#{categoryBean.preProcessPDF}" fileName="cars"/>  
</h:commandLink>
Comment

primefaces p:dataexporter encoding for pdf preProcessor

//cria o documento
    Document pdf = (Document) document;        
    
    //seta a margin e página, precisa estar antes da abertura do documento, ou seja da linha: pdf.open()
    pdf.setMargins(200f, 200f, 200f, 200f);
    pdf.setPageSize(PageSize.A4);
    pdf.addTitle("Título here brother");
    
    pdf.open();
    
    //aqui pega o contexto para formar a url da imagem
    ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext();
    String logo = servletContext.getRealPath("") + File.separator + "resources/images" + File.separator + "logo.png";

    
    //cria a imagem e passando a url
    Image image = Image.getInstance(logo);

    //alinha ao centro
    image.setAlignment(Image.ALIGN_CENTER);

    //adciona a img ao pdf
    pdf.add(image);
    

    //adiciona um paragrafo ao pdf, alinha também ao centro
    Paragraph p = new Paragraph("teste frase");
    p.setAlignment("center");
    pdf.add(p);
    
}[/code]
Comment

PREVIOUS NEXT
Code Example
Java :: open youtube by default in full screen pragmatically 
Java :: java startActivity crash 
Java :: kubernetes java client create namespace 
Java :: trivers json node as node type2 
Java :: java hashset api 
Java :: iterade dict javacirpt 
Java :: java.lang.ArrayIndexOutOfBoundsException: 4 
Java :: crud repository count number of items in a list 
Java :: hash tree in java 
Java :: display pop up window overlay permission in redmi android studio 
Java :: compare time in java 
Java :: Caused by: java.lang.ClassNotFoundException: 
Java :: polymorphism vs overriding in java 
Java :: java break statement 
Java :: how to set current item for spinner android 
Java :: how to delete last array in java 
Java :: java or cpp 
Java :: searchview android example recyclerview 
Java :: java, how to find the most repeated character 
Java :: Black belt in grepper 
Java :: Java array repeating 
Java :: array srting line by line in textview android 
Sql :: safe update mysql 
Sql :: postgresql stop all connections 
Sql :: remove mysql from centos 7 
Sql :: fetch first 5 rows in oracle sql developer 
Sql :: oracle create table comment 
Sql :: sql drop table if exists 
Sql :: oracle table size 
Sql :: get schema of table sql 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =