ScreenshotNeo

BlogHTML to image & PDF

How to Convert Pasted HTML Code to PDF Online

Paste HTML, render it, and save a reliable PDF online. Compare browser print, hosted converters, code libraries, and ScreenshotNeo.

By the ScreenshotNeo team1 October 20268 min read

Yes, you can convert pasted HTML to a PDF online without installing desktop software. The quickest free method is to put the HTML in a rendered page, open that page in Chrome, choose Print, select Save as PDF, and check the result. For repeatable automation, send the raw HTML to a hosted HTML-to-PDF API or use a browser-based or Python library.

The important detail is that a PDF converter must render the HTML first. Pasting markup into a plain-text form will produce code-looking text, not the designed page. CSS, fonts, images, JavaScript timing, print styles, page geometry, and cross-origin access determine the final PDF.

1. Fastest method: paste HTML into a page and print to PDF

  1. Create a temporary .html file, local preview, or online HTML editor.
  2. Paste your complete document, including <html>, <head>, CSS, and body content.
  3. Open the rendered page in Chrome.
  4. Press Ctrl+P on Windows/Linux or Command+P on macOS.
  5. Set the destination to Save as PDF.
  6. Choose paper size, orientation, margins, scale, and whether background graphics should print.
  7. Save the PDF, then inspect every page for clipped content, missing assets, and bad page breaks.

Google’s desktop instructions cover opening the page, image, or file, selecting the print command, choosing a destination, and printing: Chrome desktop print help.

Minimal HTML you can paste

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Invoice</title>
  <style>
    @page { size: A4; margin: 18mm; }
    body { font: 14px/1.5 Arial, sans-serif; color: #222; }
    h1 { margin-top: 0; }
    .total { font-size: 1.25rem; font-weight: 700; }
    @media print {
      .screen-only { display: none; }
      .avoid-break { break-inside: avoid; }
    }
  </style>
</head>
<body>
  <h1>Invoice</h1>
  <p>Prepared from pasted HTML.</p>
  <div class="avoid-break">
    <p class="total">Total: $125.00</p>
  </div>
</body>
</html>

Android Chrome

Open the rendered page, choose More > Share > Print, select Save as PDF, choose a location, and tap Print. See Chrome’s Android print instructions.

2. Can an online converter accept pasted HTML directly?

Some hosted services accept the markup itself instead of requiring a public URL. For example, HTML2PDF.app documents an authenticated POST request with an html field containing raw HTML or a publicly reachable URL, returning the successful PDF as binary data. Its documented request shape is:

{
  "html": "<article><h1>Invoice</h1><p>Hello</p></article>"
}

HTML2PDF.co.uk documents URL-encoded raw HTML together with options for page size, orientation, margins, print or screen CSS media, and waiting for lazy-loaded content. Read the provider’s current documentation before choosing an endpoint:

Check the exact authentication method, request limits, file-size and page limits, retention policy, and pricing. Keep API keys on a server or trusted job. HTML2PDF.app specifically warns against exposing keys in browser JavaScript, public repositories, or client-side templates.

3. Make CSS and assets survive PDF conversion

Use print CSS deliberately

@media print {
  nav, .cookie-banner, .chat-widget, .screen-only { display: none !important; }
  a { color: inherit; text-decoration: none; }
  table, pre, .card { break-inside: avoid; }
  h1, h2, h3 { break-after: avoid; }
}

@page {
  size: Letter;
  margin: 0.7in;
}

Converters that support print media should use these rules. If the output looks like the screen version, select print CSS or add explicit @media print rules.

Fonts and images

  • Use absolute HTTPS URLs for remote images and stylesheets when the converter runs outside your machine.
  • Confirm that fonts and images do not require an authenticated browser session unless the service supports custom headers or cookies.
  • For sensitive or offline documents, embed small images as data URLs and use locally available fonts where practical.
  • Enable background graphics when color blocks, backgrounds, or charts depend on them.

Dynamic and lazy content

JavaScript-rendered charts, image lazy-loading, and client-side data requests may finish after the initial page load. Use a converter’s documented delay, selector wait, or network-idle option. If no such option exists, render the page only after the content is present and then submit the resulting HTML or URL.

4. Page size, margins, orientation, and page breaks

Setting What it changes Typical check
Paper size Printable page dimensions A4 versus Letter changes wrapping
Orientation Portrait or landscape layout Use landscape for wide tables
Margins Space around the content Reduce only after checking printer-safe output
Scale Content size on each page Lower scale can prevent clipping but makes text smaller
Backgrounds Color fills and background images Enable when the design depends on them
Page ranges Which pages are exported Useful for extracting a section

Long tables, code blocks, and cards need representative testing. Add break-inside: avoid to blocks that must stay together, but expect a large block to move to the next page when it cannot fit.

5. Automation options

Browser JavaScript with html2pdf.js

The html2pdf.js project documents a browser-only pipeline that accepts an HTML string or element and runs .from(...).to(...).save(). A basic pattern is:

const html = `<article>
  <h1>Report</h1>
  <p>Generated in the browser.</p>
</article>`;

const host = document.createElement('div');
host.innerHTML = html;
document.body.appendChild(host);

html2pdf().from(host).save('report.pdf');

This keeps the conversion client-side, but it inherits browser limits: remote assets may fail, large documents consume memory, and JavaScript-generated content must be ready before conversion.

Python with xhtml2pdf

xhtml2pdf’s quickstart documents pisa.CreatePDF(html_source, dest=...) for converting an HTML string to a file or in-memory buffer.

from xhtml2pdf import pisa

html = """
<html>
  <body>
    <h1>Report</h1>
    <p>Generated from a Python string.</p>
  </body>
</html>
"""

with open("report.pdf", "wb") as output:
    result = pisa.CreatePDF(html, dest=output)

if result.err:
    raise RuntimeError("PDF conversion failed")

Choose this path when conversion belongs inside your application and your HTML/CSS fits the library’s supported rendering model. A hosted Chromium converter is usually a better fit when you need modern browser behavior, JavaScript, or complex web fonts.

Hosted conversion from a backend

Use a hosted API when you need repeatable jobs, server-side authentication, callbacks, or a central rendering environment. Send the HTML from your backend, stream the binary response to storage, and record conversion errors with the document identifier. Never put the provider key in client-side code.

6. Or skip the browser setup

ScreenshotNeo captures a rendered page through one API request and can return PNG, JPEG, WebP, or PDF. Put your pasted HTML in a reachable preview page, then pass that page URL to the API. See the ScreenshotNeo API documentation for the current request options.

cURL

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://your-host.example/rendered-html -o document.webp

Python

import requests

r = requests.get(
    "https://api.screenshotneo.com/v1/shot",
    params={"access_key": "YOUR_API_KEY", "url": "https://your-host.example/rendered-html"},
    timeout=90,
)
r.raise_for_status()
open("document.webp", "wb").write(r.content)

Node.js

const q = new URLSearchParams({
  access_key: 'YOUR_API_KEY',
  url: 'https://your-host.example/rendered-html'
});
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`ScreenshotNeo request failed: ${res.status}`);
const buffer = Buffer.from(await res.arrayBuffer());

ScreenshotNeo removes cookie or consent banners, newsletter popups, and chat widgets before capture. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing, and the response identifies the page verdict and billing status with X-Page-Verdict and X-Billed headers. It also offers full-page capture, lazy-image loading, custom CSS and JavaScript, waits, request blocking, custom headers and cookies, PDF controls, signed links, asynchronous jobs, bulk capture, a usage API, an OpenAPI specification, and an MCP server with take_screenshot, get_page_info, and capture_pdf for Claude, Cursor, and other MCP clients.

The Free plan includes 1,000 screenshots per month with no card. Paid plans start at $5 for 3,000 shots; yearly billing gives two months free. Create a free ScreenshotNeo account.

7. Troubleshooting common PDF problems

Symptom Likely cause Fix
PDF contains HTML tags Raw markup was treated as text Render the HTML in a page or use an API’s documented raw-HTML field
CSS is missing Stylesheet URL is local, blocked, or unavailable Use reachable HTTPS assets or inline critical CSS
Images are blank Lazy loading, authentication, mixed content, or cross-origin failure Wait for images, use accessible URLs, and inspect browser/network errors
Fonts changed Web font did not load before capture Wait for the font, provide a fallback, or use an available font
Charts are empty JavaScript had not finished rendering Wait for a selector or delay until the chart exists
Content is clipped Paper size, scale, or fixed-width CSS is too large Set page geometry, reduce fixed widths, or use landscape orientation
Cards split across pages No print break rule Add break-inside: avoid and test large cards
Navigation appears in the PDF Screen-only elements were not hidden Hide them in @media print
API key exposed Conversion called directly from browser code Move the request to a trusted server or job worker
Converter times out Page is slow, blocked, or waiting indefinitely Remove unnecessary resources, set a bounded wait, and log the failing URL

8. Reliability, performance, cost, and privacy

Reliability

  • Use deterministic HTML and wait for a known selector rather than an arbitrary long sleep.
  • Record the source version, conversion settings, timestamp, and resulting file checksum.
  • Retry transient network failures with a limit and backoff; do not retry malformed HTML forever.
  • Check the PDF programmatically for a nonzero file size, then inspect representative pages visually.

Performance

  • Reduce third-party scripts, advertisements, trackers, and oversized images.
  • Reuse cached output when the source and rendering settings have not changed.
  • For bulk jobs, queue work and cap concurrency so the source site and converter remain responsive.
  • Use page ranges or element capture when a full document is unnecessary.

Cost and privacy

Browser printing is free but manual. Libraries avoid per-request hosted charges but add maintenance and rendering limitations. Hosted APIs trade that maintenance for usage pricing and operational controls. Before sending confidential HTML, review retention, regional processing, access controls, and whether external assets contain private data. Do not embed passwords, tokens, or secrets in pasted source.

9. A practical checklist

  • Does the HTML render correctly before conversion?
  • Are print styles included?
  • Are fonts, images, and stylesheets reachable?
  • Has dynamic content finished loading?
  • Are paper size, orientation, margins, and backgrounds correct?
  • Do tables, code blocks, and cards break cleanly?
  • Are API credentials kept on the server?
  • Have you checked the provider’s limits, retention, and pricing?
  • Was the resulting PDF opened and inspected?

10. FAQ

Can I convert HTML to PDF without installing anything?

Yes. Render the HTML in Chrome and use Print > Save as PDF, or use a hosted converter that accepts raw HTML or a URL.

Should I paste HTML into a PDF website or upload a file?

Use a raw-HTML field when you need to submit markup directly. Use a rendered URL when the page depends on JavaScript, external assets, authentication, or a full browser environment.

Why does the browser preview look right but the PDF does not?

PDF output uses print geometry and may finish before fonts, images, or scripts load. Check print CSS, asset access, wait settings, page size, and margins.

What is the safest place for an API key?

Keep it in a server-side environment variable or trusted worker. Do not place it in browser JavaScript, public repositories, or client-side templates.

When should I use ScreenshotNeo?

Use it when you want a repeatable rendered-page capture with cleanup of consent banners and popups, capture controls, PDF support, and an API or MCP workflow. Start with the free plan at ScreenshotNeo.