October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk5 min

How to Convert a Website URL to PDF in India Using Python

Use Playwright for browser-rendered website PDFs in Python, or WeasyPrint for direct URL conversion. Includes installation, runnable code, troubleshooting, and security guidance.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For a website that needs real browser rendering, use Python with Playwright and Chromium: open the URL, wait for the page, then call page.pdf(). Playwright uses print CSS by default; use page.emulate_media(media="screen") first if you want screen styling instead. For simpler pages that fit its renderer, WeasyPrint can convert a URL directly. The India qualifier does not change these documented steps; the cited tool documentation does not establish India-specific legal rules for saving arbitrary web pages.

Choose a Python approach

Approach Choose it when Trade-off
Playwright with Chromium The page depends on browser rendering or you need browser PDF controls. Install the Python package and browser binaries. PDFs use print CSS unless you select screen media.
WeasyPrint A direct HTML URL-to-PDF conversion fits the page. Its resource access needs care, especially when processing untrusted HTML or CSS.
Requests You need to fetch HTTP content as one part of a larger pipeline. Requests handles HTTP, but is not by itself a browser renderer or URL-to-PDF converter.

For browser-style pages, start with Playwright. For either route, inspect the output: a PDF is a rendering, not a guarantee that every live interaction, delayed asset, or page behavior will be captured.

Convert a URL with Playwright and Chromium

Install Playwright and its browser

Install the package and download the browser binaries from a terminal:

python -m pip install playwright
playwright install chromium

Playwright’s Python guide documents installation with the playwright package and playwright install; Playwright supports Chromium, Firefox, and WebKit. This example installs Chromium specifically. See the Playwright Python library guide.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Save a page as a PDF

Save this as url_to_pdf.py, replacing the example address with the page you need:

import asyncio
from pathlib import Path
from playwright.async_api import async_playwright

async def main():
    url = "https://example.com"
    output = Path("page.pdf")

    async with async_playwright() as p:
        browser = await p.chromium.launch()
        page = await browser.new_page()
        response = await page.goto(url, wait_until="networkidle", timeout=60000)

        if response and not response.ok:
            raise RuntimeError(f"Page returned HTTP {response.status}: {url}")

        await page.pdf(path=str(output), format="A4", print_background=True)
        await browser.close()

    print(f"Saved {output.resolve()}")

asyncio.run(main())

Run it with python url_to_pdf.py. The output path is relative to the directory from which you run the script. The status check surfaces an HTTP error response; it does not establish that all assets loaded or that the rendered page is complete.

Print CSS versus screen CSS

page.pdf() generates a PDF using print CSS by default. That means print-specific styles can hide navigation or reflow content. If you want the screen layout, select screen media before generating the PDF:

await page.emulate_media(media="screen")
await page.pdf(path="page.pdf", format="A4", print_background=True)

Playwright documents this behavior in its Python Page API. Choose the media mode based on the layout you actually want to preserve.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Convert a URL directly with WeasyPrint

When the page is suitable for WeasyPrint’s renderer, its direct URL-to-PDF API is concise:

from weasyprint import HTML

HTML("https://example.com").write_pdf("page.pdf")

Install WeasyPrint using the instructions for your operating system in its First Steps documentation; system dependencies may be required. This method does not run a full interactive browser, so choose Playwright if the page depends on browser behavior.

Protect server-side conversions

WeasyPrint warns that untrusted HTML or CSS and unrestricted access to local or remote resources can create security risks. If your application accepts URLs or markup from users, constrain resource access and avoid letting submitted content read local files or reach internal network resources. Treat URL conversion as an input-security boundary, not just a formatting task.

Where Requests fits—and where it does not

Python Requests can fetch HTTP content, but its documentation describes HTTP requests rather than browser rendering or PDF generation. Use it when fetching is one stage in a pipeline, not as a complete converter for pages whose output depends on rendered browser content. Its documentation covers features such as timeouts and content decoding: Requests documentation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot incomplete or failed PDFs

  • Playwright says the browser executable is missing: run playwright install chromium in the same environment where the package is installed.
  • Navigation times out: check that the URL is reachable from the machine running Python. A page that continuously makes network requests may not reach networkidle; try wait_until="load" and add a targeted wait for the content you need rather than assuming the page is ready.
  • The PDF layout differs from the browser: print CSS is the default for page.pdf(). Use page.emulate_media(media="screen") when screen styling is the goal, then inspect the result.
  • Images or other assets are missing: the page may load them late, block automated access, or rely on browser behavior. Check the page in the same environment and verify the PDF rather than treating a completed call as proof that every asset was included.
  • WeasyPrint cannot fetch a resource or output looks different: check the URL and resource access allowed to the process, and confirm the page is suitable for its renderer. Do not relax security restrictions broadly for untrusted input.
  • The PDF is not where expected: use an absolute output path or check the process working directory; the sample Playwright script writes page.pdf there.

Or skip the browser setup

If you prefer a hosted screenshot/PDF API, ScreenshotNeo accepts a URL in one request and can return a PDF. Cookie banners are accepted and removed before capture, along with known newsletter popups and chat widgets; those cleanup steps can be switched off. Bot checks, blank pages and failed loads are never billed, and the response identifies the page verdict and billing status. Its MCP server lets AI agents use screenshot tools. The free plan includes 1,000 shots a month with no card; paid plans start at $5 for 3,000.

For API setup and options, see the ScreenshotNeo documentation. A Python request looks like this:

import requests

r = requests.get(
    "https://api.screenshotneo.com/v1/shot",
    params={"access_key": "YOUR_API_KEY", "url": "https://example.com"},
    timeout=90,
)
r.raise_for_status()
open("shot.pdf", "wb").write(r.content)

Use an API key from your account; check the requested output settings in the documentation if you need to specify PDF behavior. Sign up for ScreenshotNeo to get 1,000 free screenshots a month with no card.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.