Type:
Default: false
<boolean> | <object>
Default: false
It generates a PDF over the target url.
The following examples show how to use the Microlink API with CLI, cURL, JavaScript, Python, Ruby, PHP & Golang, targeting 'https://rauchg.com/2014/7-principles-of-rich-web-applications' URL with 'pdf' API parameter:
CLI Microlink API example
microlink https://rauchg.com/2014/7-principles-of-rich-web-applications&pdfcURL Microlink API example
curl -G "https://api.microlink.io" \
-d "url=https://rauchg.com/2014/7-principles-of-rich-web-applications" \
-d "pdf=true"JavaScript Microlink API example
import mql from '@microlink/mql'
const { data } = await mql('https://rauchg.com/2014/7-principles-of-rich-web-applications', {
pdf: true
})Python Microlink API example
import requests
url = "https://api.microlink.io/"
querystring = {
"url": "https://rauchg.com/2014/7-principles-of-rich-web-applications",
"pdf": "true"
}
response = requests.get(url, params=querystring)
print(response.json())Ruby Microlink API example
require 'uri'
require 'net/http'
base_url = "https://api.microlink.io/"
params = {
url: "https://rauchg.com/2014/7-principles-of-rich-web-applications",
pdf: "true"
}
uri = URI(base_url)
uri.query = URI.encode_www_form(params)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri)
response = http.request(request)
puts response.bodyPHP Microlink API example
<?php
$baseUrl = "https://api.microlink.io/";
$params = [
"url" => "https://rauchg.com/2014/7-principles-of-rich-web-applications",
"pdf" => "true"
];
$query = http_build_query($params);
$url = $baseUrl . '?' . $query;
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => $url,
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;
}Golang Microlink API example
package main
import (
"fmt"
"net/http"
"net/url"
"io"
)
func main() {
baseURL := "https://api.microlink.io"
u, err := url.Parse(baseURL)
if err != nil {
panic(err)
}
q := u.Query()
q.Set("url", "https://rauchg.com/2014/7-principles-of-rich-web-applications")
q.Set("pdf", "true")
u.RawQuery = q.Encode()
req, err := http.NewRequest("GET", u.String(), nil)
if err != nil {
panic(err)
}
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
panic(err)
}
fmt.Println(string(body))
}import mql from '@microlink/mql'
const { data } = await mql('https://rauchg.com/2014/7-principles-of-rich-web-applications', {
pdf: true
})When it's enabled, a new
pdf data field will be part of the response payload.{
"data": {
"title": "7 Principles of Rich Web Applications",
"description": "November 4, 2014",
"lang": "en",
"author": null,
"publisher": "rauchg.com",
"image": null,
"url": "https://rauchg.com/2014/7-principles-of-rich-web-applications",
"date": "2019-11-27T18:34:47.000Z",
"logo": {
"url": "https://logo.clearbit.com/rauchg.com",
"type": "png",
"size": 17675,
"height": 128,
"width": 128,
"size_pretty": "17.7 kB"
},
"pdf": {
"size_pretty": "1.36 MB",
"size": 1357350,
"type": "pdf",
"url": "https://microlink.nyc3.digitaloceanspaces.com/vIQctxsDTujq0b_f8AnldH7YMYs_"
}
},
"status": "success"
}In MQL and SDKs, use
pdf: true for the default behavior or pass an object when you need PDF-specific options:{
pdf: {
format: 'A4',
margin: '1cm',
scale: 0.8
}
}In raw query strings, the same options are expressed with dot notation such as
pdf.format=A4.The following examples show how to use the Microlink API with CLI, cURL, JavaScript, Python, Ruby, PHP & Golang, targeting 'https://rauchg.com/2014/7-principles-of-rich-web-applications' URL with 'pdf' API parameter:
CLI Microlink API example
microlink https://rauchg.com/2014/7-principles-of-rich-web-applications&pdf.scale=1&pdf.margin=0.4cmcURL Microlink API example
curl -G "https://api.microlink.io" \
-d "url=https://rauchg.com/2014/7-principles-of-rich-web-applications" \
-d "pdf.scale=1" \
-d "pdf.margin=0.4cm"JavaScript Microlink API example
import mql from '@microlink/mql'
const { data } = await mql('https://rauchg.com/2014/7-principles-of-rich-web-applications', {
pdf: {
scale: 1,
margin: "0.4cm"
}
})Python Microlink API example
import requests
url = "https://api.microlink.io/"
querystring = {
"url": "https://rauchg.com/2014/7-principles-of-rich-web-applications",
"pdf.scale": "1",
"pdf.margin": "0.4cm"
}
response = requests.get(url, params=querystring)
print(response.json())Ruby Microlink API example
require 'uri'
require 'net/http'
base_url = "https://api.microlink.io/"
params = {
url: "https://rauchg.com/2014/7-principles-of-rich-web-applications",
pdf.scale: "1",
pdf.margin: "0.4cm"
}
uri = URI(base_url)
uri.query = URI.encode_www_form(params)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri)
response = http.request(request)
puts response.bodyPHP Microlink API example
<?php
$baseUrl = "https://api.microlink.io/";
$params = [
"url" => "https://rauchg.com/2014/7-principles-of-rich-web-applications",
"pdf.scale" => "1",
"pdf.margin" => "0.4cm"
];
$query = http_build_query($params);
$url = $baseUrl . '?' . $query;
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => $url,
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;
}Golang Microlink API example
package main
import (
"fmt"
"net/http"
"net/url"
"io"
)
func main() {
baseURL := "https://api.microlink.io"
u, err := url.Parse(baseURL)
if err != nil {
panic(err)
}
q := u.Query()
q.Set("url", "https://rauchg.com/2014/7-principles-of-rich-web-applications")
q.Set("pdf.scale", "1")
q.Set("pdf.margin", "0.4cm")
u.RawQuery = q.Encode()
req, err := http.NewRequest("GET", u.String(), nil)
if err != nil {
panic(err)
}
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
panic(err)
}
fmt.Println(string(body))
}import mql from '@microlink/mql'
const { data } = await mql('https://rauchg.com/2014/7-principles-of-rich-web-applications', {
pdf: {
scale: 1,
margin: "0.4cm"
}
})The
data.pdf.url field is a CDN-hosted PDF URL you can reuse directly. If you want the API URL itself to return the PDF file, combine PDF generation with embed and return pdf.url as the response body.<a
href="https://api.microlink.io/?url=https://rauchg.com/2014/7-principles-of-rich-web-applications&pdf&embed=pdf.url&scale=1&margin=0.4cm"
download="How-to-download-file.pdf"
>
<button>Download File</button>
</a>When you generate a PDF, the default mediaType is
'print'.