Output 2
Output 2
iTextPDF
iTextPDF is a popular Java library for creating and manipulating PDF documents. It provides
functionalities for generating PDF files dynamically, adding text, images, tables, and various other
elements to PDF documents. iTextPDF is widely used in enterprise applications for generating
reports, invoices, and other types of documents programmatically. It offers both open-source and
commercial versions, with the open-source version being licensed under the Affero General Public
License (AGPL).
2. iTextPDF Features
• PDF Splitter: This feature allows you to split a PDF document into two documents, either
by specifying page ranges or by other criteria. User can choose the page where you want
to split the PDF.
• PDF Merger: With the PDF merger feature, you can combine two PDF documents into a
single document. You can choose to reorder the files, or select which pages to merge from
each PDF. The default option is to merge "All" pages, but you can choose to merge the
PDFs from specific pages if you wish.
• PDF Rotator: The PDF rotator feature enables you to rotate pages within a PDF document.
You can then choose the rotation direction and angle you want. If you have uploaded a
PDF with multiple pages, you can choose if you want to rotate a specific page.
• PDF Page Deleter: This feature allows you to delete specific pages from a PDF document,
useful for removing unnecessary or confidential content.
• PDF Protector: With the PDF protector feature, you can apply encryption and permissions
to PDF documents. You can choose an Owner Password to protect the PDF with, and select
the Encryption options you want. You can also configure permissions for the PDF, for
example if you want to allow printing without entering the password. If you wish, you can
also set a User Password to allow restricted access to the PDF.
• PDF Unlocker: The PDF unlocker feature allows you to enter the Owner Password for the
PDF and providing access to restricted content.
• Image Converter: iTextPDF supports converting images to PDF format. You can choose
the page size and margin settings for the resulting PDF. You can also choose if you want
to rotate the image and set image position settings.
• SVG Converter: This feature allows you to convert Scalable Vector Graphics (SVG) files
to PDF format, preserving vector graphics quality and scalability.
• HTML to PDF Creator: With this feature, you can convert HTML content, such as web
pages or HTML documents, into PDF format, facilitating document generation from web-
based sources.
• XFA Flattener: iTextPDF supports flattening XFA (XML Forms Architecture) forms
within PDF documents. If you want to update the XFA data, or just flatten the XFA to a
static PDF. If you choose Update XFA Data you can edit the XML directly and download
the updated unflattened XFA form. To view the updated XFA data you'll need to use a PDF
viewer that supports XFA-based PDF forms.
• PDF Optimizer: The PDF optimizer feature allows you to reduce the file size of PDF
documents by compressing images, removing redundant data, and optimizing the
document structure. You can select an optimization profile to use. Each optimization
profile uses different types of compression to optimize a PDF, including image quality,
scaling, stream compression, font duplication, and font subsetting. The available profiles
range from Low to High compression, with a Lossless compression profile which
preserves image quality while applying all other optimizations.
• Render PDFs to Images: With this feature, you can render individual pages or entire PDF
documents as image files, such as JPEG or PNG, for various purposes, including display
or further processing. If you want to render all pages or a custom range. It is required to
select your preferred output format. You can select a scaling percentage value or enter a
custom number. The default is 100%.
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Image;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfImage;
import com.itextpdf.text.pdf.PdfIndirectObject;
import com.itextpdf.text.pdf.PdfName;
import com.itextpdf.text.pdf.PdfReader;
import java.io.IOException;
file.getParentFile().mkdirs();
image.scaleAbsolute(newWidth, newHeight);
image.setAbsolutePosition(absoluteX, absoluteY);
over.addImage(image);
stamper.close();
reader.close();