/** * Copyright (C) 2008-2010, Squale Project - http://www.squale.org * * This file is part of Squale. * * Squale is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 3 of the * License, or any later version. * * Squale is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with Squale. If not, see <http://www.gnu.org/licenses/>. */ /* * Cr�� le 2 mars 05 * * Pour changer le mod�le de ce fichier g�n�r�, allez � : * Fen�tre>Pr�f�rences>Java>G�n�ration de code>Code et commentaires */ package org.squale.welcom.outils.pdf.advanced; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; import com.lowagie.text.DocumentException; import com.lowagie.text.Rectangle; import com.lowagie.text.pdf.PdfContentByte; import com.lowagie.text.pdf.PdfReader; import com.lowagie.text.pdf.PdfStamper; /** * @author M327837 Pour changer le mod�le de ce commentaire de type g�n�r�, allez � : * Fen�tre>Pr�f�rences>Java>G�n�ration de code>Code et commentaires */ public class WPdfDecoration { /** le header */ private WIPdfHeaderFooter header; /** le footer */ private WIPdfHeaderFooter footer; /** int */ private int startDecorationPage = 1; /** * Constructeur * * @param pHeader le header * @param pFooter le footer */ public WPdfDecoration( final WIPdfHeaderFooter pHeader, final WIPdfHeaderFooter pFooter ) { footer = pFooter; header = pHeader; } /** * Constructeur */ public WPdfDecoration() { this( null, null ); } /** * @param pdfReader le reader * @return le byte array "rempli" * @throws DocumentException exception pouvant etre levee * @throws IOException exception pouvant etre levee */ public byte[] fill( final PdfReader pdfReader ) throws DocumentException, IOException { final ByteArrayOutputStream tmpout = new ByteArrayOutputStream(); fill( pdfReader, tmpout ); return tmpout.toByteArray(); } /** * Met a la decoration du document; * * @param pdfReader le reader * @param out l'outputstream * @throws DocumentException exception pouvant etre levee * @throws IOException exception pouvant etre levee */ public void fill( final PdfReader pdfReader, final OutputStream out ) throws DocumentException, IOException { final int n = pdfReader.getNumberOfPages(); final PdfStamper stamp = new PdfStamper( pdfReader, out ); for ( int i = 1; i <= n; i++ ) { if ( i >= startDecorationPage ) { // PdfImportedPage page = stamp.getImportedPage (pdfReader, i); final PdfContentByte over = stamp.getOverContent( i ); final Rectangle pageSize = pdfReader.getPageSizeWithRotation( i ); if ( header != null ) { header.fill( over, pageSize, i, n ); } if ( footer != null ) { footer.fill( over, pageSize, i, n ); } } } stamp.close(); } /** * @return footer */ public WIPdfHeaderFooter getFooter() { return footer; } /** * @return header */ public WIPdfHeaderFooter getHeader() { return header; } /** * @param pFooter footer */ public void setFooter( final WIPdfHeaderFooter pFooter ) { footer = pFooter; } /** * @param pFooter header */ public void setHeader( final WIPdfHeaderFooter pFooter ) { header = pFooter; } /** * @return startDecorationPage */ public int getStartDecorationPage() { return startDecorationPage; } /** * @param i startDecorationPage */ public void setStartDecorationPage( final int i ) { startDecorationPage = i; } }