URL to PDF vs Screenshot to PDF: Choosing the Right Approach
SnapAPI supports two distinct approaches to generating PDF documents from web content. The url-to-pdf approach calls the PDF endpoint with a target URL and returns a single PDF document rendered from that page, preserving the page's print stylesheet if one is defined, or rendering the screen stylesheet at print dimensions if no print stylesheet exists. This is the fastest approach for single-page documents and works well for invoices, receipts, and reports that live at a permanent URL. The screenshot-to-pdf approach first captures a full-page screenshot of the URL as a high-resolution PNG image, then embeds that image in a PDF document using a PDF generation library. This approach produces PDF files that look exactly like the web page as rendered in a browser, including all visual styling, gradients, and shadows that might not survive PDF rendering, and is better suited for creating visual archives, sending screenshot evidence as PDF attachments, or generating PDF portfolios of web pages for client deliverables.
Generating PDFs from Multiple Screenshots
For multi-page PDF documents, capture a screenshot of each source page and combine them into a single PDF using Python's reportlab or img2pdf library. This pattern is useful for creating client reports that combine screenshots of multiple dashboard pages, generating evidence packages that document a sequence of web pages visited during a research task, or producing design review documents that show multiple page designs side by side. Capture each screenshot in the correct order, save each to a temporary file, then pass the list of image files to img2pdf to combine them into a single PDF with one image per page at the original image dimensions. For high-quality output, capture screenshots at double the normal resolution by setting the device_scale_factor parameter to 2, then rescale the screenshots to standard print dimensions when embedding them in the PDF to produce a sharp, print-ready document.
import requests, img2pdf, tempfile, os
API_KEY = "your_api_key"
def url_to_screenshot(url, scale=2):
r = requests.get(
"https://api.snapapi.pics/screenshot",
params={"url": url, "format": "png", "full_page": "true",
"width": "1440", "device_scale_factor": str(scale)},
headers={"Authorization": f"Bearer {API_KEY}"}
)
r.raise_for_status()
return r.content
def screenshots_to_pdf(urls, output_path):
tmp_files = []
try:
for url in urls:
img = url_to_screenshot(url)
tf = tempfile.NamedTemporaryFile(suffix=".png", delete=False)
tf.write(img)
tf.close()
tmp_files.append(tf.name)
with open(output_path, "wb") as f:
f.write(img2pdf.convert(tmp_files))
print(f"PDF saved: {output_path} ({os.path.getsize(output_path):,} bytes)")
finally:
for f in tmp_files:
os.unlink(f)
urls = [
"https://example.com/page1",
"https://example.com/page2",
"https://example.com/page3",
]
screenshots_to_pdf(urls, "output.pdf")
PDF Output Quality and Size Optimization
Screenshot-based PDFs tend to be larger than HTML-rendered PDFs because they contain rasterized image data rather than vector text and shapes. A full-page screenshot of a typical web page at 2x device scale and 1440px viewport width produces an image of roughly three to eight megabytes, which translates to a similar-sized PDF page. For documents that need to be emailed or downloaded quickly, optimize the screenshots before embedding them in the PDF by converting them to JPEG format at 85 percent quality, which reduces file size by sixty to eighty percent with minimal perceptible quality loss for most web page content. Use the format=jpeg parameter in the SnapAPI screenshot call and specify quality=85 to get compressed output directly from the API without a post-processing step. For documents where text readability matters more than file size, such as legal evidence packages, keep the PNG format for lossless quality and use PDF compression options in your PDF generation library to reduce the file size without quality degradation.
Use Cases for Screenshot-Based PDF Generation
Design agencies generating client deliverables use screenshot-to-PDF workflows to produce design review documents that show each page design as it appears in the browser, combined into a single PDF for the client to annotate and approve. Digital marketing teams generate competitive intelligence reports by capturing screenshots of competitor landing pages, ad pages, and pricing pages, combining them into a weekly PDF report distributed to the sales and product teams. Legal teams documenting web evidence capture screenshots of web pages as part of a case file, combining related pages into a single PDF exhibit with page numbers and timestamps for court submission. E-commerce teams generate product catalog PDFs from their own product pages by capturing screenshot thumbnails of each product page and arranging them in a grid layout using reportlab, producing a printable catalog automatically from the live website without a separate print design workflow. Compliance teams generate visual audit reports by capturing screenshots of regulated pages at each audit date, combining them into a chronological PDF that documents the state of the pages at each snapshot point.
Get Started with SnapAPI PDF Generation
Register at snapapi.pics/register for a free API key with two hundred requests per month. The PDF endpoint is available on all plans and converts any URL to a PDF in a single API call. For screenshot-to-PDF workflows, the screenshot endpoint with full_page=true provides the high-quality source images, and open-source Python libraries like img2pdf, reportlab, and fpdf2 handle the PDF assembly. The SnapAPI documentation at snapapi.pics/docs includes examples for both the native PDF endpoint and the screenshot-plus-PDF-assembly pattern for multi-page document generation.