Important alert: (current site time 7/15/2013 2:26:42 PM EDT)
 

article

PDF File to HTML Conversion in Java Applications Using REST API

Email
Submitted on: 1/14/2013 3:48:26 PM
By: aspose_seo 
Level: Intermediate
User Rating: Unrated
Compatibility: Java (JDK 1.3), Java (JDK 1.4), Java (JDK 1.5)
Views: 2250
 
     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.

 
 
Terms of Agreement:   
By using this article, you agree to the following terms...   
  1. You may use this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this article from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.
				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.Pdf
- Homepage of Saaspose.Pdf: http://saaspose.com/api/pdf 
- More Technical Tips by Saaspose.Pdf: http://saaspose.com/docs/display/pdf/1.2+-+Saaspose.Pdf+Examples 


Other 11 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Intermediate category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)
 

To post feedback, first please login.