HTML-to-PDF with .NET


Code Examples

Frameworks supported

  • .NET 4.0 or later
  • Windows Phone 7.1 (Mango)



Command line:

nuget.exe install DocRaptor

Package Manager Console:

Install-Package DocRaptor

Download DLLs: get DocRaptor.dll from GitHub

Basic Usage

using DocRaptor.Client;
using DocRaptor.Model;
using DocRaptor.Api;
using System.IO;

class Example {
  static void Main(string[] args) {
    DocApi docraptor = new DocApi();
    docraptor.Configuration.Username = "YOUR_API_KEY_HERE";

    Doc doc = new Doc(
      test: true,                                                    // test documents are free but watermarked
      documentContent: "<html><body>Hello World</body></html>",      // supply content directly
      // documentUrl: "",  // or use a url
      name: "docraptor-csharp.pdf",                                  // help you find a document later
      documentType: Doc.DocumentTypeEnum.Pdf                         // pdf or xls or xlsx
      // Javascript: true,                                           // enable javaScript processing
      // princeOptions: new PrinceOptions(
      //   media: "screen",                                          // use screen styles instead of print styles
      //   baseurl: ""                               // pretend URL when using document_content
      // )

    byte[] createResponse = docraptor.CreateDoc(doc);

Next Steps

With DocRaptor, it's fast and painless to convert HTML, CSS, and JavaScript into PDF and XLS documents with .NET. Below are working .NET examples for creating documents. Our API reference lists all the generation options and our style and formatting guide will help make it look perfect.