This is an outdated version of the HTML To PDF API. Please refer to Latest Version Documentation for the greatest functionality.
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.
Here are some code samples you can use. Don't forget to obtain a token here.
http --form POST https://restpack.io/api/html2pdf/v5/convert \
x-access-token:TOKEN \
url=http://google.com \
json=true
curl --request POST \
--url https://restpack.io/api/html2pdf/v5/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/v5/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/v5/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_body
import 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/v5/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/v5/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/v5/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/v5/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/v5/convert")
.header("x-access-token", "TOKEN")
.body("url=http%3A%2F%2Fgoogle.com&json=true")
.asString();
You can find detailed usage information below.
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.
access_token
querystring parameter. As in https://restpack.io/api/html2pdf/v5/convert?access_token={TOKEN}
http GET 'https://restpack.io/api/html2pdf/v5/convert?access_token=YOUR_ACCESS_TOKEN&url=URL_TO_CAPTURE'
curl --request GET \
--url 'https://restpack.io/api/html2pdf/v5/convert?access_token=YOUR_ACCESS_TOKEN&url=URL_TO_CAPTURE'
var request = require("request");
var options = { method: 'GET',
url: 'https://restpack.io/api/html2pdf/v5/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/v5/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_body
import http.client
conn = http.client.HTTPSConnection("restpack.io")
conn.request("GET", "/api/html2pdf/v5/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/v5/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/v5/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/v5/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/v5/convert?access_token=YOUR_ACCESS_TOKEN&url=URL_TO_CAPTURE")
.asString();
X-Access-Token
header.http GET 'https://restpack.io/api/html2pdf/v5/convert?url=URL_TO_CAPTURE' \
x-access-token:TOKEN
curl --request GET \
--url 'https://restpack.io/api/html2pdf/v5/convert?url=URL_TO_CAPTURE' \
--header 'x-access-token: TOKEN'
var request = require("request");
var options = { method: 'GET',
url: 'https://restpack.io/api/html2pdf/v5/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/v5/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_body
import http.client
conn = http.client.HTTPSConnection("restpack.io")
headers = { 'x-access-token': "TOKEN" }
conn.request("GET", "/api/html2pdf/v5/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/v5/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/v5/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/v5/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/v5/convert?url=URL_TO_CAPTURE")
.header("x-access-token", "TOKEN")
.asString();
Access token errors are represented in 4xx
class HTTP errors.
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 json: true
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
}
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.
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 |
privacyboolean | Ensure that the captured document does not get cached / stored for further use. You can not use json mode with this setting as it would not be possible to provide a CDN URL. Default: false |
cache_ttlnumber | Time in seconds for the resulting image to be cached for further requests. Max: 1 week |
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 |
pdf_heightstring | Custom pdf page height. Check |
pdf_marginscss sizes | CSS style margin sizes. |
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_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: 20000 |
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 |
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.
http --form POST https://restpack.io/api/html2pdf/v5/convert \
x-access-token:TOKEN \
url=http://google.com \
json=true
curl --request POST \
--url https://restpack.io/api/html2pdf/v5/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/v5/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/v5/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_body
import 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/v5/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/v5/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/v5/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/v5/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/v5/convert")
.header("x-access-token", "TOKEN")
.body("url=http%3A%2F%2Fgoogle.com&json=true")
.asString();
{
"image": "http://cdn.restpack.io/...",
"cached": true
}
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 numbertotalPages
: Total number of pages in the documenturl
: Captured page URLtitle
: Document titledate
: Date of capture in UTFAlso 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/v5/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/v5/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/v5/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/v5/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_body
import 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/v5/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/v5/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/v5/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/v5/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/v5/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>
.
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/v5/convert \
x-access-token:TOKEN \
url=http://google.com \
delay=5000
curl --request POST \
--url https://restpack.io/api/html2pdf/v5/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/v5/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/v5/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_body
import 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/v5/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/v5/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/v5/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/v5/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/v5/convert")
.header("x-access-token", "TOKEN")
.body("url=http%3A%2F%2Fgoogle.com&delay=5000")
.asString();
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/v5/convert \
x-access-token:TOKEN \
url=http://google.com \
ttl=60000
curl --request POST \
--url https://restpack.io/api/html2pdf/v5/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/v5/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/v5/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_body
import 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/v5/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/v5/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/v5/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/v5/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/v5/convert")
.header("x-access-token", "TOKEN")
.body("url=http%3A%2F%2Fgoogle.com&ttl=60000")
.asString();
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/v5/convert \
x-access-token:TOKEN
curl --request POST \
--url https://restpack.io/api/html2pdf/v5/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/v5/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/v5/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_body
import 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/v5/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/v5/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/v5/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/v5/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/v5/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();