Skip to content
PDF API · Use case

Convert a web page to a clean PDF, without ads or cookie banners

Convert a web page to PDF without ads, consent dialogs or a sticky header stamped on every page break. Research exports, client reports, legal copies and reading lists all need the content, not the browser tab around it. The PDF API blocks the third-party noise before the page renders and lets you hide the rest with one CSS rule.

The problem

Browser-saved PDFs carry the ads, banners and sticky headers along

Web pages are built to be scrolled, not paginated. Print one as it is and the ad slots leave holes in the text, the cookie banner covers the first paragraph, the fixed navigation repeats at the top of every sheet, and a wide layout gets squeezed into an unreadable column.

The usual fixes are manual or brittle. Reader mode and print dialogs work for one page at a time, not for a pipeline. HTML-to-PDF converters that skip the browser skip the site’s CSS too, so the result looks nothing like the article. A self-hosted headless Chrome prints faithfully, including every popup it was served.

Microlink renders the page in a real browser with adblock enabled by default, so ad, tracker and cookie consent requests are blocked before they run. PDFs use the print media type, so the site’s print stylesheet applies, and styles removes whatever is left. Switch mediaType to screen when the print stylesheet strips too much.

How it works

How to convert a web page to PDF without ads

Start with the defaults, because they already block most of the noise. Add a CSS rule for site-specific chrome, then pick print or screen styles depending on what the site ships. The PDF page preparation guide walks through each control.

1 · Print with the defaults
import createClient from 'microlink.io'

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

const { url } = await microlink.pdf('https://example.com/article')

No options needed: adblock stops ads, trackers and third-party consent services, and the print media type applies the site’s own print stylesheet. url points to the hosted A4 document.

2 · Hide sticky chrome and narrow the layout
import createClient from 'microlink.io'

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

const { url } = await microlink.pdf('https://example.com/article', {
  styles: [
    'header, .navbar, .cookie-banner, .newsletter { display: none !important }',
    'main { max-width: 900px !important; margin: 0 auto !important }'
  ]
})

Injected CSS removes the navigation that would repeat on each page and gives long text a readable measure. styles accepts inline rules or the absolute URL of a stylesheet.

3 · The same request as a URL
curl 'https://api.microlink.io/?url=https%3A%2F%2Fexample.com%2Farticle&pdf=true&meta=false&mediaType=screen&styles=header%2C+.cookie-banner+%7B+display%3A+none+%21important+%7D'

mediaType=screen keeps the on-screen design when the print stylesheet removes images or changes fonts. Try the result first with the website to PDF converter before wiring the URL into your code.

Parameters used
  • adblock Blocks third-party ad, tracker and cookie consent requests. On by default on every plan.
  • styles Inline CSS or an absolute stylesheet URL injected before printing.
  • mediaType print (the default for PDFs) or screen.
  • click Clicks one selector or several in order, to dismiss a first-party banner or expand a section before printing.
  • javascript Set to false for static pages to skip client-side widgets and reduce rendering work. Default true.

Think in page state: block the noise, wait for the content, hide the chrome, then print. The same options drive screenshots without cookie banners or ads, so a clean capture recipe carries over. Reach for the function parameter only when CSS and clicks are not enough.

Why it works

Why a real browser with adblock makes a cleaner PDF

Rendering the real page and subtracting the noise is more faithful than converting raw HTML, and blocking a request is more reliable than hiding its result. The adblock feature runs inside the rendering browser on every plan.

01 · Blocked at the network
Ads and consent scripts never execute.
The adblock engine stops third-party ad, tracker and consent requests before the page renders. There is nothing to hide afterwards, the page loads faster, and the layout is the one the content was designed for.

Turn it off with adblock: false only when the PDF must show the page exactly as a first-time visitor sees it.

02 · Print styles, then your styles
Two layers of CSS shape the document.
The site’s print stylesheet applies first because PDFs render with the print media type. Your injected styles apply on top, which is where sticky headers, sidebars, newsletter boxes and first-party popups disappear.

A narrower max-width on the main column is the single most effective rule for long articles: fewer awkward page breaks, easier reading. It is the base of the article archiving recipe.

03 · Screen when needed
mediaType: screen preserves the web design.
Some sites ship print stylesheets that strip images or change fonts. Switching to the screen media type prints the page as it looks in the browser, and the styles parameter still lets you trim it.

When not to: if you need the consent flow or the ads in the document, for an audit or a compliance record, disable adblock and skip the CSS. If you only need the text, clean Markdown is lighter than a PDF.

FAQ

The banner is probably first-party, built into the site’s own code rather than injected by a consent service, so it is not a third-party request adblock can stop. Hide it with styles, for example .cookie-banner { display: none !important }, or dismiss it with click before printing.

Should I use print or screen styles when converting a page to PDF?

Start with print, the default for PDFs: it applies the site’s print stylesheet and usually gives a document-oriented layout. Switch mediaType to screen when that stylesheet removes images or changes the design in ways you do not want. Injected styles work on top of either.

How do I remove the sticky header that repeats on every PDF page?

Fixed and sticky headers are the usual cause. Hide them with styles, for example header { display: none !important }. Narrowing the main column with a max-width in the same rule set also produces cleaner page breaks.

Do I need a paid plan to convert a web page to PDF without ads?

No. adblock, styles, mediaType and click are request options available on every plan, including the free endpoint with 25 requests per day and no API key. A Pro plan adds custom headers, proxy, filename and configurable caching when you move to production.

Does disabling JavaScript produce a cleaner PDF?

For static or server-rendered pages, often yes. javascript: false stops client-side widgets, popups and late-loading embeds from running and reduces rendering work. Keep it enabled for pages that build their content in the browser, or the PDF will be empty.
Related use cases

Solve the next problem with the same API

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.

Paper size, margins and orientation

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

PDFs of JavaScript-rendered pages

Print dashboards and single-page apps after they render: wait for the chart, open tabs and sections, then print.

PDF download links and previews

Turn the API URL into the PDF itself for one-click download links and iframe previews, with no storage pipeline.

Screenshots without cookie banners or ads

Ads, trackers and consent popups are blocked before the page renders, and one option dismisses first-party banners.

Clean Markdown, no boilerplate

Convert only the article body: one selector keeps navigation, ads and widgets out of the Markdown.

Ready for clean PDFs?

Ads and banners gone by default, chrome removed with one rule. Start on the free tier and print your first clean document today.