Convert XHTML to PDF – Cloud SDK and REST API

XHTML to PDF

XHTML is a markup language that combines the syntax of HTML with the strictness of XML, allowing for well-formed and structured web documents. Converting XHTML to PDF offers many benefits, most notably preserving web content’s layout, style, and structure in a portable and easily distributable format. PDF files maintain the integrity of the original XHTML content, including text formatting, images, and hyperlinks, making them ideal for distributing documents across multiple platforms and devices. In addition, PDF files are widely supported by various software applications and can be easily viewed and printed using PDF reading software, giving users universal access to content.

Aspose.HTML Cloud v4.0 provides the simplest API to convert XHTML documents to PDF format with high quality, easy and fast.

The article explains in a set of code examples how to convert an XHTML document to PDF using Aspose.HTML Cloud SDK and REST API. SDKs are available in PHP, C++, Python, C#, Ruby, Java, Android, Swift, and Node.js. We will consider various scenarios of XHTML to PDF conversion:

  • Converting a local XHTML file to PDF and saving the result in your local file system. In this scenario, we will explore both conversions with default conversion parameters and with explicitly specified parameters.
  • Converting XHTML to PDF in cloud storage with default conversion parameters.

Examples of XHTML to PDF Conversion

A widespread use case for Aspose.HTML Cloud functions is file processing and converting. Cloud SDK allows you to fetch an XHTML document from a storage location by its name or a local file on your drive, convert it to a specified format and save it to the storage or a local drive. The following code examples demonstrate how to convert XHTML to PDF for different cases using available SDKs and REST API.

Example 1. Convert XHTML to PDF with default conversion options

Consider converting an XHTML document initially located on a local file system to PDF format. The resultant file is then saved back to the local file system. The conversion occurs with default conversion options.

XHTML to PDF conversion occurs with the default conversion options: the resulting PDF document’s width and height correspond to A4, and all margins have zero value.

Example 2. Convert XHTML to PDF with explicitly specified options

The example below demonstrates how to convert an XHTML file from the local file system to PDF with explicitly specified options and save the result back to the local path.

More details about available conversion parameters for XHTML files are in the SDK Conversion Options section.

Example 3. Convert XHTML to PDF inside cloud storage

Aspose.HTML Cloud allows you to get an XHTML file from your cloud storage and save conversion result back to cloud storage. Let’s look at an example of conversion within the cloud storge with default saving options.

See Also