DocRaptor

Documentation

HTML-to-PDF with .NET

Test API Key: YOUR_API_KEY_HERE

Code Examples

DocRaptor C# Native Client Library

This is a DLL and NuGet package for using DocRaptor API to convert HTML to PDF and XLSX.

Frameworks supported

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

Dependencies

Installation

Command line:

nuget.exe install DocRaptor

Package Manager Console:

Install-Package DocRaptor

Download DLLs: get DocRaptor.dll from GitHub

Usage

See examples for runnable examples with file output, error handling, etc.

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

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

    Doc doc = new Doc(
      Test: true,                                                    // test documents are free but watermarked
      DocumentContent: "<html><body>Hello World</body></html>",      // supply content directly
      // DocumentUrl: "http://docraptor.com/examples/invoice.html",  // 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: "http://hello.com"                               // pretend URL when using document_content
      // )
    );

    byte[] create_response = docraptor.CreateDoc(doc);
  }
}

Docs created like this are limited to 60 seconds to render, check out the async example which allows 10 minutes.

We have guides for doing some of the common things:

Converting HTML into PDF and XLS documents with .NET is fast and painless with DocRaptor. Just POST to our Docs API with your HTML content and some required parameters, either as a form serialized string or a JSON object.

Below you’ll find complete examples for .NET, but our API Reference Guide has all the details about the complete workings of the Docs API.

Circledoc@2x

With DocRaptor, your PDF content is HTML and its style is CSS - things you already know! Even still, it can be difficult to get your PDF to look just right. Check out our Style and Formatting Documentation for everything related getting a perfectly styled PDF!