## Table of Contents

- [PDF](#pdf)
  - [CLI Microlink API example](#cli-microlink-api-example)
  - [cURL Microlink API example](#curl-microlink-api-example)
  - [JavaScript Microlink API example](#javascript-microlink-api-example)
  - [Python Microlink API example](#python-microlink-api-example)
  - [Ruby Microlink API example](#ruby-microlink-api-example)
  - [PHP Microlink API example](#php-microlink-api-example)
  - [Golang Microlink API example](#golang-microlink-api-example)
- [MQL installation](#mql-installation)
- [How PDF options work](#how-pdf-options-work)
- [The response](#the-response)
- [Choose a delivery mode](#choose-a-delivery-mode)
  - [CLI Microlink API example](#cli-microlink-api-example-1)
  - [cURL Microlink API example](#curl-microlink-api-example-1)
  - [JavaScript Microlink API example](#javascript-microlink-api-example-1)
  - [Python Microlink API example](#python-microlink-api-example-1)
  - [Ruby Microlink API example](#ruby-microlink-api-example-1)
  - [PHP Microlink API example](#php-microlink-api-example-1)
  - [Golang Microlink API example](#golang-microlink-api-example-1)
- [One important default: Print css](#one-important-default-print-css)
- [Using the raw URL](#using-the-raw-url)
- [Free tier and API key](#free-tier-and-api-key)
  - [CLI Microlink API example](#cli-microlink-api-example-2)
  - [cURL Microlink API example](#curl-microlink-api-example-2)
  - [JavaScript Microlink API example](#javascript-microlink-api-example-2)
  - [Python Microlink API example](#python-microlink-api-example-2)
  - [Ruby Microlink API example](#ruby-microlink-api-example-2)
  - [PHP Microlink API example](#php-microlink-api-example-2)
  - [Golang Microlink API example](#golang-microlink-api-example-2)
- [What's next](#whats-next)
- [See also](#see-also)

---

[](https://microlink.io/docs/api/getting-started/overview)

[API](https://microlink.io/docs/api/getting-started/overview)

[](https://microlink.io/docs/guides)

GUIDES

[](https://microlink.io/docs/mql/getting-started/overview)

MQL

[](https://microlink.io/docs/sdk/getting-started/overview)

SDK

[](https://microlink.io/docs/cards/getting-started/overview)

CARDS

## PDF

Generating a PDF with Microlink API requires two parameters: the target `url` and `pdf`.

Use `pdf: true` for the default behavior, or pass an object when you need PDF-specific options such as `format`, `margin`, `scale`, or `pageRanges`.

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

``` bash
microlink https://rauchg.com/2014/7-principles-of-rich-web-applications&pdf
```

### cURL Microlink API example

``` bash
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

``` javascript
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

``` python
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

``` ruby
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.body
```

### PHP Microlink API example

``` php
<?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

``` bash
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))
}
```

``` javascript
import mql from '@microlink/mql'

const { data } = await mql('https://rauchg.com/2014/7-principles-of-rich-web-applications', {

  pdf: true

})
```

Run the request and look for the generated asset under `data.pdf.url`.

Microlink renders the page in a headless browser, prints it to PDF, stores the result on the CDN, and returns the PDF asset metadata in the response.

## MQL installation

To run the JavaScript examples with MQL, install `@microlink/mql`:

``` bash
npm install @microlink/mql --save
```

It works in Node.js, Edge runtimes, and the browser. See the [MQL installation guide](https://microlink.io/docs/mql/getting-started/installation) for the environment-specific setup.

If you are using another language, you do not need to install MQL to follow this guide. You can use the terminal examples or call the API directly from any HTTP client.

## How PDF options work

As soon as you want to customize paper size, margins, or scale, switch from `true` to a `pdf` object:

``` js
{

  url: 'https://rauchg.com/2014/7-principles-of-rich-web-applications',

  pdf: {

    format: 'A4',

    margin: '1cm',

    scale: 0.8

  },

  meta: false

}
```

This guide uses the nested object form consistently because it keeps PDF-specific options grouped together. In raw query strings, the same options are expressed with dot notation such as `pdf.format=A4`.

## The response

The `pdf` field in the response contains the generated asset you will usually reuse:

``` json
{

  "status": "success",

  "data": {

    "pdf": {

      "url": "https://microlink-cdn.s3.amazonaws.com/pdf/...",

      "type": "pdf",

      "size": 1357350,

      "size_pretty": "1.36 MB"

    }

  }

}
```

Most application workflows use `data.pdf.url` directly. It is a CDN-hosted PDF URL you can store, cache, download, or embed elsewhere.

## Choose a delivery mode

You have two main ways to consume generated PDFs:

| Need                                               | Best option        | Why                                                           |
| -------------------------------------------------- | ------------------ | ------------------------------------------------------------- |
| You want JSON plus PDF metadata                    | Default response   | You get `data.pdf.url`, type, and size                        |
| You want the API URL itself to return the PDF file | `embed: 'pdf.url'` | The API URL behaves like a direct PDF download or preview URL |

If you already know you want a direct download link or embedded PDF preview, skip to [delivery and embedding](https://microlink.io/docs/guides/pdf/embedding).

By default, the API also extracts metadata from the target page. If you only need the PDF, disable it:

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' & 'meta' API parameters:

### CLI Microlink API example

``` bash
microlink https://rauchg.com/2014/7-principles-of-rich-web-applications&pdf
```

### cURL Microlink API example

``` bash
curl -G "https://api.microlink.io" \
  -d "url=https://rauchg.com/2014/7-principles-of-rich-web-applications" \
  -d "pdf=true" \
  -d "meta=false"
```

### JavaScript Microlink API example

``` javascript
import mql from '@microlink/mql'

const { data } = await mql('https://rauchg.com/2014/7-principles-of-rich-web-applications', {
  pdf: true,
  meta: false
})
```

### Python Microlink API example

``` python
import requests

url = "https://api.microlink.io/"

querystring = {
    "url": "https://rauchg.com/2014/7-principles-of-rich-web-applications",
    "pdf": "true",
    "meta": "false"
}

response = requests.get(url, params=querystring)

print(response.json())
```

### Ruby Microlink API example

``` ruby
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",
  meta: "false"
}

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.body
```

### PHP Microlink API example

``` php
<?php

$baseUrl = "https://api.microlink.io/";

$params = [
    "url" => "https://rauchg.com/2014/7-principles-of-rich-web-applications",
    "pdf" => "true",
    "meta" => "false"
];

$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

``` bash
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")
    q.Set("meta", "false")
    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))
}
```

``` javascript
import mql from '@microlink/mql'

const { data } = await mql('https://rauchg.com/2014/7-principles-of-rich-web-applications', {

  pdf: true,

  meta: false

})
```

Setting `meta: false` skips metadata extraction and is usually the biggest speedup for PDF-only requests.

If you still need a few metadata fields, `meta` also accepts an object for selective extraction. See the [meta reference](https://microlink.io/docs/api/parameters/meta).

## One important default: Print css

When Microlink generates a PDF, the default `mediaType` is `'print'`. That means print stylesheets are applied automatically.

If the page looks better in its normal on-screen layout, switch to `mediaType: 'screen'` in [page preparation](https://microlink.io/docs/guides/pdf/page-preparation).

## Using the raw URL

You can call the API directly from your browser address bar or any HTTP client:

``` bash
https://api.microlink.io?url=https://rauchg.com/2014/7-principles-of-rich-web-applications&pdf=true&meta=false
```

That returns JSON. To make the API URL return the PDF file directly instead, use `embed=pdf.url` in the [delivery and embedding](https://microlink.io/docs/guides/pdf/embedding) guide.

## Free tier and API key

The Microlink API works without an API key. You get **50 free requests per day**, which is enough to test the full PDF flow and the examples in this guide.

For production usage, you'll usually want a

PRO

plan. It unlocks features such as [configurable TTL](https://microlink.io/docs/api/parameters/ttl), [stale-while-revalidate caching](https://microlink.io/docs/api/parameters/staleTtl), [custom filenames](https://microlink.io/docs/api/parameters/filename), [custom headers](https://microlink.io/docs/api/parameters/headers), and [proxy](https://microlink.io/docs/api/parameters/proxy).

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', 'meta' & 'apiKey' API parameters:

### CLI Microlink API example

``` bash
microlink https://rauchg.com/2014/7-principles-of-rich-web-applications&pdf --api-key YOUR_API_TOKEN
```

### cURL Microlink API example

``` bash
curl -G "https://api.microlink.io" \
  -H "x-api-key: YOUR_API_TOKEN" \
  -d "url=https://rauchg.com/2014/7-principles-of-rich-web-applications" \
  -d "pdf=true" \
  -d "meta=false"
```

### JavaScript Microlink API example

``` javascript
import mql from '@microlink/mql'

const { data } = await mql('https://rauchg.com/2014/7-principles-of-rich-web-applications', {
  pdf: true,
  meta: false,
  apiKey: "YOUR_API_TOKEN"
})
```

### Python Microlink API example

``` python
import requests

url = "https://api.microlink.io/"

querystring = {
    "url": "https://rauchg.com/2014/7-principles-of-rich-web-applications",
    "pdf": "true",
    "meta": "false"
}

headers = {
    "x-api-key": "YOUR_API_TOKEN"
}

response = requests.get(url, params=querystring, headers=headers)

print(response.json())
```

### Ruby Microlink API example

``` ruby
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",
  meta: "false"
}

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)
request['x-api-key'] = "YOUR_API_TOKEN"
response = http.request(request)

puts response.body
```

### PHP Microlink API example

``` php
<?php

$baseUrl = "https://api.microlink.io/";

$params = [
    "url" => "https://rauchg.com/2014/7-principles-of-rich-web-applications",
    "pdf" => "true",
    "meta" => "false"
];

$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",
    CURLOPT_HTTPHEADER => [
        "x-api-key: YOUR_API_TOKEN"
    ]
]);

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

curl_close($curl);

if ($err) {
    echo "cURL Error #: " . $err;
} else {
    echo $response;
}
```

### Golang Microlink API example

``` bash
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")
    q.Set("meta", "false")
    u.RawQuery = q.Encode()

    req, err := http.NewRequest("GET", u.String(), nil)
    if err != nil {
        panic(err)
    }

    req.Header.Set("x-api-key", "YOUR_API_TOKEN")

    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))
}
```

``` javascript
import mql from '@microlink/mql'

const { data } = await mql('https://rauchg.com/2014/7-principles-of-rich-web-applications', {

  pdf: true,

  meta: false,

  apiKey: "YOUR_API_TOKEN"

})
```

You can enter your API key in any interactive example by clicking the key icon in the terminal toolbar.

Throughout this guide, features that require a

PRO

plan are marked inline.

See the [authentication](https://microlink.io/docs/api/basics/authentication) and [rate limit](https://microlink.io/docs/api/basics/rate-limit) docs for details.

## What's next

Pick the next step based on the result you want:

- **[Page size and layout](https://microlink.io/docs/guides/pdf/page-size-and-layout)** — control paper format, custom dimensions, margins, orientation, scale, and page ranges.
- **[Page preparation](https://microlink.io/docs/guides/pdf/page-preparation)** — choose print or screen CSS, wait for content, click UI elements, and inject CSS before printing.
- **[Delivery and embedding](https://microlink.io/docs/guides/pdf/embedding)** — choose between JSON + CDN URLs and direct PDF responses for downloads and previews.
- **[Caching and performance](https://microlink.io/docs/guides/pdf/caching-and-performance)** — tune freshness, cache behavior, and PDF generation speed.
- **[Private pages](https://microlink.io/docs/guides/pdf/private-pages)** — generate PDFs from logged-in or header-dependent pages safely.
- **[Troubleshooting](https://microlink.io/docs/guides/pdf/troubleshooting)** — fix missing content, wrong layout, timeouts, blocked sites, and plan-related errors.

## See also

- [Screenshot](https://microlink.io/docs/guides/screenshot) — if you need an image of the page instead of a printable document.
- [Metadata](https://microlink.io/docs/guides/metadata) — if you need link preview data alongside or instead of a PDF.