Skip to content

Microlink PDF:
turn any URL into a PDF

Any URL to a hosted PDF with one query parameter

January 8, 2020

Today we're introducing Microlink PDF: add the pdf query parameter to any Microlink API request and the response includes a PDF of the target URL, hosted and ready to link.
TL;DR
  • Add the pdf query parameter to any Microlink API request and the response includes a PDF of the target URL, hosted and ready to link.
  • The file is hosted on Microlink CDN. Combine it with ttl and the PDF refreshes in the background.
  • Three new query parameters, scale, margin, and mediaType, change how the headless browser prints pages that were not built to print.
  • With embed=pdf.url, the request URL is the PDF itself: no server code, just HTML.
It follows Microlink screenshot, which we launched six months ago as part of offering browser capabilities you can use directly from the API.
See live demo at microlink.io/pdf.

One parameter adds a pdf field to the response

Microlink PDF is built on the same principle as the rest of the Microlink API: getting something back from any URL should be trivial. Enabling pdf adds a pdf data field to the response payload, with the file size in bytes, a human-readable size_pretty, the type, and the url of the generated file:
{
  "pdf": {
    "size_pretty": "62.5 kB",
    "size": 62450,
    "type": "pdf",
    "url": "https://microlink.nyc3.digitaloceanspaces.com/wEjulsXuSQxZhZcm5BKmUoiyDcc_"
  }
}
The file is hosted on Microlink CDN, so the url field is a link you can hand straight to a user. Combine it with ttl and the PDF refreshes in the background, so the link keeps pointing at an up-to-date representation of the target URL.

Parameters for pages that were not built to print

When the target URL is not prepared to be exported as a PDF, three new query parameters change how the headless browser prints it:
  • scale: resizes the rendered page to fit the PDF.
  • margin: sets the space around the content on each page.
  • mediaType: chooses which CSS media type the page is rendered with.

Serve the PDF straight from HTML

With embed mode, the API responds with the file itself instead of JSON. Setting embed=pdf.url makes the request URL the PDF, so it works anywhere HTML accepts a link. This is the first chapter of Basecamp's Shape Up, rendered in an <iframe>:
<iframe frameborder='0'	target='_parent' src='https://api.microlink.io/?url=https://basecamp.com/shapeup/0.3-chapter-01&pdf&embed=pdf.url'
></iframe>
The same URL also works as the href of a download button:
<a href="https://api.microlink.io/?url=https://basecamp.com/shapeup/0.3-chapter-01&pdf&embed=pdf.url">
	<button>Download File</button>
</a>
Either way, the PDF is created on the fly when the request arrives. That makes it a backendless solution: no server code, just HTML.

Try it

Add &pdf to any API request, or open the live demo at microlink.io/pdf to generate a PDF from a URL of your own. The pdf parameter reference documents every option.

Join the community

All of these improvements or features are community driven: We listen to your feedback and act accordingly.
Whether you are building a product, an indie developer, or just interested in web technologies, come chat with us.