Displaying PDF files in the browser is essential for modern web applications such as content management portals, internal dashboards, document workflows, and online libraries. While basic PDF embedding with <iframe> works, it lacks flexibility, responsiveness, and custom UI options. The most powerful and customizable approach is to convert PDF pages into HTML and build your own online PDF viewer.
This guide explains how to create a full browser-based PDF viewer using .NET REST API. Therefore, by the end of this article, you will be able to embed a modern, lightweight, mobile-friendly PDF viewer into any C# web application.
Why PDF Viewer?
Building an online PDF viewer using HTML has several advantages:
- Mobile-Responsive - Converted pages scale automatically on mobile and tablets.
- Plugin-Free - No dependencies on browser PDF plugins.
- Fast Loading - Load only page-by-page HTML instead of the entire PDF.
PDF to HTML Conversion API
Aspose.PDF Cloud is an amazing REST API offering amazing capabilities for PDF generation and conversion into various other supported formats. Similarly, it also supports the conversion of PDF to HTML format. Now in order to convert PDF file to HTML web format within .NET application, try using Aspose.PDF Cloud SDK for .NET API.
Step 1 — Install Cloud SDK.
Install Aspose.PDF Cloud SDK for .NET via NuGet Package Manager:
Install-Package Aspose.PDF-Cloud
Step 2 - Cloud credentials. Obtain your Client ID and Client Secret from Aspose Cloud dashboard.
Export PDF to HTML using C#
Given below are the details on how we can develop “online PDF viewer” using C# .NET.
PdfApi pdfApi = new PdfApi(clientSecret, clientID);
Create an instance of PdfApi object while passing client secret details as argument.
var pdfFile = System.IO.File.OpenRead(inputFile);
Load the input PDF file from local drive as this API expects the input PDF as argument.
pdfApi.PutPdfInRequestToHtml("converted.zip",documentType: "Html5",
splitIntoPages: true, rasterImagesSavingMode: "AsPngImagesEmbeddedIntoSvg",
outputFormat: "Zip" , file: "inputPDF.pdf");
Save PDF as HTML using cURL
Other than C# code snippet, you may also consider exporting PDF as HTML using Aspose.PDF Cloud and cURL commands.
Step 1: Generate Access Token:
The first step in this approach is to generate JWT access token based on client credentials.
curl -v "https://api.aspose.cloud/connect/token" \
-X POST \
-d "grant_type=client_credentials&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"
Step 2. Save PDF as HTML:
curl -v "https://api.aspose.cloud/v3.0/pdf/{inputPDF}/convert/html?compressSvgGraphicsIfAny=false&documentType=Html5&fixedLayout=true&splitIntoPages=false&rasterImagesSavingMode=AsPngImagesEmbeddedIntoSvg&removeEmptyAreasOnTopAndBottom=true&flowLayoutParagraphFullWidth=true" \
-X GET \
-H "accept: multipart/form-data" \
-H "authorization: Bearer {ACCESS_TOKEN}" \
-o "Converted.zip"
Replace {ACCESS_TOKEN} and inputPDF with your actual token and PDF file available in cloud storage.
Free Online PDF to HTML Converter
In order to test the capabilities of the REST API in a web browser, you may consider using our free online PDF to HTML converter App. No software download or installation required.
Free PDF to HTML Converter App.
Conclusion
Building an online PDF viewer in C# becomes simple when using PDF → HTML conversion through Aspose.PDF Cloud REST API. HTML pages render natively in browsers, allowing you to build a feature-rich and fully customizable PDF viewer without plugins.
Whether you’re developing a document portal, an internal tool, or a public web application — the conversion of PDF to HTML format gives a flexibility to view PDF files online, without the need of Adobe Acrobat or any other software.
Useful Links
Related Articles
We highly recommend visiting the following blog posts for information on: