Skip to content
PDF API · Use case

Create a PDF download link or an embedded preview from any URL

Create a PDF download link from any URL with one query parameter. With embed=pdf.url the PDF API URL returns the document directly, so an anchor, an iframe or a Markdown link is the whole integration. It fits “Download as PDF” buttons, report previews in admin panels and printable versions of docs pages.

The problem

A PDF download link should not need a queue and a bucket

Generating a PDF is the easy half. The usual pipeline then uploads the file somewhere, stores the URL, signs it, and expires it later. For a download button or an in-app preview, that is a lot of moving parts for a file the user opens once.

Skipping the pipeline has its own costs. Rendering inside the request handler ties up your web server for seconds per document, and client-side libraries that rebuild the page as a PDF in the browser rarely match the fonts and layout of the real page.

The embed parameter changes the API response: instead of JSON with a pdf.url field, the response body is the PDF with the right content type. Put that URL in an anchor for downloads, in an iframe for previews, and add filename to control the name. The response is cached, so the second click does not render again.

How it works

How to create a PDF download link from a URL

Keep the JSON response for backend jobs. Use the direct response for links and previews. Both come from the same request options, and the delivery and embedding guide compares the two modes side by side.

1 · Download link
<a
  href="https://api.microlink.io/?url=https%3A%2F%2Fexample.com%2Freport&pdf=true&meta=false&embed=pdf.url"
  download="report.pdf"
>
  Download PDF
</a>

The browser fetches the API URL and receives the PDF, not JSON; the download attribute names the file locally. The free endpoint needs no API key, so this works in public HTML as is.

2 · Embedded preview
<iframe
  src="https://api.microlink.io/?url=https%3A%2F%2Fexample.com%2Freport&pdf=true&meta=false&embed=pdf.url"
  width="100%"
  height="800"
  title="Report preview"
></iframe>

The same URL renders inline with the browser’s built-in PDF viewer, which suits admin panels, invoice previews and document review flows.

3 · JSON for a backend job
import createClient from 'microlink.io'

const microlink = createClient({
  apiKey: process.env.MICROLINK_API_KEY
})

const { url, size_pretty: size } = await microlink.pdf(
  'https://example.com/report',
  { filename: 'report-2026-09.pdf', ttl: '7d' }
)

Backend workflows keep the JSON response: url is the CDN-hosted document, next to its type and size. filename and ttl are Pro options, so this call runs with your API key on the server.

Parameters used
  • embed Returns the pdf.url field as the response body, with the headers of the original file, instead of JSON.
  • filename Readable name for the generated document. Pro plans.
  • filter Keeps the JSON response but only the pdf field when the rest is noise.
  • ttl How long the response stays cached, from 1 minute to 31 days. Default 24 hours. Pro plans.
  • pdf.format Every PDF layout option still applies to the embedded response. Default A4.

Never put an API key in a public download URL. On the free endpoint none is needed; on Pro, route the request through your own domain with @microlink/proxy or @microlink/edge-proxy, as the authentication docs describe.

Why it works

Why a direct PDF response beats a storage pipeline

For documents that are viewed on demand, the API is the renderer, the cache and the delivery. Your code holds a URL.

01 · No plumbing
The URL is the integration.
An anchor tag, an iframe or a Markdown link is enough. There is no worker to run, no bucket to configure and no expiry job to write, because the response is generated and cached on request.

This is the same mechanism that serves screenshots as Open Graph images, so one pattern covers both outputs.

02 · Cached delivery
The first request renders; the rest are cache hits.
Responses are cached for 24 hours by default and up to 31 days with ttl, so a report shared with a team renders once and downloads instantly afterwards. Cache hits do not count against your quota.

Use force when the underlying page changed and you need a fresh document before the cache expires. The configurable cache feature explains ttl and staleTtl together.

03 · Still customizable
Layout, waits and styles apply before delivery.
Paper format, margins, page ranges, waits for charts and injected CSS all work with embed. The delivery mode is the last step of the request, not a separate product.

When not to: documents you must keep for years belong in your own storage, so download the file from the JSON response and archive it. Private pages need forwarded headers, which must stay server-side; see PDF invoices from authenticated pages.

FAQ

Build the API URL with the encoded page URL, pdf=true, meta=false and embed=pdf.url, and use it as the href of an anchor with the download attribute. The response is the PDF file, not JSON, so the browser saves it directly. You can test the output first with the website to PDF converter.

Can I embed a PDF preview of a URL in an iframe?

Yes. Put the same embed URL in the src of an iframe or an embed element and the browser renders it with its built-in PDF viewer. Embedded assets are served with a strict Content-Security-Policy and nosniff headers, so the preview cannot run scripts under the API host.

How do I set the filename of the PDF download?

In HTML, the download attribute on the anchor sets the local filename and works on every plan. The filename parameter names the generated asset itself and requires a Pro plan; without one the request fails with the EFILENAME error code.

Is the PDF regenerated on every download?

No. The response is cached for 24 hours by default, so repeated downloads of the same URL are served from the cache and do not count against your quota. Adjust ttl on Pro plans, or pass force to regenerate on demand; the x-cache-status header tells you whether a request was a HIT, a MISS or a BYPASS, as the cache docs explain.

Is it safe to put a PDF API URL in public HTML?

Yes on the free endpoint, which needs no credentials: the URL only contains the public page address and the PDF options. Never expose an API key, a cookie or an authorization header in client-side markup. For Pro features, keep the request on your server or put @microlink/proxy or @microlink/edge-proxy in front of it.
Related use cases

Solve the next problem with the same API

PDF invoices from authenticated pages

Print the invoice page your app already renders: forward the session, hide the chrome, name the file.

Paper size, margins and orientation

Print any URL on A4, Letter or custom paper, with per-side margins, landscape, scale and page ranges.

PDFs in bulk

Render thousands of documents from URLs in one job: parallel requests, server-side retries and per-document caching.

Archive web articles as PDF

Keep readable, searchable PDFs of articles and docs, printed with their print styles and trimmed to the pages you need.

Clean PDFs without ads or banners

Get a document, not a browser tab: ads and consent popups blocked by default, sticky chrome removed with one CSS rule.

Dynamic Open Graph images

Point og:image at an API URL and every share shows a current, cached screenshot of the page.

Ready to serve PDFs from a URL?

Download links and previews without a storage pipeline. Start on the free tier and wire your first download button today.