0.0
No commit activity in last 3 years
No release in over 3 years
A native command line client library for the DocRaptor HTML to PDF/XLS service.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 1.11.2, ~> 1.11
>= 0.10.3, ~> 0.10
>= 11.1.2, ~> 11.1

Runtime

~> 0.3.0
 Project Readme

DocRaptor CLI

WARNING: This is a beta client and subject to serious change

This is a command line interface for using DocRaptor API to convert HTML to PDF and XLSX.

Installation

gem install docraptor-cli

Usage

docraptor local_file.html                              # local files
docraptor https://docraptor.com/examples/invoice.html  # URLs are detected by prefix

The full DocRaptor API is available, see:

Usage: docraptor [options] <url/file>

Server options:
    -k, --key KEY                    The API Key to use when calling the service. Defaults to YOUR_API_KEY_HERE or ENV[DOCRAPTOR_API_KEY].
    -s, --server SERVER              Make API requests against SERVER, scheme not required. Defaults to https://docraptor.com

Document options:
        --async                      Create document asynchronously(10 min limit). Defaults to synchronous(1 min limit).
    -d, --debug                      Enable debug logging.
        --no-ignore-resource-errors  Error when a resource cannot be downloaded.
    -j, --javascript                 Enable DocRaptor JavaScript parsing. Defaults to no javascript.
        --name NAME                  Give a name to this document. Defaults to a randomized string. Does not affect output filename.
        --referrer URL               Set HTTP REFERRER when rendering. Defaults to localhost for file rendering or render url.
        --strict STRICTNESS          Set HTML strictness. Defaults to none.
        --test                       Create this as a test document. Defaults to non-test.
    -t, --type TYPE                  Type of document to make, can be pdf, xls, xlsx. Defaults to pdf.

Prince options:
        --prince-baseurl URL         Set base url when rendering. Defaults to nothing for file rendering or render url.
        --prince-css-dpi DPI         Set a base CSS DPI. Defaults value used by Prince is 96.

...

We have guides for doing some of the common things:

Testing Callbacks

The --callback-url option can be used to set a URL that will receive a POST request after your document has successfully been processed. You can simulate this in your *nix development environment using a couple of simple tools: nc and ngrok.

Let's say you had some document content in a file named test.html. To test the callback URL, start a new console and type:

nc -lk 9001

This will listen on port 9001 for requests. Now open another console and type in:

ngrok http 9001

This will setup an external URL that port forwards to port 9001 on your computer (conveniently being listened to by nc). Note the ngrok http URL. It should look something like http://87654321.ngrok.io. Copy that URL and open a third console where we will generate our document:

bin/docraptor test.html --async --callback_url "http://87654321.ngrok.io"

After the document has been generated, if we go to our console running nc, we should see we got an HTTP POST request that looks something like this:

POST / HTTP/1.1
Connection: close
Host: d94c779c.ngrok.io
Content-Length: 139
Content-Type: application/x-www-form-urlencoded
X-Forwarded-For: 54.158.114.123

download_url=https%3A%2F%2Fdocraptor.com%2Fdownload%2Fe4eabaca-f811-49f8-9375-fcb9cdeae5aa&download_id=e4eabaca-f811-49f8-9375-fcb9cdeae5aa

More Help

DocRaptor has a lot of more styling and implementation options.

Stuck? We're experts at using DocRaptor so please email us if you run into trouble.

Development

This code is a thin wrapper around the docraptor gem to make it suitable for command line users.

Release Process

  1. Pull latest master
  2. Merge feature branch(es) into master
  3. script/test
  4. Increment version in code:
  • lib/docraptor-cli/version.rb
  1. Update CHANGELOG.md
  2. Commit "Release vX.Y.Z"
  3. rake release

Version Policy

This library follows Semantic Versioning 2.0.0.