Friday, 21 October 2016

Itext: Rotating image

Image class provides following methods to rotate image.
setRotationDegrees()
setRotation()

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.pdf.PdfWriter;

public class TestImage {
    public static void main(String args[]) throws DocumentException, MalformedURLException, IOException {
        Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream("my_images.pdf"));
        document.open();

        Image image1 = Image.getInstance("lion.jpeg");
        image1.setRotationDegrees(45);
        document.add(image1);
        
        document.close();
    }
}



Previous                                                 Next                                                 Home

No comments:

Post a Comment