Java examples on com.itextpdf
- How do I create a table in PDF document?
- How do I create a PDF document using iText?
- How do I set column width of a table in iText?
- How do I set cell border width and color in iText?
- How do I set paragraph indentation in iText?
- How do I create table cell that span multiple columns in iText?
- How do I set line space in Paragraph?
- How do I create an underlined or striked through chunk in iText?
- How do I set paragraph alignment in iText?
- How do I scale an image in pdf document using iText?
- How do I create internal anchor in iText?
- How do I set table's cell padding in iText?
- How do I add an image into PDF document in iText?
- How do I create Chapter in iText?
- How do I create anchor or link in iText?
- How do I set table's cell alignmen in iText?
- How do I create nested table in iText?
- How do I define a font for text object in iText?
- How do I set an image as the content of a cell in iText?
- How do I set the absolute position of an image in iText?
- How do I rotate cell contents in iText?
- How do I create a List in iText?
- How do I create super / subscript in iText?
- How do I use iText Document class?
- How do I rotate image in iText pdf document?
- How do I customize the Phrase object?
- How do I use iText Paragraph class?
- How do I use iText Chunk class?
- How do I set the width of a table in iText?
- How do I create ZapfDingbats List in iText?
- How do I use iText Phrase class?
- How do I create roman or greek numeral list in iText?
How do I scale an image in pdf document using iText?
There some methods of the com.itextpdf.text.Image class that can be use to scale the image. These methods include the following: scaleAbsolute(), scaleAbsoluteWidth(), scaleAbsoluteHeight(), scalePercent() and scaleToFit().
package org.kodejava.example.itextpdf;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Image;
import com.itextpdf.text.pdf.PdfWriter;
import java.io.FileOutputStream;
import java.io.IOException;
public class ImageScalingDemo {
public static void main(String[] args) {
Document document = new Document();
try {
PdfWriter.getInstance(document,
new FileOutputStream("ImageScaling.pdf"));
document.open();
//
// Scale the image to an absolute width and an absolute
// height
//
String filename = "other-sample/src/main/resources/java.gif";
Image image = Image.getInstance(filename);
image.scaleAbsolute(200f, 200f);
document.add(image);
//
// Scale the image to a certain percentage
//
String url = "http://localhost/xampp/img/xampp-logo-new.gif";
image = Image.getInstance(url);
image.scalePercent(200f);
document.add(image);
//
// Scales the image so that it fits a certain width and
// height
//
image = Image.getInstance(url);
image.scaleToFit(100f, 200f);
document.add(image);
} catch (DocumentException | IOException e) {
e.printStackTrace();
} finally {
document.close();
}
}
}