Rotate layout Example
iText is a free and open source library for creating and manipulating
PDF documents in Java. The following example shows rotating the screen layout of a PDF document.
package com.bethecoder.tutorials.itext.tests;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Image;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Rectangle;
import com.itextpdf.text.pdf.PdfWriter;
public class RotateRectange {
/**
* @param args
* @throws DocumentException
* @throws IOException
* @throws MalformedURLException
*/
public static void main ( String [] args ) throws DocumentException, MalformedURLException, IOException {
//Get rotated layout
Rectangle layout = new Rectangle ( PageSize.A4 ) .rotate () ;
Document document = new Document ( layout ) ;
PdfWriter.getInstance ( document, new FileOutputStream ( "test9.pdf" )) ;
//Open the document before adding any content
document.open () ;
Paragraph paragraph = new Paragraph ( "BE THE CODER" ) ;
document.add ( paragraph ) ;
//Get image to insert
document.add ( Image.getInstance ( "http://www.google.com/logos/2011/first_day_school-2011-hp.jpg" )) ;
document.add ( Image.getInstance ( "C:\\jfkinaugural11-hp.jpg" )) ;
//Close the document
document.close () ;
}
}
It gives the following output,