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.
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 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.
<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.
<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.
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.
- 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 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.
This is the same mechanism that serves screenshots as Open Graph images, so one pattern covers both outputs.
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.
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
How do I make a link that downloads a web page as a PDF?
Can I embed a PDF preview of a URL in an iframe?
How do I set the filename of the PDF download?
Is the PDF regenerated on every download?
Is it safe to put a PDF API URL in public HTML?
Solve the next problem with the same API
PDF invoices from authenticated pages
Paper size, margins and orientation
PDFs in bulk
Archive web articles as PDF
Clean PDFs without ads or banners
Dynamic Open Graph images
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.