ScreenshotNeo

BlogHow-to

How to use Microlink to turn a web page into a PDF

Generate a PDF from a web page with Microlink’s JavaScript SDK or HTTP API, choose print settings, and troubleshoot common rendering problems.

By the ScreenshotNeo team4 October 20267 min read

Use Microlink’s PDF method to print a URL to PDF. In JavaScript, call microlink.pdf(url, options); the result includes a hosted PDF asset URL. You can also call the API over HTTP and either read the JSON asset information or request the PDF URL as the response body.

Install the SDK in a JavaScript project, then call its PDF method with a publicly reachable page URL. This example uses A4 paper and prints the returned asset URL.

import createClient from 'microlink.io'

const microlink = createClient()
const { url } = await microlink.pdf('https://example.com', { format: 'A4' })
console.log(url)

The returned url points to the generated PDF asset. Use it as a download link or pass it to the next step in your application. See the Microlink SDK method documentation for the method and its options.

Microlink’s API accepts GET requests. Supply the page URL and enable PDF generation. Build the query string with a URL encoder so nested characters in the target URL, such as its own query parameters, are encoded correctly.

cURL

curl -G 'https://api.microlink.io' \
  --data-urlencode 'url=https://example.com' \
  --data-urlencode 'pdf=true'

The standard API response is JSON containing output data, including the PDF asset information. To ask for the generated PDF URL as the direct response, use the documented embed selector:

curl -G 'https://api.microlink.io' \
  --data-urlencode 'url=https://example.com' \
  --data-urlencode 'pdf=true' \
  --data-urlencode 'embed=pdf.url' \
  -o page.pdf

Microlink documents embed: 'pdf.url' for selecting the generated PDF URL for document downloads. Check the response content type and resulting file when integrating this behavior. Refer to the PDF parameter documentation, embed parameter documentation, and the API overview.

Python

import requests

response = requests.get(
    'https://api.microlink.io',
    params={
        'url': 'https://example.com',
        'pdf': 'true',
    },
    timeout=90,
)
response.raise_for_status()
data = response.json()
print(data)

With the normal JSON response, inspect the returned data for the PDF asset URL. If you need the PDF URL itself as the response, add 'embed': 'pdf.url' to params, then save the response body as a PDF file after confirming the response is successful.

Node.js

const params = new URLSearchParams({
  url: 'https://example.com',
  pdf: 'true',
})

const response = await fetch(`https://api.microlink.io?${params}`)
if (!response.ok) {
  throw new Error(`Microlink request failed: ${response.status}`)
}
const data = await response.json()
console.log(data)

For a direct PDF URL response, add embed: 'pdf.url' to the URLSearchParams. The API request is a GET, so encode the full target URL as a query parameter rather than concatenating it into the request URL yourself.

Choose PDF page and print settings

Start with default settings, then change only the options that address a visible layout issue. Microlink documents the following controls through its SDK reference:

Option What it controls Documented detail
format Standard paper size A4 is the default. Supported sizes include Letter, Legal, Tabloid, Ledger, and A0 through A6.
landscape Page orientation Set to true for landscape orientation.
margin Space around printed content Accepts a unit-labelled value or an object with individual sides. The documented default is 0.35cm.
scale Rendered page zoom Documented range is 0.1 to 2; documented default is 0.6.
pageRanges Pages included in the PDF Use ranges such as 1-5, 8, 11-13.
width and height Custom page dimensions Use these in place of a standard paper size when needed.
printBackground Background graphics and colors Set to true to include printed backgrounds.

For example, the SDK supports a combination of Letter paper, landscape orientation, asymmetric margins, and a page range. Use the option names and object shape in the SDK reference for the current syntax:

const { url } = await microlink.pdf('https://example.com', {
  format: 'Letter',
  landscape: true,
  margin: {
    top: '1cm',
    right: '1.5cm',
    bottom: '1cm',
    left: '1.5cm',
  },
  pageRanges: '1-3',
})

console.log(url)

PDF options affect the browser’s print output, but they cannot guarantee that every site will have a clean layout. Review the result for clipping, unexpected page breaks, blank pages, missing backgrounds, and content that appears only after interaction.

Review the generated PDF

  1. Begin with a public URL and the fewest options possible.
  2. Read the API response and retrieve the generated asset, or use embed: 'pdf.url' if your consumer needs the PDF URL as the response.
  3. Open the output and check page breaks, margins, orientation, backgrounds, and whether any important content is missing.
  4. Adjust format, scale, margins, or page ranges to address specific issues, then generate and inspect a new document.

Client-rendered pages may need a headless browser. Microlink says its API detects when a page needs one, including client-rendered pages. A page’s own print stylesheet can change its layout, so a screen view and PDF may not match.

Or skip the browser setup

If you need a screenshot rather than a paginated PDF, ScreenshotNeo is a website screenshot API and MCP server. One GET request returns a PNG, JPEG, WebP, or PDF. For a PDF capture, set the documented PDF output options in the API request; see the ScreenshotNeo API documentation.

curl -G "https://api.screenshotneo.com/v1/shot" \
  -d access_key=YOUR_API_KEY \
  --data-urlencode url=https://stripe.com \
  -o shot.webp

ScreenshotNeo accepts cookie and consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing, and response headers report the page verdict and billing status. Its MCP server gives AI agents tools to take screenshots, get page information, and capture PDFs. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000 screenshots. Every feature is on every plan.

Sign up free for 1,000 screenshots a month, with no card required.

Troubleshooting

Symptom Likely cause What to try
The request returns an error instead of a PDF asset The target URL is inaccessible, malformed, or rejected by the API. Check that the URL is public and correctly encoded. Inspect the response status and error body before treating the response as a PDF.
The output is JSON when you expected a file The request used the normal API response. Read the JSON for the PDF asset URL, or request embed=pdf.url as documented. Check the response before saving its body with a .pdf extension.
A page is blank or missing content The page may rely on client rendering, delayed assets, or interaction before content appears. Confirm the page works without authentication and inspect whether the content is rendered only after a user action. Microlink documents headless-browser detection for client-rendered pages, but restricted or anti-bot-protected pages may still fail.
Background colors or images are missing Print backgrounds are not enabled, or the site’s print stylesheet suppresses them. Set printBackground: true and inspect the page’s print-specific output.
Text or columns are clipped The selected paper size, orientation, margins, or scale do not fit the page layout. Try landscape, a larger format, smaller margins, or a different scale. Check custom dimensions if using a nonstandard page.
Some pages are absent A page range may exclude them, or the site’s print layout paginates content differently than expected. Remove the page range first, inspect the full document, then apply a corrected range.
An anti-bot error appears The target site is protected against automated access. Microlink’s API overview says free-plan requests to sites behind anti-bot protection can return EPROXYNEEDED; its paid-plan flow may retry through a residential proxy. Access is not guaranteed. Use only URLs you are authorized to access.
Python or Node code fails while parsing the response The response may be an error or a direct embedded PDF rather than JSON. Check the HTTP status and response content type. Parse JSON only for the normal JSON response; handle the embedded PDF response as document data.

Performance, reliability, and cost

PDF generation time depends on the target page and its resources. Microlink’s published API overview lists P95 figures for screenshots and metadata, but those are not PDF performance benchmarks; do not use them to predict PDF latency.

The same overview currently says the free endpoint requires no API key and allows 25 requests per day, and that paid plans have a 99.9% SLA. Quotas and commercial terms can change, so check Microlink’s current API overview before choosing a plan. The documentation reviewed does not provide an independent benchmark for PDF speed or fidelity.

For production workflows, handle non-success responses explicitly, avoid assuming every target is accessible, and inspect the generated PDF when layout matters. Save or distribute the returned asset URL according to your application’s needs.

Frequently asked questions

The standard documented SDK workflow returns an object containing the hosted PDF asset URL. The API can select pdf.url with its embed parameter when you need that PDF URL as the response.

Can I create a PDF from a page that needs JavaScript?

Microlink says its API detects when a headless browser is needed, including for client-rendered pages. A site’s access controls or anti-bot protection can still prevent a successful capture.

Can I make the PDF look exactly like the screen?

Not necessarily. Print stylesheets, page dimensions, and browser print behavior affect the output. Inspect the PDF and tune the documented print options for the target page.

Can I save only selected pages?

Yes. The SDK reference documents page ranges such as 1-5, 8, 11-13.