Convert XHTML to PDF using C# REST API

This article guides on how to convert XHTML to PDF using C# REST API. It will provide details to transform the file format from XHTML to PDF using C# RESTful Service with the help of a Dotnet-based Cloud SDK. Customization of the output PDF file will also be discussed.

Prerequisite

Steps for XHTML to PDF Converter using C# Low Code API

  1. Add Aspose.HTML.Cloud.Sdk and Aspose.HTML.Cloud.Sdk.Conversion to your application for accessing HTML Cloud API classes and conversion features
  2. Create an instance of HtmlApi by providing your Client ID and Client Secret for authentication with Aspose Cloud
  3. Retrieve the ConvertApi object from the initialized HtmlApi to perform document conversions
  4. Instantiate a PDFConversionOptions object to define output parameters for the PDF file
  5. Set the PDF page height to 8 inches and width to 11 inches (landscape format)
  6. Specify all four margins—top, bottom, left, and right—as 1 inch each
  7. Call ConvertAsync() on the convertApi to convert the XHTML file into a PDF

These steps explain how to change an XHTML document to PDF using C# .NET-based API. To convert your XHTML file into a PDF, first connect to Aspose Cloud by adding the SDK, authenticating with your Client ID and Secret, and then accessing the conversion API. After that, set up your PDF options such as page size and margins, and run ConvertAsync() to generate the final PDF.

Code to Convert XHTML to PDF Online using C# REST Interface

The above code demonstrates how to export an XHTML file to PDF using C# REST API. The simplest version of the code can be with two arguments only in the ConvertAsync() method i.e. without using the PDFConversionOptions. It creates the output PDF file with the default settings when no additional options are used.

This article has taught us the conversion of XHTML. To convert a Markdown file to PDF, refer to the article on Convert Markdown to PDF using C# REST API.

 English