Java Programing laungage

iText Projects

iText Project 1

adplus-dvertising
Rotate the Images
Previous Home Next

By help of this program we are trying to rotate the image in any direction in a pdf file. If the images is exists, then fine otherwise we are going to insert the image into the PDF file. For creating this program we are firstly need to import some packages. For make this program the first is to place the iText.jar into the WEB-INF/lib of our web application. Without iText.jar the application will not run. These packages will help us to make and use pdf file in our program. The packages we were talking about are

  • java.io.*;
  • com.lowagie.text.pdf.*; and
  • com.lowagie.text.*;

Now firstly we are creating a file name imagesRotate. what the program is going to perform. Inside the class declare a main method inside which we are going to write the logic of our program. Firstly make a object of Document class. This class describes a document's margins,page size,and other attributes.

Example:

package r4r;
import java.io.FileOutputStream;
import com.lowagie.text.Document;
import com.lowagie.text.Image;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;

public class rotateimagetest 
	{
public static void main(String[]args)throws Exception
	{
Document doc=new Document();
PdfWriter.getInstance(doc,new FileOutputStream
("rotateimagetest.pdf"));

doc.open();
Image img = Image.getInstance
("d:/r4r/rotateimage/images/bag.jpg");

doc.add(new Paragraph("Original Images of Bag:"));
doc.add(img);
img.scalePercent (10.0f);
img.setRotationDegrees (60.0f); 
doc.add(new Paragraph("After Rotation"));
doc.add(img);
doc.close();
}
}
Previous Home Next