• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

PDF File to HTML Conversion in Java Applications Using REST API

Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 = "http://api.saaspose.com/v1.0/pdf/convert?format=html";
//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 = zipinputstream.read(buf, 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
    Bookmark Topic Watch Topic
  • New Topic