Merge PDF to HTML via Java
Sample code for concatenation PDF documents into single formats HTML on Java. Programmers can use this example code to placing PDF into HTML within any Web or Desktop Java based Application.
Merge PDF to HTML Using Java
In order to merge PDF to HTML, 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 PDF to HTML via Java
Java developers can easily load & merge PDF files to HTML in just a few lines of code.
- Initialize a new Document, and run a loop for merging files
- In loop: add a new page to HTML document
- In loop: add PDF file to new page
- After the loop save the result
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 PDF to HTML Java concatenation
// create empty pdf document
outputDoc = new com.aspose.pdf.Document();
// read pdf file to Aspose Document
firstDoc = new com.aspose.pdf.Document("1.pdf");
secondDoc = new com.aspose.pdf.Document("2.pdf");
// 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 html to file
// embed css into a page
// embed images into a page
// enhance conversion of documents with backgrounds
// use fixed layout render
opt1 = new com.aspose.pdf.HtmlSaveOptions();
opt1.setPartsEmbeddingMode(com.aspose.pdf.HtmlSaveOptions.PartsEmbeddingModes.EmbedAllIntoHtml);
opt1.setRasterImagesSavingMode(com.aspose.pdf.HtmlSaveOptions.RasterImagesSavingModes.AsEmbeddedPartsOfPngPageBackground);
opt1.setAntialiasingProcessing(com.aspose.pdf.HtmlSaveOptions.AntialiasingProcessingType.TryCorrectResultHtml);
opt1.setFixedLayout(true);
outputDoc.save("Merger_pdf_html.html", opt1);
Combine PDF to HTML in Java
Convert or combine multiple PDF into single HTML file in Java is not straightforward task without using 3rd party library. This page shows how to merge multiple PDF files into a single HTML 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>