The ability to convert PDF documents to HTML format is essential for a variety of purposes, such as web development or content management. Whether you’re a developer seeking to enhance website accessibility or a content creator looking to repurpose PDF content for online consumption, mastering the process of PDF to HTML conversion using C# .NET can significantly streamline your workflow and improve efficiency. In this article, we will explore all the details of PDF to HTML conversion using .NET REST API, covering everything from essential concepts to advanced techniques.
This article covers following topics:
- REST API for PDF to HTML Conversion
- Convert PDF to HTML using C# .NET
- Convert PDF to Web Page using cURL Commands
REST API for PDF to HTML Conversion
GroupDocs.Conversion Cloud SDK for .NET provides a robust and versatile solution for seamlessly converting PDF documents to HTML format. The SDK also provides advanced customization options, allowing you to specify conversion settings such as page range, image quality, and output file structure according to your specific requirements. In order to use the SDK, the first step is its installation. So, search GroupDocs.Conversion-Cloud in NuGet package manager and click the Install button. Another option is to execute the following command in package manager console.
NuGet\Install-Package GroupDocs.Conversion-Cloud -Version 24.2.0
Once the REST API is successfully installed, make sure you have the API credentials(i.e. Client ID and Client Secret). You may visit this short tutorial to see how to get the API credentials.
Convert PDF to HTML using C# .NET
The following section explains the details on how we can leverage the powerful capabilities of Cloud SDK and programmatically automate the PDF to HTML conversion task, using C# .NET.
- Create an instance of
Configuration
class where we pass client credentials as arguments.
var configurations = new Configuration(clientId, clientSecret1);
- Initialize the
ConvertApi
where we pass Configuration object as an input argument.
var apiInstance = new ConvertApi(configurations);
- Upload the input PDF file to cloud storage while passing the name for input PDF document.
fileUpload.UploadFile(new UploadFileRequest("input.pdf", stream));
- Create an instance
ConvertSettings
where we specify the name for input PDF, output format ashtml
and the name for resultant HTML file.
var settings = new ConvertSettings{...}
- Call the ConvertDocumentRequest API to convert PDF to HTML format. After successful conversion, the resultant HTML is stored in cloud storage.
var response = apiInstance.ConvertDocument(new ConvertDocumentRequest(settings));
The sample PDF file used in the above example can be downloaded from input.pdf.
Convert PDF to Web Page using cURL Commands
Converting PDF to HTML using GroupDocs.Conversion Cloud and cURL commands offers a convenient and scriptable solution for automating document conversion tasks. One of the key benefits of this approach is its simplicity and ease of integration into existing workflows and automation pipelines. With just a few simple commands, you can initiate and manage the conversion process without the need for complex code or additional libraries.
The first step in this approach is to obtain your personalized credentials (App Key and App SID) and generate JWT access token. Once we have JWT token, please execute the following cURL command to turn PDF into HTML format. The following command adds sample string as watermark but its optional.
curl -v "https://api.groupdocs.cloud/v2.0/conversion" \
-X POST \
-H "accept: application/json" \
-H "authorization: Bearer {accessToken}" \
-H "Content-Type: application/json" \
-d "{ \"FilePath\": \"{sourceFile}\", \"Format\": \"html\", \"LoadOptions\": { \"Format\": \"pdf\" }, \"ConvertOptions\": { \"FromPage\": 1, \"PagesCount\": 3, \"Pages\": [ 1,2,3 ], \"WatermarkOptions\": { \"Text\": \"Hello World !\", \"FontName\": \"Arial\", \"FontSize\": 10, \"Bold\": true, \"Italic\": true, \"Color\": \"Yellow\", \"Width\": 0, \"Height\": 0, \"Top\": 0, \"Left\": 0, \"RotationAngle\": 20, \"Transparency\": .5, \"Background\": true, \"AutoAlign\": true } }, \"OutputPath\": \"{resultantFile}\"}" -v
Please replace sourceFile
with the name of input PDF file available in cloud storage, resultantFile
with the name of output HTML format to be generated and accessToken
with JWT token generated above. After successful conversion, the resultant file is stored in cloud storage.
In case you want to save the resultant HTML to local drive, please use the following command.
curl -v "https://api.groupdocs.cloud/v2.0/conversion" \
-X POST \
-H "accept: application/json" \
-H "authorization: Bearer {accessToken}" \
-H "Content-Type: application/json" \
-d "{ \"FilePath\": \"{sourceFile}\", \"Format\": \"html\", \"LoadOptions\": { \"Format\": \"pdf\" }, \"ConvertOptions\": { \"FromPage\": 1, \"PagesCount\": 3, \"Pages\": [ 1,2,3 ], \"WatermarkOptions\": { \"Text\": \"Hello World !\", \"FontName\": \"Arial\", \"FontSize\": 10, \"Bold\": true, \"Italic\": true, \"Color\": \"Yellow\", \"Width\": 0, \"Height\": 0, \"Top\": 0, \"Left\": 0, \"RotationAngle\": 20, \"Transparency\": .5, \"Background\": true, \"AutoAlign\": true } } }" \
-o "resultant.html"
Free PDF to HTML Conversion App
You may consider using our free, lightweight and super-efficient PDF to HTML Converter developed on top of GroupDocs.Conversion API.
Useful Links
Conclusion
In conclusion, whether you choose to utilize GroupDocs.Conversion Cloud SDK for .NET or integrate GroupDocs.Conversion Cloud with cURL commands, converting PDF to HTML becomes a seamless and efficient process. Both approaches offer versatile solutions for automating document conversion tasks, empowering you to effortlessly bridge the gap between PDF and HTML formats. Overall, whether you prefer the convenience of an SDK or the flexibility of cURL commands, both approaches empower you to efficiently convert PDF to HTML and optimize your document processing workflows with confidence.
Related Articles
We highly recommend visiting the following links to learn more about: