This is an outdated version of the HTML To PDF API. Please refer to Latest Version Documentation for the greatest functionality.

Introduction

Restpack HTML to PDF API is an easy to use RESTful web service that can capture live web pages and deliver the structured view as a PDF document. The service sits on a fully functional browser rendering engine with rich html / css / js capabilities.

Quick Start

Here are some code samples you can use. Don't forget to obtain a token here.

http --form POST https://restpack.io/api/html2pdf/v4/convert \
  x-access-token:TOKEN \
  url=http://google.com \
  json=truecurl --request POST \
  --url https://restpack.io/api/html2pdf/v4/convert \
  --header 'x-access-token: TOKEN' \
  --data 'url=http%3A%2F%2Fgoogle.com&json=true'var request = require("request");

var options = { method: 'POST',
  url: 'https://restpack.io/api/html2pdf/v4/convert',
  headers: { 'x-access-token': 'TOKEN' },
  form: { url: 'http://google.com', json: true } };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
require 'uri'
require 'net/http'

url = URI("https://restpack.io/api/html2pdf/v4/convert")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

request = Net::HTTP::Post.new(url)
request["x-access-token"] = 'TOKEN'
request.body = "url=http%3A%2F%2Fgoogle.com&json=true"

response = http.request(request)
puts response.read_bodyimport http.client

conn = http.client.HTTPSConnection("restpack.io")

payload = "url=http%3A%2F%2Fgoogle.com&json=true"

headers = { 'x-access-token': "TOKEN" }

conn.request("POST", "/api/html2pdf/v4/convert", payload, headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))package main

import (
	"fmt"
	"strings"
	"net/http"
	"io/ioutil"
)

func main() {

	url := "https://restpack.io/api/html2pdf/v4/convert"

	payload := strings.NewReader("url=http%3A%2F%2Fgoogle.com&json=true")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("x-access-token", "TOKEN")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := ioutil.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://restpack.io/api/html2pdf/v4/convert",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => "url=http%3A%2F%2Fgoogle.com&json=true",
  CURLOPT_HTTPHEADER => array(
    "x-access-token: TOKEN"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}var client = new RestClient("https://restpack.io/api/html2pdf/v4/convert");
var request = new RestRequest(Method.POST);
request.AddHeader("x-access-token", "TOKEN");
request.AddParameter("undefined", "url=http%3A%2F%2Fgoogle.com&json=true", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);HttpResponse<String> response = Unirest.post("https://restpack.io/api/html2pdf/v4/convert")
  .header("x-access-token", "TOKEN")
  .body("url=http%3A%2F%2Fgoogle.com&json=true")
  .asString();

You can find detailed usage information below.

Authentication

With each API call, you must provide an authentication token. To create a new access token please refer to user tokens page on your account dashboard.

You will need to use your Direct Access Token for simple API calls.

You can either provide the access token within the querystring or as a header.

  • If you wish to use the querystring method. Provide the token as access_token querystring parameter. As in https://restpack.io/api/html2pdf/v4/convert?access_token={TOKEN}
    http GET 'https://restpack.io/api/html2pdf/v4/convert?access_token=YOUR_ACCESS_TOKEN&url=URL_TO_CAPTURE'curl --request GET \
      --url 'https://restpack.io/api/html2pdf/v4/convert?access_token=YOUR_ACCESS_TOKEN&url=URL_TO_CAPTURE'var request = require("request");
    
    var options = { method: 'GET',
      url: 'https://restpack.io/api/html2pdf/v4/convert',
      qs: { access_token: 'YOUR_ACCESS_TOKEN', url: 'URL_TO_CAPTURE' } };
    
    request(options, function (error, response, body) {
      if (error) throw new Error(error);
    
      console.log(body);
    });
    require 'uri'
    require 'net/http'
    
    url = URI("https://restpack.io/api/html2pdf/v4/convert?access_token=YOUR_ACCESS_TOKEN&url=URL_TO_CAPTURE")
    
    http = Net::HTTP.new(url.host, url.port)
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
    
    request = Net::HTTP::Get.new(url)
    
    response = http.request(request)
    puts response.read_bodyimport http.client
    
    conn = http.client.HTTPSConnection("restpack.io")
    
    conn.request("GET", "/api/html2pdf/v4/convert?access_token=YOUR_ACCESS_TOKEN&url=URL_TO_CAPTURE")
    
    res = conn.getresponse()
    data = res.read()
    
    print(data.decode("utf-8"))package main
    
    import (
    	"fmt"
    	"net/http"
    	"io/ioutil"
    )
    
    func main() {
    
    	url := "https://restpack.io/api/html2pdf/v4/convert?access_token=YOUR_ACCESS_TOKEN&url=URL_TO_CAPTURE"
    
    	req, _ := http.NewRequest("GET", url, nil)
    
    	res, _ := http.DefaultClient.Do(req)
    
    	defer res.Body.Close()
    	body, _ := ioutil.ReadAll(res.Body)
    
    	fmt.Println(res)
    	fmt.Println(string(body))
    
    }<?php
    
    $curl = curl_init();
    
    curl_setopt_array($curl, array(
      CURLOPT_URL => "https://restpack.io/api/html2pdf/v4/convert?access_token=YOUR_ACCESS_TOKEN&url=URL_TO_CAPTURE",
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_ENCODING => "",
      CURLOPT_MAXREDIRS => 10,
      CURLOPT_TIMEOUT => 30,
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => "GET",
    ));
    
    $response = curl_exec($curl);
    $err = curl_error($curl);
    
    curl_close($curl);
    
    if ($err) {
      echo "cURL Error #:" . $err;
    } else {
      echo $response;
    }var client = new RestClient("https://restpack.io/api/html2pdf/v4/convert?access_token=YOUR_ACCESS_TOKEN&url=URL_TO_CAPTURE");
    var request = new RestRequest(Method.GET);
    IRestResponse response = client.Execute(request);HttpResponse<String> response = Unirest.get("https://restpack.io/api/html2pdf/v4/convert?access_token=YOUR_ACCESS_TOKEN&url=URL_TO_CAPTURE")
      .asString();
  • In case you want to use a header, please provide the access token in X-Access-Token header.
    http GET 'https://restpack.io/api/html2pdf/v4/convert?url=URL_TO_CAPTURE' \
      x-access-token:TOKENcurl --request GET \
      --url 'https://restpack.io/api/html2pdf/v4/convert?url=URL_TO_CAPTURE' \
      --header 'x-access-token: TOKEN'var request = require("request");
    
    var options = { method: 'GET',
      url: 'https://restpack.io/api/html2pdf/v4/convert',
      qs: { url: 'URL_TO_CAPTURE' },
      headers: { 'x-access-token': 'TOKEN' } };
    
    request(options, function (error, response, body) {
      if (error) throw new Error(error);
    
      console.log(body);
    });
    require 'uri'
    require 'net/http'
    
    url = URI("https://restpack.io/api/html2pdf/v4/convert?url=URL_TO_CAPTURE")
    
    http = Net::HTTP.new(url.host, url.port)
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
    
    request = Net::HTTP::Get.new(url)
    request["x-access-token"] = 'TOKEN'
    
    response = http.request(request)
    puts response.read_bodyimport http.client
    
    conn = http.client.HTTPSConnection("restpack.io")
    
    headers = { 'x-access-token': "TOKEN" }
    
    conn.request("GET", "/api/html2pdf/v4/convert?url=URL_TO_CAPTURE", headers=headers)
    
    res = conn.getresponse()
    data = res.read()
    
    print(data.decode("utf-8"))package main
    
    import (
    	"fmt"
    	"net/http"
    	"io/ioutil"
    )
    
    func main() {
    
    	url := "https://restpack.io/api/html2pdf/v4/convert?url=URL_TO_CAPTURE"
    
    	req, _ := http.NewRequest("GET", url, nil)
    
    	req.Header.Add("x-access-token", "TOKEN")
    
    	res, _ := http.DefaultClient.Do(req)
    
    	defer res.Body.Close()
    	body, _ := ioutil.ReadAll(res.Body)
    
    	fmt.Println(res)
    	fmt.Println(string(body))
    
    }<?php
    
    $curl = curl_init();
    
    curl_setopt_array($curl, array(
      CURLOPT_URL => "https://restpack.io/api/html2pdf/v4/convert?url=URL_TO_CAPTURE",
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_ENCODING => "",
      CURLOPT_MAXREDIRS => 10,
      CURLOPT_TIMEOUT => 30,
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => "GET",
      CURLOPT_HTTPHEADER => array(
        "x-access-token: TOKEN"
      ),
    ));
    
    $response = curl_exec($curl);
    $err = curl_error($curl);
    
    curl_close($curl);
    
    if ($err) {
      echo "cURL Error #:" . $err;
    } else {
      echo $response;
    }var client = new RestClient("https://restpack.io/api/html2pdf/v4/convert?url=URL_TO_CAPTURE");
    var request = new RestRequest(Method.GET);
    request.AddHeader("x-access-token", "TOKEN");
    IRestResponse response = client.Execute(request);HttpResponse<String> response = Unirest.get("https://restpack.io/api/html2pdf/v4/convert?url=URL_TO_CAPTURE")
      .header("x-access-token", "TOKEN")
      .asString();

Errors

Access token errors are represented in 4xx class HTTP errors.

  • 401 - in case no access token is provided.
  • 402 - when the account balance is not sufficient for this API call.
  • 403 - when the access token is not valid / revoked.

Response Modes

By default, the API returns the raw document itself. This is the easiest way to consume the API. You can stream the result back to a file, to a web request or any other storage service. Meanwhile, it is possible to receive a JSON response using mode: json parameter.

When you request a JSON response, API will return a JSON object with a publicly accesible URL to the resulting rendered pdf. You can use this document directly on your websites or access the file from this URL and save it elsewhere. Using this URL is not counted against your API call limits and it is being hosted over our CDN servers.

JSON responses simply contain an image URL, that points to the PDF and a cached field to indicate if the document is being served from cache:

{
  "image": "http://cdn.restpack.io/...",
  "cached": true
}

Endpoint

Create and return a PDF document

In order to create a PDF document, you simply need to invoke a GET request on the following URL.

All parameters should be passed in querysting.

GEThttps://restpack.io/api/html2pdf/v4/convert

Parameters

It is required to provide one of url or html parameters as the document source.

urlurl

The URL of web page, including the protocol that you want to capture.

Example: http://example.com
htmlstring

Raw HTML string of a page that you want to capture.

Example: <p>Test</p>
access_tokenstring

Your personal access token for API access.

jsonboolean

Return a JSON response with the resulting image's URL instead of the image itself.

Default: false
filenamestring

If specified, ensures that the resulting file is saved with the given name.

Example: mydocument.pdf
pdf_pageenum

Page size for created document

Default: FullPattern: A0 | A1 | A2 | A3 | A4 | A5 | A6 | Legal | Letter | Tabloid | Ledger | Full
pdf_widthstring

Custom pdf page width. Must be used together with pdf_height. Prefer pdf_page if you don't have an exact page size requirement.. Unit can be either px for pixels, in for inches.

Pattern: NUM[px|in]Example: 700px
pdf_heightstring

Custom pdf page height. Check pdf_width for details.

Pattern: NUM[px|in]Example: 30in
pdf_marginscss sizes

CSS style margin sizes. 1px 2px 3px 4px would cause 1px top, 2px right, 3px bottom, 4px left margins. A single size can be specified for both margins.

Default: 0Example: 30px 20px
pdf_orientationenum

Page orientation

Default: portraitPattern: portrait | landscape
pdf_headerstring

HTML template for page header. It should have a valid markup and can contain elements with classes 'pageNumber', 'totalPages', 'url', 'title' or 'date'. Header is automatically added to all pages. Note that you need to have top margins on your documents in order to have the header show up. Please add margins using pdf_margins. Check Headers and Footers section for more details.

Example: Page <span class="pageNumber"></span> of <span class="totalPages"></span>
pdf_footerstring

HTML template for page footer. Please check pdf_header information for details.

Example: Page <span class="pageNumber"></span> of <span class="totalPages"></span>
cssstring

Additional CSS string to be injected into the page before render.

jsstring

Additional JS string to be injected into the page before render.

delaynumber

Time in milliseconds to delay capture after page load.

Default: 500Max: 10000
ttlnumber

Time in milliseconds for the resulting image to be cached for further requests.

Default: 1 dayMax: 1 week
freshboolean

Force rendering a new screenshot disregarding the cache status.

Default: false
user_agentstring

Custom user-agent header string for the web request.

Default: Chrome Compatible User Agent
accept_languagestring

Custom accept-language header string for the web request.

headersstring

Additional headers seperated with newline

Example: X-Test: header\nAccept-Type: html
emulate_mediaenum

Force CSS media emulation for print or screen.

Default: screenPattern: screen | print
allow_failedboolean

By default, any response from remote server outside http 200-299 status codes generates an error. If you wish to capture error pages, pass true.

Default: false
waitenum

Wait until window load event fires or network becomes idle before capturing the page. By default we wait for the load event but if you are capturing pages with async content / lazy loaded images etc, waiting for network might work better. Third option is dom, which basically waits for domready event on the main window.

Default: loadPattern: load | network | dom
shutterstring

Wait until a DOM element matching the provided css selector becomes present on the page. You can control when you want to capture the page using this parameter. The process times out after 10 seconds.

Example: h1.someclass
block_adsboolean

Block / hide ads on the page.

Default: false
block_cookie_warningsboolean

Block / hide European Union cookie warnings before capture.

Default: false
POSThttps://restpack.io/api/html2pdf/v4/convert

POST mode accepts the exact same parameters but you need to use a JSON or url encoded body. access_token parameter still needs to be passed in the querystring or via x-access-token header.

Request & Response Sample:

http --form POST https://restpack.io/api/html2pdf/v4/convert \
  x-access-token:TOKEN \
  url=http://google.com \
  json=truecurl --request POST \
  --url https://restpack.io/api/html2pdf/v4/convert \
  --header 'x-access-token: TOKEN' \
  --data 'url=http%3A%2F%2Fgoogle.com&json=true'var request = require("request");

var options = { method: 'POST',
  url: 'https://restpack.io/api/html2pdf/v4/convert',
  headers: { 'x-access-token': 'TOKEN' },
  form: { url: 'http://google.com', json: true } };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
require 'uri'
require 'net/http'

url = URI("https://restpack.io/api/html2pdf/v4/convert")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

request = Net::HTTP::Post.new(url)
request["x-access-token"] = 'TOKEN'
request.body = "url=http%3A%2F%2Fgoogle.com&json=true"

response = http.request(request)
puts response.read_bodyimport http.client

conn = http.client.HTTPSConnection("restpack.io")

payload = "url=http%3A%2F%2Fgoogle.com&json=true"

headers = { 'x-access-token': "TOKEN" }

conn.request("POST", "/api/html2pdf/v4/convert", payload, headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))package main

import (
	"fmt"
	"strings"
	"net/http"
	"io/ioutil"
)

func main() {

	url := "https://restpack.io/api/html2pdf/v4/convert"

	payload := strings.NewReader("url=http%3A%2F%2Fgoogle.com&json=true")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("x-access-token", "TOKEN")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := ioutil.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://restpack.io/api/html2pdf/v4/convert",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => "url=http%3A%2F%2Fgoogle.com&json=true",
  CURLOPT_HTTPHEADER => array(
    "x-access-token: TOKEN"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}var client = new RestClient("https://restpack.io/api/html2pdf/v4/convert");
var request = new RestRequest(Method.POST);
request.AddHeader("x-access-token", "TOKEN");
request.AddParameter("undefined", "url=http%3A%2F%2Fgoogle.com&json=true", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);HttpResponse<String> response = Unirest.post("https://restpack.io/api/html2pdf/v4/convert")
  .header("x-access-token", "TOKEN")
  .body("url=http%3A%2F%2Fgoogle.com&json=true")
  .asString();
{
  "image": "http://cdn.restpack.io/...",
  "cached": true
}

Features

Headers and Footers

Captured documents do not contain any header or footer by default. If you wish to add page headers or footers you can provide an HTML template and the API automatically handles injection for you.

Note that we refer to these html snippets as templates because they can contain placeholders for dynamic data. For example if you wish to show the current page number somewhere within your header, you can use <span class="pageNumber"></span> element. The pageNumber class instructs our engine to inject the current page number in that element.

Available class names for dynamic data:

  • pageNumber: Current page number
  • totalPages: Total number of pages in the document
  • url: Captured page URL
  • title: Document title
  • date: Date of capture in UTF

Also note that you must have a pdf_margins paramater in order to use the header / footer functionality. The header and footer show up inside your top and bottom margins, you need to provide appropriate space for the headers and footers to render.

http --form POST https://restpack.io/api/html2pdf/v4/convert \
  x-access-token:TOKEN \
  url=http://google.com \
  delay=5 \
  pdf_margins='20px 0' \
  pdf_header='This is page <span class="pageNumber" style="color: red;"></span>'curl --request POST \
  --url https://restpack.io/api/html2pdf/v4/convert \
  --header 'x-access-token: TOKEN' \
  --data 'url=http%3A%2F%2Fgoogle.com&delay=5&pdf_margins=20px%200&pdf_header=This%20is%20page%20%3Cspan%20class%3D%22pageNumber%22%20style%3D%22color%3A%20red%3B%22%3E%3C%2Fspan%3E'var request = require("request");

var options = { method: 'POST',
  url: 'https://restpack.io/api/html2pdf/v4/convert',
  headers: { 'x-access-token': 'TOKEN' },
  form: 
   { url: 'http://google.com',
     delay: '5',
     pdf_margins: '20px 0',
     pdf_header: 'This is page <span class="pageNumber" style="color: red;"></span>' } };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
require 'uri'
require 'net/http'

url = URI("https://restpack.io/api/html2pdf/v4/convert")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

request = Net::HTTP::Post.new(url)
request["x-access-token"] = 'TOKEN'
request.body = "url=http%3A%2F%2Fgoogle.com&delay=5&pdf_margins=20px%200&pdf_header=This%20is%20page%20%3Cspan%20class%3D%22pageNumber%22%20style%3D%22color%3A%20red%3B%22%3E%3C%2Fspan%3E"

response = http.request(request)
puts response.read_bodyimport http.client

conn = http.client.HTTPSConnection("restpack.io")

payload = "url=http%3A%2F%2Fgoogle.com&delay=5&pdf_margins=20px%200&pdf_header=This%20is%20page%20%3Cspan%20class%3D%22pageNumber%22%20style%3D%22color%3A%20red%3B%22%3E%3C%2Fspan%3E"

headers = { 'x-access-token': "TOKEN" }

conn.request("POST", "/api/html2pdf/v4/convert", payload, headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))package main

import (
	"fmt"
	"strings"
	"net/http"
	"io/ioutil"
)

func main() {

	url := "https://restpack.io/api/html2pdf/v4/convert"

	payload := strings.NewReader("url=http%3A%2F%2Fgoogle.com&delay=5&pdf_margins=20px%200&pdf_header=This%20is%20page%20%3Cspan%20class%3D%22pageNumber%22%20style%3D%22color%3A%20red%3B%22%3E%3C%2Fspan%3E")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("x-access-token", "TOKEN")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := ioutil.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://restpack.io/api/html2pdf/v4/convert",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => "url=http%3A%2F%2Fgoogle.com&delay=5&pdf_margins=20px%200&pdf_header=This%20is%20page%20%3Cspan%20class%3D%22pageNumber%22%20style%3D%22color%3A%20red%3B%22%3E%3C%2Fspan%3E",
  CURLOPT_HTTPHEADER => array(
    "x-access-token: TOKEN"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}var client = new RestClient("https://restpack.io/api/html2pdf/v4/convert");
var request = new RestRequest(Method.POST);
request.AddHeader("x-access-token", "TOKEN");
request.AddParameter("undefined", "url=http%3A%2F%2Fgoogle.com&delay=5&pdf_margins=20px%200&pdf_header=This%20is%20page%20%3Cspan%20class%3D%22pageNumber%22%20style%3D%22color%3A%20red%3B%22%3E%3C%2Fspan%3E", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);HttpResponse<String> response = Unirest.post("https://restpack.io/api/html2pdf/v4/convert")
  .header("x-access-token", "TOKEN")
  .body("url=http%3A%2F%2Fgoogle.com&delay=5&pdf_margins=20px%200&pdf_header=This%20is%20page%20%3Cspan%20class%3D%22pageNumber%22%20style%3D%22color%3A%20red%3B%22%3E%3C%2Fspan%3E")
  .asString();

While the header and footer sections can be styled using CSS, they do not share the main pages css styles. The best way to style header and footer elements is to use inline styles as in <div style="background: red">...</div>.

Delay

By default, capturing engine waits for the page load and then 2 more seconds for initial javascripts to settle their rendering. You can control this duration using delay parameter (in milliseconds) from instantaneous to 10 seconds.

http --form POST https://restpack.io/api/html2pdf/v4/convert \
  x-access-token:TOKEN \
  url=http://google.com \
  delay=5000curl --request POST \
  --url https://restpack.io/api/html2pdf/v4/convert \
  --header 'x-access-token: TOKEN' \
  --data 'url=http%3A%2F%2Fgoogle.com&delay=5000'var request = require("request");

var options = { method: 'POST',
  url: 'https://restpack.io/api/html2pdf/v4/convert',
  headers: { 'x-access-token': 'TOKEN' },
  form: { url: 'http://google.com', delay: '5000' } };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
require 'uri'
require 'net/http'

url = URI("https://restpack.io/api/html2pdf/v4/convert")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

request = Net::HTTP::Post.new(url)
request["x-access-token"] = 'TOKEN'
request.body = "url=http%3A%2F%2Fgoogle.com&delay=5000"

response = http.request(request)
puts response.read_bodyimport http.client

conn = http.client.HTTPSConnection("restpack.io")

payload = "url=http%3A%2F%2Fgoogle.com&delay=5000"

headers = { 'x-access-token': "TOKEN" }

conn.request("POST", "/api/html2pdf/v4/convert", payload, headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))package main

import (
	"fmt"
	"strings"
	"net/http"
	"io/ioutil"
)

func main() {

	url := "https://restpack.io/api/html2pdf/v4/convert"

	payload := strings.NewReader("url=http%3A%2F%2Fgoogle.com&delay=5000")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("x-access-token", "TOKEN")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := ioutil.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://restpack.io/api/html2pdf/v4/convert",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => "url=http%3A%2F%2Fgoogle.com&delay=5000",
  CURLOPT_HTTPHEADER => array(
    "x-access-token: TOKEN"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}var client = new RestClient("https://restpack.io/api/html2pdf/v4/convert");
var request = new RestRequest(Method.POST);
request.AddHeader("x-access-token", "TOKEN");
request.AddParameter("undefined", "url=http%3A%2F%2Fgoogle.com&delay=5000", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);HttpResponse<String> response = Unirest.post("https://restpack.io/api/html2pdf/v4/convert")
  .header("x-access-token", "TOKEN")
  .body("url=http%3A%2F%2Fgoogle.com&delay=5000")
  .asString();

TTL

The API caches generated PDF documents up to a specified time period. If you request a PDF of a previously cached web page, result will be provided from the cache. It is possible to control the duration of cache using ttl parameter (in seconds)

In addition to setting a ttl, it is possible to use fresh=true prameter to invalidate cache and capture a new PDF.

http --form POST https://restpack.io/api/html2pdf/v4/convert \
  x-access-token:TOKEN \
  url=http://google.com \
  ttl=60000curl --request POST \
  --url https://restpack.io/api/html2pdf/v4/convert \
  --header 'x-access-token: TOKEN' \
  --data 'url=http%3A%2F%2Fgoogle.com&ttl=60000'var request = require("request");

var options = { method: 'POST',
  url: 'https://restpack.io/api/html2pdf/v4/convert',
  headers: { 'x-access-token': 'TOKEN' },
  form: { url: 'http://google.com', ttl: '60000' } };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
require 'uri'
require 'net/http'

url = URI("https://restpack.io/api/html2pdf/v4/convert")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

request = Net::HTTP::Post.new(url)
request["x-access-token"] = 'TOKEN'
request.body = "url=http%3A%2F%2Fgoogle.com&ttl=60000"

response = http.request(request)
puts response.read_bodyimport http.client

conn = http.client.HTTPSConnection("restpack.io")

payload = "url=http%3A%2F%2Fgoogle.com&ttl=60000"

headers = { 'x-access-token': "TOKEN" }

conn.request("POST", "/api/html2pdf/v4/convert", payload, headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))package main

import (
	"fmt"
	"strings"
	"net/http"
	"io/ioutil"
)

func main() {

	url := "https://restpack.io/api/html2pdf/v4/convert"

	payload := strings.NewReader("url=http%3A%2F%2Fgoogle.com&ttl=60000")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("x-access-token", "TOKEN")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := ioutil.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://restpack.io/api/html2pdf/v4/convert",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => "url=http%3A%2F%2Fgoogle.com&ttl=60000",
  CURLOPT_HTTPHEADER => array(
    "x-access-token: TOKEN"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}var client = new RestClient("https://restpack.io/api/html2pdf/v4/convert");
var request = new RestRequest(Method.POST);
request.AddHeader("x-access-token", "TOKEN");
request.AddParameter("undefined", "url=http%3A%2F%2Fgoogle.com&ttl=60000", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);HttpResponse<String> response = Unirest.post("https://restpack.io/api/html2pdf/v4/convert")
  .header("x-access-token", "TOKEN")
  .body("url=http%3A%2F%2Fgoogle.com&ttl=60000")
  .asString();

HTTP Headers

While the service uses reasonable defaults for the request headers, you can customize them as you wish.

  • user_agent parameter customizes the User-Agent header.
  • headers parameter is the freeform one. You can pass any string containing headers seperated by \n.
echo '{ "url": "http://google.com", "json": true, user_agent: "MyBot 1/2", headers: "Cookie: name=value\nX-Custom-Header: custom" }' |  \
  http POST https://restpack.io/api/html2pdf/v4/convert \
  x-access-token:TOKENcurl --request POST \
  --url https://restpack.io/api/html2pdf/v4/convert \
  --header 'x-access-token: TOKEN' \
  --data '{ "url": "http://google.com", "json": true, user_agent: "MyBot 1/2", headers: "Cookie: name=value\nX-Custom-Header: custom" }'var request = require("request");

var options = { method: 'POST',
  url: 'https://restpack.io/api/html2pdf/v4/convert',
  headers: { 'x-access-token': 'TOKEN' },
  body: '{ "url": "http://google.com", "json": true, user_agent: "MyBot 1/2", headers: "Cookie: name=value\\nX-Custom-Header: custom" }' };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
require 'uri'
require 'net/http'

url = URI("https://restpack.io/api/html2pdf/v4/convert")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

request = Net::HTTP::Post.new(url)
request["x-access-token"] = 'TOKEN'
request.body = "{ \"url\": \"http://google.com\", \"json\": true, user_agent: \"MyBot 1/2\", headers: \"Cookie: name=value\\nX-Custom-Header: custom\" }"

response = http.request(request)
puts response.read_bodyimport http.client

conn = http.client.HTTPSConnection("restpack.io")

payload = "{ \"url\": \"http://google.com\", \"json\": true, user_agent: \"MyBot 1/2\", headers: \"Cookie: name=value\\nX-Custom-Header: custom\" }"

headers = { 'x-access-token': "TOKEN" }

conn.request("POST", "/api/html2pdf/v4/convert", payload, headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))package main

import (
	"fmt"
	"strings"
	"net/http"
	"io/ioutil"
)

func main() {

	url := "https://restpack.io/api/html2pdf/v4/convert"

	payload := strings.NewReader("{ \"url\": \"http://google.com\", \"json\": true, user_agent: \"MyBot 1/2\", headers: \"Cookie: name=value\\nX-Custom-Header: custom\" }")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("x-access-token", "TOKEN")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := ioutil.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://restpack.io/api/html2pdf/v4/convert",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => "{ \"url\": \"http://google.com\", \"json\": true, user_agent: \"MyBot 1/2\", headers: \"Cookie: name=value\\nX-Custom-Header: custom\" }",
  CURLOPT_HTTPHEADER => array(
    "x-access-token: TOKEN"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}var client = new RestClient("https://restpack.io/api/html2pdf/v4/convert");
var request = new RestRequest(Method.POST);
request.AddHeader("x-access-token", "TOKEN");
request.AddParameter("undefined", "{ \"url\": \"http://google.com\", \"json\": true, user_agent: \"MyBot 1/2\", headers: \"Cookie: name=value\\nX-Custom-Header: custom\" }", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);HttpResponse<String> response = Unirest.post("https://restpack.io/api/html2pdf/v4/convert")
  .header("x-access-token", "TOKEN")
  .body("{ \"url\": \"http://google.com\", \"json\": true, user_agent: \"MyBot 1/2\", headers: \"Cookie: name=value\\nX-Custom-Header: custom\" }")
  .asString();