IET
Decrease font size
Increase font size
Topic Title: Convert PDF File to HTML Locally in Java Applications Using REST API
Topic Summary:
Created On: 15 January 2013 07:37 AM
Status: Read Only
Linear : Threading : Single : Branch
Search Topic Search Topic
Topic Tools Topic Tools
View similar topics View similar topics
View topic in raw text format. Print this topic.
 15 January 2013 07:37 AM
User is offline View Users Profile Print this message



saaspose

Posts: 2
Joined: 15 January 2013

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 = "Link removed/v1.0/pdf/convert?format=html";
//sign URI
String signedURI = Sign(strURI);
InputStreamfileStream = new FileInputStream(inputPath);
//get response stream
InputStreamhtmlOutput = ProcessCommand(signedURI, "PUT", fileStream);

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

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

public static void getZippedFiles(InputStreamzipFile, String destination) {
try {

byte[] buf = new byte[1024];
ZipInputStreamzipinputstream = null;
ZipEntryzipentry;
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;
FileOutputStreamfileoutputstream;
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();
}
}
 07 March 2013 12:35 PM
User is offline View Users Profile Print this message



COllson

Posts: 2
Joined: 20 February 2013

Where to see it working?
 21 March 2013 09:42 AM
User is offline View Users Profile Print this message



MariaLynette

Posts: 3
Joined: 21 March 2013

Hi, Thanks for the codes. I hope it will be useful to many. May i know where to see it working. I'm also confused same as Collson. Please help me to come out of it.
 16 May 2013 04:06 AM
User is offline View Users Profile Print this message



Brookeann

Posts: 1
Joined: 16 May 2013

Hi, buddy, thanks for sharing such useful pdf to html sample code in java, and besides java, I believe c# is widely used in prorgamming, i would like to share my PDF to HTML converting soucr code in c#HTML to PDF converting source code in c# with all and also the vice versa.
 16 May 2013 07:26 AM
User is offline View Users Profile Print this message



StefyDilon

Posts: 2
Joined: 15 May 2013

This guide lines are huge advantage for programmers and web developers. Because still some individuals struggling with the converting source.

________________________

point of sale

Edited: 17 May 2013 at 09:51 AM by StefyDilon
 06 December 2013 09:52 PM
User is offline View Users Profile Print this message



twista123456

Posts: 1
Joined: 06 December 2013

I hope it will be useful Link removed to many. May i know where to see it working. I'm also confused same as Collson. Please help me to come out of it.
 22 March 2014 07:45 AM
User is offline View Users Profile Print this message



lalitv74

Posts: 6
Joined: 21 March 2014

dude show us few working samples!
Statistics

See Also:



FuseTalk Standard Edition v3.2 - © 1999-2014 FuseTalk Inc. All rights reserved.