wood burning stoves 2.0*
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 Android Security Essentials Live Lessons this week in the Android 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
Author

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

SaasposeApp.setAppKey("9a6************************");
SaasposeApp.setAppSID("77**************************");
//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()) {
break;
}
zipentry = zipinputstream.getNextEntry();
continue;
}

fileoutputstream = new FileOutputStream(entryName);

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

fileoutputstream.close();
zipinputstream.closeEntry();
zipentry = zipinputstream.getNextEntry();

}// while

zipinputstream.close();
} catch (Exception e) {
e.printStackTrace();
}
}

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
Australia
Saaspose - Your File Format Experts 2.0
sales@aspose.com
Phone: 1.214.329.1520
Fax: 866.810.9465
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: PDF File to HTML Conversion in Java Applications Using REST API
 
Similar Threads
Exception in thread "main" java.io.FileNotFoundException: ReadZip (Access is denied)
Get PDF Links Count, Extract Specific Link or All Links of a PDF File
Replace Text on Specific PDF Page or Whole PDF Document Using REST API
Extract Images from Entire PDF File or Single PDF Page Using REST API
Count Form Fields, Get Form Fields Values of a PDF Document in Cloud