![]() |
IET | ![]() |


|
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: Post and Reply |
Linear : Threading : Single : Branch |
Search Topic |
Topic Tools
|
|
|
|
|
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(); } } |
|
|
|
|
|
|
|
|
Where to see it working?
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
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 |
|
|
|
|
FuseTalk Standard Edition v3.2 - © 1999-2013 FuseTalk Inc. All rights reserved.