HTML JPG PDF XML CGM
  Product Family
BMP

Merge HTML to PDF via Java

Sample code for concatenation HTML documents into single formats PDF on Java. Programmers can use this example code to placing HTML into PDF within any Web or Desktop Java based Application.

Merge HTML to PDF Using Java

In order to merge HTML to PDF, we’ll use Aspose.PDF for Java API which is a feature-rich, powerful, and easy to use concatenation API for Java platform. You can download its latest version directly from Maven and install it within your Maven-based project by adding the following configurations to the pom.xml.

Repository

<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>https://repository.aspose.com/repo/</url>
</repository>

Dependency

<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-pdf</artifactId>
<version>version of aspose-pdf API</version>
<classifier>jdk17</classifier>
</dependency>

How to merge HTML to PDF via Java

Java developers can easily load & merge HTML files to PDF in just a few lines of code.

<% ld-json %>

System Requirements

Aspose.PDF for Javais supported on all major operating systems. Just make sure that you have the following prerequisites.

  • Microsoft Windows or a compatible OS with Java Runtime Environment for JSP/JSF Application and Desktop Applications.
  • Development environment like Eclipse or IntelliJ IDEA.
  • Aspose.PDF for Java library referenced in your project.
 

This sample code shows HTML to PDF Java concatenation


	// create empty pdf document
	outputDoc = new com.aspose.pdf.Document();

	// html files can be parsed and loaded as Aspose Document
	//set html encoding
	//render all html to single large pdf page
	com.aspose.pdf.HtmlLoadOptions opt1 = new com.aspose.pdf.HtmlLoadOptions();
	opt1.setInputEncoding("UTF-8");
	opt1.setRenderToSinglePage(true);
	firstDoc = new com.aspose.pdf.Document("1.html", opt1);
	secondDoc = new com.aspose.pdf.Document("2.html", opt1);

	// add page from one document to another directly
	for (com.aspose.pdf.Page page : firstDoc.getPages())
		outputDoc.getPages().add(page);
	for (com.aspose.pdf.Page page : secondDoc.getPages())
		outputDoc.getPages().add(page);

	// save result pdf to file
	outputDoc.save("Merger_html_pdf.pdf", com.aspose.pdf.SaveFormat.Pdf);
	```
 

Combine HTML to PDF in Java

Convert or combine multiple HTML into single PDF file in Java is not straightforward task without using 3rd party library. This page shows how to merge multiple HTML files into a single PDF document using Aspose.PDF for Java. The example is written in Python but the API can be used in other programming languages. PDF files are merged such that the first one is joined at the end of the other document.

Repository

<repository>
    <id>AsposeJavaAPI</id>
    <name>Aspose Java API</name>
    <url>https://repository.aspose.com/repo/</url>
    </repository>
    

 

Dependency

<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-pdf</artifactId>
    <version>version of aspose-pdf API</version>
    <classifier>jdk17</classifier>
    </dependency>
    

 

About Aspose.PDF for .NET API

A PDF Processing Library to create cross-platform applications with the ability to generate, modify, merge, render, secure and print documents without using Adobe Acrobat. It supports merging various file formats into PDF including HTML and merging PDF documents into various output formats. Developers can easily render all HTML content in a single Page PDF as well as merge HTML files with SVG graphic tags to Tagged PDF files. .NET PDF API offers compression, table creation, graph & image functions, hyperlinks, stamp and watermarking tasks, extended security controls & custom font handling.
  • Merge HTML to PDF via Online App