Most people use Portable Document Format (PDF) owing to the fact that document formatting is preserved when viewing these files on any platform. The fidelity of the document is not compromised when viewed either on a Desktop or mobile platform. But, in order to view the PDF file, you need to use a specific viewer application. So in order to overcome such shortcomings, the HTML format can be one of the viable solutions. In this article, we are going to discuss the details on how to convert PDF to HTML using C# .NET.
In this article, we are going to discuss the following topics in details
- PDF to HTML Conversion API
- Convert PDF to HTML - Result in Response
- PDF to HTML - Result in Cloud Storage
- Local Drive PDF to HTML - Output in Cloud Storage
PDF to HTML Conversion API
Aspose.PDF Cloud is based on REST architecture and offers the capabilities to create, edit as well as transform PDF to Supported Document Formats including HTML, JPEG, DOCX, PPTX, XLSX, SVG, etc. In this article, our focus is on the steps on how to convert PDF to HTML using C# .NET. This task can be accomplished using Aspose.PDF Cloud SDK for .NET which is a wrapper around Aspose.PDF Cloud so that you get all the features of REST API within your .NET application.
Or, you may also consider installing the SDK directly within the Visual Studio project as the NuGet package. All you need to do is expand the project tree in Solution Explorer, right-click the Packages folder and select Manage NuGet Packages… option from the context menu.
Now search Aspose.PDF Cloud in the search field, enable the checkbox beside the package name and click Add Package button.
Notice that Aspose.Pdf-Cloud.dll appears under the Packages folder.
After the installation, you need to Sign In on the cloud dashboard using your existing GitHub or Google account or, click on the Create a new Account button.
Convert PDF to HTML - Result in Response
Please follow the steps given below to perform the PDF to HTML conversion operation. The input PDF is loaded from cloud storage and the resultant HTML is returned as a response stream context that can be saved in a local drive or displayed directly in a web browser.
- The first step is to create a String variable defining Client ID and Client Secret details
- Secondly, create an instance of PdfApi while passing Client ID and Client Secret variables are arguments
- Thirdly, read the content of PDF file and load it in the Stream instance
- Then upload the PDF file to Cloud stroage using UploadFile(…) method of PdfApi class
- Finally, call the GetPdfInStorageToHtml(…) method to perform the conversion
PDF to HTML - Result in Cloud Storage
In this section, we are going to use an approach to convert PDF files to HTML and save the output in cloud storage. Please follow the steps given below to accomplish this requirement:
- Firstly, create an instance of PdfApi class by passing Client ID and Client Secret details as arguments
- Secondly, read the input PDF file to the Stream instance and specify the output file name with the .zip extension
- Thirdly, upload the PDF file to Cloud storage using the UploadFile(…) method
- Penultimate, call the PutPdfInStorageToHtml(…) method which takes input PDF filename and resultant file name as arguments
- Finally, print the response code in the console
Local Drive PDF to HTML - Output in Cloud Storage
In this section, we are going to discuss the steps on how we can load a PDF from a local drive, then convert PDF to HTML online and save the output in Cloud storage.
- The first step is to create an instance of PdfApi while passing Client ID and Client Secret as arguments
- Secondly, define string variables for input PDF and resultant .zip to be stored in cloud storage
- Thirdly, load the input PDF into the stream instance
- Finally, call the PutPdfInRequestToHtml(…) method which takes the resultant file name and stream holding PDF as arguments. The output is saved in Cloud storage
In this article, we have discussed the steps on how to convert PDF to HTML in various approaches. We managed to load the PDF file already stored in Cloud storage as well as loaded a file from the local drive and converted it to HTML format. Please be noted that Aspose.PDF Cloud SDK for .NET is distributed under an MIT license and its complete source code is available for download over GitHub. In case you encounter any issue while using the API, or you have any related queries, please feel free to contact us through the Free product support forum.
We also recommend visiting the following links to learn more about