Examples Iia - PHP Id 119
Examples Iia - PHP Id 119
StampStationery Page 1 of 2
You are here: Home > Support > Book > Chapter 6 > StampStationery
part2.chapter06.StampStationery
If you compile and execute this example, you'll get the following result:
original.pdf
stamped_stationary.pdf
You can download the full source code of StampStationery, or read it here:
/*
* This class is part of the book "iText in Action - 2nd Edition"
* written by Bruno Lowagie (ISBN: 9781935182610)
* For more info, go to: http://itextpdf.com/examples/
* This example only works with the AGPL version of iText.
*/
package part2.chapter06;
import java.io.FileOutputStream;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Set;
import java.util.TreeSet;
import com.lowagie.database.DatabaseConnection;
import com.lowagie.database.HsqldbConnection;
import com.lowagie.filmfestival.FilmFonts;
import com.lowagie.filmfestival.Movie;
import com.lowagie.filmfestival.MovieComparator;
import com.lowagie.filmfestival.PojoFactory;
import com.lowagie.filmfestival.PojoToElementFactory;
import com.itextpdf.text.Chunk;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfImportedPage;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStamper;
import com.itextpdf.text.pdf.PdfWriter;
public class StampStationery {
/** The original PDF file. */
public static final String ORIGINAL
= "results/part2/chapter06/original.pdf";
/** The resulting PDF. */
public static final String RESULT
= "results/part2/chapter06/stamped_stationary.pdf";
/**
* Main method.
* @param args no arguments needed
* @throws DocumentException
* @throws IOException
* @throws SQLException
*/
public static void main(String[] args)
throws IOException, DocumentException, SQLException {
Stationery.createStationary(Stationery.STATIONERY);
StampStationery stationary = new StampStationery();
stationary.createPdf(ORIGINAL);
stationary.manipulatePdf(ORIGINAL, Stationery.STATIONERY, RESULT);
}
/**
* Manipulates a PDF file src with the file dest as result
* @param src the original PDF
* @param stationery a PDF that will be added as background
* @param dest the resulting PDF
* @throws IOException
* @throws DocumentException
*/
public void manipulatePdf(String src, String stationery, String dest)
throws IOException, DocumentException {
// Create readers
PdfReader reader = new PdfReader(src);
http://itextpdf.com/examples/iia.php?id=119 3/3/2011
iText in Action: example part2.chapter06.StampStationery Page 2 of 2
http://itextpdf.com/examples/iia.php?id=119 3/3/2011