DocRaptor

Documentation

HTML-to-PDF with Java

Test API Key: YOUR_API_KEY_HERE

Code Examples

Installation

To install the API client library to your local Maven repository, simply execute:

mvn install

To deploy it to a remote Maven repository instead, configure the settings of the repository and execute:

mvn deploy

After the client library is installed/deployed, you can use it in your Maven project by adding the following to your pom.xml:

<dependency>
  <groupId>com.docraptor</groupId>
  <artifactId>docraptor</artifactId>
  <version>2.0.0</version>
</dependency>

Usage

Below is a barebones example, more robust examples with file output and error handling, asynchronous generation, hosted documents, or asynchronous hosted documents are also available.

import java.io.*;
import java.net.*;
import com.docraptor.*;

public class Sync {
  public static void main(String[] args) throws Exception {
    DocApi docraptor = new DocApi();
    ApiClient client = docraptor.getApiClient();
    client.setUsername("YOUR_API_KEY_HERE");
    //client.setDebugging(true);

    Doc doc = new Doc();
    doc.setTest(true);                                                   // test documents are free but watermarked
    doc.setDocumentContent("<html><body>Hello World</body></html>");     // supply content directly
    // doc.setDocumentUrl("http://docraptor.com/examples/invoice.html"); // or use a url
    doc.setDocumentType(Doc.DocumentTypeEnum.PDF);                       // PDF or XLS or XLSX
    doc.setName("docraptor-java.pdf");                                   // help you find a document later
    doc.setJavascript(true);                                             // enable JavaScript processing
    // princeOptions = new PrinceOptions();
    // doc.setPrinceOptions(princeOptions);
    // princeOptions.setMedia("screen");                                // use screen styles instead of print styles
    // princeOptions.setBaseurl("http://hello.com")                     // pretend URL when using document_content
    docraptor.createDoc(doc);
  }
}

Documents created synchronously like above are limited to 60 seconds of generation time, the asynchronous method allows up to 10 minutes.

Our styling documentation and knowledge base contain tips and guides on creating headers, footers, page numbers, table of contents, and much more.

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