aspose file tools
The moose likes Blatant Advertising and the fly likes PDF File to HTML Conversion in Java Applications Using REST API Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Other » Blatant Advertising
Bookmark "PDF File to HTML Conversion in Java Applications Using REST API" Watch "PDF File to HTML Conversion in Java Applications Using REST API" New topic

PDF File to HTML Conversion in Java Applications Using REST API

sher azam
Ranch Hand

Joined: Jul 04, 2012
Posts: 60
This technical tip allows developers to convert local PDF file to HTML without using Saaspose or any other storage using Saaspose.Pdf REST API in your Java applications. Saaspose API returns the output as a ZIP file when converting to HTML. We will create and use getZippedFiles method in this example to save output ZIP file as HTML. Some important steps for performing this task is to build url to convert Pdf file, sign URI, execute signed URI request and get response stream.

Sample Code for Converting PDF File to HTML Locally

//build uri to convert Pdf file
String strURI = "";
//sign URI
String signedURI = Sign(strURI);
InputStream fileStream = new FileInputStream(inputPath);
//get response stream
InputStream htmlOutput = ProcessCommand(signedURI, "PUT", fileStream);

String destination = "c:\\OutputHTML\\";
boolean success = (new File(destination)).mkdir();

if (success) {
getZippedFiles(htmlOutput, destination);

public static void getZippedFiles(InputStream zipFile, String destination) {
try {

byte[] buf = new byte[1024];
ZipInputStream zipinputstream = null;
ZipEntry zipentry;
zipinputstream = new ZipInputStream(zipFile);

zipentry = zipinputstream.getNextEntry();
while (zipentry != null) {
// for each entry to be extracted
String entryName = destination + zipentry.getName();
entryName = entryName.replace('/', File.separatorChar);
entryName = entryName.replace('\\', File.separatorChar);
System.out.println("entryname " + entryName);
int n;
FileOutputStream fileoutputstream;
File newFile = new File(entryName);
if (zipentry.isDirectory()) {
if (!newFile.mkdirs()) {
zipentry = zipinputstream.getNextEntry();

fileoutputstream = new FileOutputStream(entryName);

while ((n =, 0, 1024)) > -1) {
fileoutputstream.write(buf, 0, n);

zipentry = zipinputstream.getNextEntry();

}// while

} catch (Exception e) {

Overview: Saaspose.Pdf

Saaspose.Pdf is a REST API to create, edit & manipulate PDF files. It also convert PDF file to DOC, DOCX, HTML, XPS, TIFF etc. You can create a new PDF either from scratch or from HTML, XML, template, database, XPS or an image. A PDF file can also be rendered to JPEG, PNG, GIF, BMP, TIFF and many other image formats. It works with any language like .NET, Java, PHP, Ruby, Python and many others. It is platform independent REST API & working with web, desktop, mobile or cloud applications alike.

More about Saaspose.BarCode

- Homepage of Saaspose.Pdf
- More Technical Tips by Saaspose.Pdf
- Ask technical questions/queries from Saaspose Support Team

Contact Information
Aspose Pty Ltd, Suite 163,
79 Longueville Road
Lane Cove, NSW, 2066
Saaspose - Your File Format Experts 2.0
Phone: 1.214.329.1520
Fax: 866.810.9465
It is sorta covered in the JavaRanch Style Guide.
subject: PDF File to HTML Conversion in Java Applications Using REST API