HTML JPG PDF XML DOCX
  Product Family
PDF

Convert HTML to PDF in .NET SDK

Export HTML documents to multiple formats including PDF with Aspose.PDF Cloud .NET SDK

Get Started

How to Convert HTML to PDF Using SDK for .NET

In order to convert HTML to PDF, we’ll use Aspose.PDF Cloud .NET SDK This Cloud SDK allows you to easily build cloud-based PDF creator, editor & converter apps in C#, ASP.NET, or other .NET languages for various cloud platforms. Open NuGet package manager, search for Aspose.PDF Cloud and install. You may also use the following command from the Package Manager Console.

Package Manager Console Command


     
    PM> Install-Package Aspose.Pdf-Cloud
     
     

Steps to Convert HTML to PDF via .NET SDK

Aspose.PDF Cloud developers can easily load & convert HTML files to PDF in just a few lines of code.

  1. Create a new Configuration object with your Application Secret and Key
  2. Create an object to connect to the Cloud API
  3. Upload your document file
  4. Perform the conversion
  5. Download the result
 

This sample code shows HTML to PDF Cloud .NET SDK Conversion


    public static void ConvertHtmlToPdf()
    {
        const string localHtmlFileName = @"C:\Samples\Conversion\sample.html";
        const string storageHtmlFileName = "sample.html";
        const string resultFileName = "sample-html-to-pdf.pdf";
        
        // Get your AppSid and AppSecret https://dashboard.aspose.cloud (free registration required).
        var pdfApi = new PdfApi(AppSecret, AppSid);
        using var file = File.OpenRead(localHtmlFileName);
        pdfApi.UploadFile(storageHtmlFileName, file);
        
        var response = pdfApi.PutHtmlInStorageToPdf(resultFileName, storageHtmlFileName);
        Console.WriteLine($"HTML to PDF result: {response.Status}");
        pdfApi.DownloadFile(resultFileName)
            .CopyTo(File.Create(resultFileName));
    }
 
  • Other Supported Conversions

    You can also convert many other file formats

    BMP TO PDF (Bitmap Image)
    EMF TO PDF (Enhanced Metafile Format)
    EPUB TO PDF (E-book Format)
    GIF TO PDF (Graphical Interchange Format)
    HTML-TO-PDF (Hyper Text Markup Language)
    JPEG TO PDF (JPEG Image)
    MD TO PDF (Markdown)
    PCL TO PDF (Printer Command Language)
    PDF TO BMP (Bitmap Image)
    PDF TO DOCX (Office 2007+ Words Document)
    PDF TO EMF (Enhanced Metafile Format)
    PDF TO EPUB (E-book Format)
    PDF TO GIF (Graphical Interchange Forma)
    PDF TO HTML (Hyper Text Markup Language)
    PDF TO JPEG (JPEG Image)
    PDF TO PDF/A (Portable Document Format/A)
    PDF TO PNG (Portable Network Graphics)
    PDF TO PPTX (Open XML presentation Format)
    PDF TO SVG (Scalable Vector Graphics)
    PDF TO TEX (LaTeX Output Text)
    PDF TO TIFF (Tagged Image Format)
    PDF TO TXT (Text Document)
    PDF TO XLSX (OOXML Excel File)
    PDF TO XPS (XML Paper Specifications)
    PDF TO PPTX (Open XML presentation Format)
    PNG TO PDF (Portable Network Graphics)
    SVG TO PDF (Scalable Vector Graphics)
    TEX TO PDF (LaTeX Output Text)
    TEXT TO PDF (Text Document)
    TIFF TO PDF (Tagged Image Format)
    XPS TO PDF (XML Paper Specifications)