Test in a live environment
Test in production without watermarks.
Works wherever you need it to.
PDF (Portable Document Format) is a widely used file format for representing documents in a manner independent of application software, third party software or drivers, hardware, and operating systems such as macOS. Manipulating PDF files programmatically without user intervention is a common requirement in various applications. This article explores two Java libraries, IronPDF and jPDFPrint, which provide capabilities for manipulating PDF files in different ways on a Java runtime environment. We will delve into their features, functionalities, and compare their offerings to understand their strengths and weaknesses and how it is different from using Acrobat PDF documents directly.
IronPDF is a powerful Java library that enables developers to create, manipulate, and convert PDFs programmatically. It provides a wide range of functionalities such as generating PDFs from HTML, images, or existing documents, merging multiple PDFs, extracting text and images from PDFs, and performing various document manipulation tasks.
IronPDF offers a user-friendly API with a comprehensive set of methods and properties, making it easy for developers to work with Acrobat PDF documents directly. It also provides extensive documentation and tutorials to guide developers through the process of integrating IronPDF into their Java applications.
One of the notable features of IronPDF is its ability to convert HTML to PDF. With this functionality, developers can easily generate PDF documents from HTML content, including CSS styles, JavaScript interactivity, and even dynamic data.
import com.ironpdf.*;
public class HtmlToPdfExample {
public static void main(String [] args) {
HtmlToPdfRenderer renderer = new HtmlToPdfRenderer();
HtmlToPdfOutput output = renderer.RenderHtmlFileAsPdf("input.html");
output.saveAs("output.pdf");
}
}
jPDFPrint is a Java library developed by Qoppa third party software that focuses specifically to print PDF documents programmatically on a Java runtime environment. It provides a simple and straightforward API for printing PDF documents using Java print documents service.
jPDFPrint allows developers to print PDF documents to any printer installed on the system, control the load and print document settings such as page range, orientation, and scaling, and even specify custom printer commands, if required. It also supports features like duplex printing, booklet printing, no user intervention silent print and watermarking.
The library integrates seamlessly with Java applications, enabling developers to easily incorporate PDF printing functionality into their Java application software solutions.
//import Qoppa third party software to simply call the library
import com.qoppa.pdfPrinter.PDFPrinterJob;
import java.io.File;
import java.io.IOException;
import java.net.URL;
public class HtmlToPdfExample {
public static void main(String [] args) throws IOException {
// Load the HTML page
URL url = new URL("http://www.example.com");
String html = org.apache.commons.io.IOUtils.toString(url);
// Create a PDFPrinterJob object
PDFPrinterJob printerJob = new PDFPrinterJob();
// Set the output file
File outputFile = new File("output.pdf");
printerJob.setOutputFile(outputFile);
// Print the HTML page to the output file
printerJob.printHTML(html);
}
}
Both libraries are very sophisticated and helpful to manipulate PDF documents such as print PDF documents, convert Microsoft Word documents to PDF documents.
jPDFPrint is a Java library developed by Qoppa Software using the Qoppa's proprietary PDF technology, that focuses on programmatic load and prints PDF files. Here is an overview of how to use it:
Import the Required Classes: Start by importing the necessary classes from the jPDFPrint library into your Java application.
package jPDFPrintSamples;
import java.io.FileOutputStream;
import javax.print.DocFlavor;
import javax.print.DocPrintJob;
import javax.print.SimpleDoc;
import javax.print.StreamPrintService;
import javax.print.StreamPrintServiceFactory;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.print.attribute.standard.MediaSizeName;
PDFPrint
Object: Create an instance of the PDFPrint
class and pass the path of the PDF file you want to print as a parameter.PDFPrint
class. You can set the printer name, specify page range, select paper trays, choose print quality, and configure other printing options to print PDF documents.Print the PDF: Call the print
method on the PDFPrint
object to initiate the printing process. The library will use the Java's Print Service to send the PDF file to the printer.
package jPDFPrintSamples;
import java.io.FileOutputStream;
import javax.print.DocFlavor;
import javax.print.DocPrintJob;
import javax.print.SimpleDoc;
import javax.print.StreamPrintService;
import javax.print.StreamPrintServiceFactory;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.print.attribute.standard.MediaSizeName;
import com.qoppa.pdfPrint.PDFPrint;
public class PDFToPS
{
public static void main (String [] args)
{
try
{
DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
String psMimeType = DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType();
StreamPrintServiceFactory [] factories = StreamPrintServiceFactory.lookupStreamPrintServiceFactories(flavor, psMimeType);
System.out.println ("Available PS services: " + factories.length);
if(factories.length == 0)
{
System.err.println ("No PS factories available!");
System.exit(0);
}
// Open the PDF file
PDFPrint pdfPrint = new PDFPrint ("test.pdf", null);
// Open the output file
FileOutputStream fos = new FileOutputStream("output.ps");
// Use the first service available
StreamPrintService sps = factories [0].getPrintService(fos);
DocPrintJob pj = sps.createPrintJob();
// Define paper size
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
aset.add(MediaSizeName.NA_LETTER);
// Create simple doc using PDFPrint as Printable and print it
SimpleDoc doc = new SimpleDoc(pdfPrint, flavor, null);
pj.print(doc, aset);
// Close the output PS stream
fos.close();
}
catch (Throwable t)
{
t.printStackTrace();
}
}
}
IronPDF is a powerful Java library used in the Java application for PDF manipulation, including PDF generation, conversion, and document manipulation. Here is an overview of how to use IronPDF:
Import the Required Classes: Begin by importing the necessary classes from the IronPDF library into your Java application.
import com.ironsoftware.ironpdf.*;
PDF Generation: To generate a PDF document, you have several options with IronPDF. For example, you can convert Java input, HTML content to PDF using the HtmlToPdfRenderer
class which is a PDF document's print command, as shown in the sample code to silent print or send documents to PDF. You can also create PDF documents programmatically by adding elements such as text, images, tables, and annotations.
import com.ironsoftware.ironpdf.*;
import java.io.IOException;
import java.nio.file.Paths;
// Apply your license key
License.setLicenseKey("YOUR-LICENSE-KEY");
// Set a log path
Settings.setLogPath(Paths.get("C:/tmp/IronPdfEngine.log"));
// Render the HTML as a PDF. Stored in myPdf as type PdfDocument;
PdfDocument myPdf = PdfDocument.renderHtmlAsPdf("<h1> ~Hello World~ </h1> Made with IronPDF!");
// Save the PdfDocument to a file
myPdf.saveAs(Paths.get("html_saved.pdf"));
Document Manipulation: IronPDF provides a range of methods and properties to manipulate existing PDF documents. You can merge multiple PDFs into a single document, split a PDF into multiple files, extract text and images, add watermarks, encrypt and decrypt PDFs, and much more.
import com.ironsoftware.ironpdf.PdfDocument;
import com.ironsoftware.ironpdf.font.FontTypes;
import com.ironsoftware.ironpdf.headerfooter.TextHeaderFooter;
import com.ironsoftware.ironpdf.headerfooter.HeaderFooterOptions;
import java.io.IOException;
// Initialize HeaderFooterOptions object.
HeaderFooterOptions options = new HeaderFooterOptions();
PdfDocument pdf = PdfDocument.renderUrlAsPdf("http://www.google.com");
// Add a header to every page easily
// Mergeable fields are:
// {page} {total-pages} {url} {date} {time} {html-title} & {pdf-title}
options.setFirstPageNumber(1); // use 2 if a cover page will be appended
TextHeaderFooter textHeader = new TextHeaderFooter();
textHeader.setDrawDividerLine(true);
textHeader.setCenterText("{url}");
textHeader.setFont(FontTypes.getHelvetica());
textHeader.setFontSize(12);
pdf.addTextHeader(textHeader, options);
// Add a footer too
TextHeaderFooter textFooter = new TextHeaderFooter();
textFooter.setDrawDividerLine(true);
textFooter.setFont(FontTypes.getArial());
textFooter.setFontSize(10);
textFooter.setLeftText("{date} {time}");
textFooter.setRightText("{page} of {total-pages}");
pdf.addTextFooter(textFooter, options);
try {
pdf.saveAs(Paths.get("assets/text_headers_footers.pdf"));
} catch (IOException e) {
System.out.println("Failed to save PDF");
throw new RuntimeException(e);
}
PDF Conversion: In addition to generating PDFs from HTML, IronPDF allows you to convert or print Acrobat PDF documents to various formats, such as images (JPEG, PNG, TIFF), HTML, and even Excel spreadsheets.
try {
List<BufferedImage> images = pdf.extractAllImages();
System.out.println("Number of images extracted from the website: " + images.size());
int i = 0;
for (BufferedImage image : images) {
ImageIO.write(image, "PNG", Files.newOutputStream(Path.of("assets/extracted_" + ++i + ".png")));
}
} catch(Exception exception) {
System.out.println("Failed to extract images from the website");
exception.printStackTrace();
}
saveAs
method to send documents to a stream or HTTP response.While both jPDFPrint and IronPDF offer PDF manipulation capabilities, IronPDF provides a more comprehensive set of functionalities and flexibility. IronPDF stands out in several ways:
HTML to PDF Conversion: IronPDF excels in converting HTML content to PDF, making it a suitable choice for applications that require dynamic PDF generation from web pages or HTML templates.
import com.ironsoftware.ironpdf.*;
import java.io.IOException;
import java.nio.file.Paths;
// Apply your license key
License.setLicenseKey("YOUR-LICENSE-KEY");
// Set a log path
Settings.setLogPath(Paths.get("C:/tmp/IronPdfEngine.log"));
// Render the HTML as a PDF. Stored in myPdf as type PdfDocument;
PdfDocument myPdf = PdfDocument.renderHtmlAsPdf("<h1> ~Hello World~ </h1> Made with IronPDF!");
// Save the PdfDocument to a file
myPdf.saveAs(Paths.get("html_saved.pdf"));
Rich Documentation and Support: IronPDF provides extensive documentation, tutorials, and a dedicated support team to assist developers in integrating the library and solving any issues that may arise during development.
import com.ironsoftware.ironpdf.PdfDocument;
import java.io.IOException;
import java.nio.file.Paths;
// Case 1: Generate a PDF from a string of Rich Text Content
try {
String content = "{\\rtf1\\ansi\\ansicpg1252\\deff0\\nouicompat\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Calibri;}}\n" +
"{\\*\\generator Riched20 10.0.22621}\\viewkind4\\uc1 \n" +
"\\pard\\sa200\\sl276\\slmult1\\b\\f0\\fs160\\lang9 Hello, world!\\par\n" +
"}\n" +
" ";
PdfDocument pdf = PdfDocument.renderRtfAsPdf(content);
pdf.saveAs(Paths.get("assets/rtf_to_pdf.pdf"));
} catch(IOException exception) {
exception.printStackTrace();
}
// Case 2: Generate a PDF from a RTF file located on a filesystem path
try {
PdfDocument pdf = PdfDocument.renderRtfFileAsPdf(Paths.get("assets/test.rtf"));
pdf.saveAs(Paths.get("assets/rtf_to_pdf_2.pdf"));
} catch(IOException exception) {
exception.printStackTrace();
}
Given these advantages, developers seeking a powerful and flexible PDF manipulation solution with HTML to PDF conversion capabilities, extensive document manipulation features, and excellent support should give preference to IronPDF over jPDFPrint.
However, it's essential to assess the specific requirements of your project and evaluate the features, documentation, and support offered by each library to make an informed decision that aligns with your application's needs.
jPDFPrint focuses solely on printing PDF files and provides extensive control over the printing process.
package jPDFPrintSamples;
import com.qoppa.pdfPrint.PDFPrint;
public class SimplePrint
{
public static void main (String [] args)
{
try
{
PDFPrint pdfPrint = new PDFPrint("input.pdf", null);
pdfPrint.print(null);
}
catch (Throwable t)
{
t.printStackTrace();
}
}
}
IronPDF offers a broader range of functionalities, including PDF generation from HTML, document manipulation, extraction of text and images, and more.
// Import statement for IronPDF Java
import com.ironsoftware.ironpdf.*;
// Apply your license key
License.setLicenseKey("YOUR-LICENSE-KEY");
// Set a log path
Settings.setLogPath(Paths.get("C:/tmp/IronPdfEngine.log"));
// Render the URL page as a PDF. Stored in myPdf as type PdfDocument
PdfDocument myPdf = PdfDocument.renderUrlAsPdf("/java");
// Save the PdfDocument to a file
myPdf.saveAs(Paths.get("url_saved.pdf"));
PdfDocument pdfDocument = PdfDocument.renderUrlAsPdf("/java");
jPDFPrint has a straightforward API specifically designed for PDF printing. It provides methods and properties to handle print settings and interact with printers.
IronPDF offers a comprehensive API with a wider scope of functionality. It provides methods and properties for creating, manipulating, and converting PDF documents, along with extensive support for HTML to PDF conversion.
jPDFPrint seamlessly integrates with Java applications and simplifies PDF printing tasks. It is well-documented and easy to integrate into existing projects.
IronPDF provides a user-friendly API with comprehensive documentation and tutorials. Its extensive set of features may require more effort to learn and integrate, but its capabilities offer a broader range of possibilities for PDF manipulation.
IronPDF excels in HTML to PDF conversion, allowing developers to generate PDF documents directly from HTML content, including CSS styling and JavaScript interactivity.
jPDFPrint does not provide native HTML to PDF conversion capabilities. Its main focus is on printing existing PDF files rather than generating them from HTML.
jPDFPrint provides advanced printing features such as duplex printing, booklet printing, watermarking, and more. It offers fine-grained control over the printing process and allows customization of printer commands.
IronPDF, on the other hand, does not specialize in printing features. Its main strength lies in PDF generation, manipulation, and extraction.
Both IronPDF and jPDFPrint have active communities and provide support for developers. Qoppa's proprietary PDF technology, the creator of jPDFPrint, offers comprehensive documentation, tutorials, and responsive customer support. IronPDF also provides extensive documentation and resources, including tutorials and a dedicated support team.
Licensing and pricing models differ between IronPDF and jPDFPrint. Developers should consider their project requirements, budget, and licensing constraints when choosing between the two libraries.
IronPDF offers a straightforward and open price structure that is based on the quantity of developers that will be using the product. A license can be bought for a single developer, a group of developers, or an organization with an unlimited number of developers. The costs are as follows:
You can use IronPDF in any number of projects with the purchase of a license, and you will get free upgrades and technical support for a year. You have the option to renew your license for a lower cost after the first year.
Perpetual, yearly, and subscription licenses are just a few of the licensing choices that Qoppa PDF provides. Depending on the particular parts and functionality you require, the price varies. For instance, a Qoppa PDF Automation Server perpetual license costs $4,000, whereas an annual license costs $1,500.
A royalty-based licensing scheme for web service orchestration is also provided by Qoppa PDF. This implies that you will be charged according to the volume of PDF files that your online service processes.
IronPDF for Java and jPDFPrint Java libraries provide distinct features for PDF manipulation. While jPDFPrint focuses on programmatically printing PDF files with advanced features and fine-grained control, IronPDF provides a comprehensive set of functionalities, including PDF generation from HTML, document manipulation, and extraction. IronPDF is a versatile PDF library for Java that allows developers to manipulate PDF files programmatically. It provides extensive functionality, such as PDF creation, editing, merging, splitting, and conversion from HTML. IronPDF offers a user-friendly API, easy-to-use features, and comprehensive documentation that simplify the development process for PDF manipulation.
On the other hand, jPDFPrint is a Java library designed specifically for printing PDF files programmatically. It provides advanced features, such as printer selection, page range selection, duplex printing, and paper size and orientation settings. jPDFPrint also offers an intuitive API, detailed documentation, and excellent customer support.
IronPDF offers a more straightforward and open pricing structure than jPDFPrint. IronPDF's licensing model is based on the number of developers who will be using the library, with options for a single developer, a team of developers, or an organization with an unlimited number of developers. IronPDF licenses are slightly cheaper than jPDFPrint's, with prices ranging from $749 to $5,999 per year, depending on the license type. IronPDF also offers free upgrades and technical support for the first year, with the option to renew at a lower cost.
In terms of technical capabilities, IronPDF offers a more comprehensive set of functionalities than jPDFPrint. IronPDF allows developers to manipulate PDF files in multiple ways, including PDF creation, editing, merging, splitting, and conversion from HTML. IronPDF also provides extensive documentation, a user-friendly API, and an easy-to-use interface that simplifies the development process for PDF manipulation.
Iron Software Products - Developers looking to purchase IronPDF or any other Iron Software product can take advantage of a "Buy 5, Pay for 2" offer available on the Iron Software website. This offer provides a substantial discount for developers who purchase multiple Iron Software products, including IronPDF, IronOCR, and IronBarcode, among others.
9 .NET API products for your office documents