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
HTTP

How to Send a Snappy wkhtmltopdf PDF to the Browser (Inline or Download)

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

To display a PDF generated by Snappy in a browser, return the generated bytes with Content-Type: application/pdf. Use Content-Disposition: inline (or omit the disposition) when you want the browser to attempt an embedded viewer; use attachment with a filename when you want a download prompt. Snappy is a PHP wrapper around the wkhtmltopdf executable, so the same HTTP rules apply whether output is generated in memory or written to disk.

The response headers decide what the browser does

A PDF is not sent to a browser by a special Snappy method. Your controller or PHP endpoint creates the document, then sends an HTTP response containing PDF bytes and the correct headers.

Goal Header Typical result
Ask the browser to display the PDF Content-Type: application/pdf
Content-Disposition: inline
A built-in PDF viewer may open in the current tab or a new tab, depending on client settings.
Force a download Content-Type: application/pdf
Content-Disposition: attachment; filename="file.pdf"
The browser offers or starts a file download.

Inline disposition is a request, not a guarantee. A browser, mobile app, embedded web view, or user preference can still download the file or refuse to render PDF content.

Plain PHP: return Snappy output inline

Install a compatible wkhtmltopdf 0.12.x executable and point Snappy at its actual path. The path must exist in the deployment environment, not merely on your development machine.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
PDF Converter Ultimate - Convert PDF files into Word, Excel, PowerPoint and others - PDF converter software with OCR recognition compatible with Windows 11 / 10 / 8.1 / 8 / 7
  • Convert your PDF files into Word, Excel & Co. the easy way
  • Convert scanned documents thanks to our new 2022 OCR technology
  • Adjustable conversion settings
  • No subscription! Lifetime license!
  • Compatible with Windows 11, 10, 8.1, 7 - Internet connection required
<?php
require __DIR__ . '/vendor/autoload.php';

use KnpSnappyPdf;

$snappy = new Pdf('/usr/local/bin/wkhtmltopdf');

header('Content-Type: application/pdf');
header('Content-Disposition: inline; filename="page.pdf"');
echo $snappy->getOutput('https://example.com');

The essential operations are ordered deliberately: create the renderer, send headers before any body output, then echo the binary result. Remove accidental whitespace, debug output, and PHP warnings before the headers; otherwise the response can be corrupted or the headers can become immutable.

Force a download instead

<?php
$snappy = new Pdf('/usr/local/bin/wkhtmltopdf');
$url = 'https://example.com';

header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="file.pdf"');
echo $snappy->getOutput($url);

Use a fixed, validated filename. Never copy an arbitrary request value directly into a response header: newline characters can create header-injection vulnerabilities.

Symfony: choose a response for bytes or a file

Symfony’s Response represents content, status, and headers. It is appropriate when Snappy has produced PDF bytes in memory. Symfony’s file helpers and BinaryFileResponse are more suitable when the PDF has been saved to disk and you want the framework to stream it.

In-memory output with Response

<?php
namespace AppController;

use KnpSnappyPdf;
use SymfonyComponentHttpFoundationResponse;
use SymfonyComponentHttpFoundationResponseHeaderBag;
use SymfonyComponentRoutingAnnotationRoute;

final class PdfController
{
    #[Route('/report.pdf')]
    public function report(Pdf $snappy): Response
    {
        $pdf = $snappy->getOutput('https://example.com');

        $response = new Response($pdf, Response::HTTP_OK, [
            'Content-Type' => 'application/pdf',
        ]);
        $response->headers->set(
            'Content-Disposition',
            $response->headers->makeDisposition(
                ResponseHeaderBag::DISPOSITION_INLINE,
                'report.pdf'
            )
        );

        return $response;
    }
}

ResponseHeaderBag::DISPOSITION_INLINE makes the intent explicit. For a download, change it to DISPOSITION_ATTACHMENT. Symfony’s disposition helpers also handle filename quoting more safely than hand-concatenating untrusted text.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Doxillion Free Document Converter – Converts DOCX, DOC, PDF, WPS and Many More Files Quickly [Download]
  • Convert over 50 document file formats.
  • Preview your files from Doxillion before converting them.
  • Use batch conversion to convert thousands of files at once.
  • Enjoy an easy-to-use, intuitive interface with a Drag and Drop file option.
  • Burn your converted or original files directly to disc.

A saved PDF with a file response

use SymfonyComponentHttpFoundationBinaryFileResponse;
use SymfonyComponentHttpFoundationResponseHeaderBag;

$path = '/var/app/generated/report.pdf';
$response = new BinaryFileResponse($path);
$response->headers->set('Content-Type', 'application/pdf');
$response->setContentDisposition(
    ResponseHeaderBag::DISPOSITION_INLINE,
    'report.pdf'
);
return $response;

Use a file response only after confirming that the file exists and is readable. Delete temporary files after the response lifecycle when they are no longer needed, and keep generated files outside directories that serve arbitrary uploads.

Headers and caching details worth getting right

  • Content type: always send application/pdf; do not label a PDF as HTML or a generic binary stream.
  • Disposition: inline is for viewing, attachment is for downloading. Include a safe ASCII fallback filename.
  • Length: frameworks can calculate it for a string or file. Avoid manually setting a stale Content-Length.
  • Caching: private or user-specific reports commonly need Cache-Control: private, no-store. Public, immutable reports can use a deliberate cache policy.
  • Errors: do not send a successful PDF content type before rendering finishes. If wkhtmltopdf fails, return an appropriate HTTP error instead of an HTML error page mislabeled as PDF.

Snappy and wkhtmltopdf deployment requirements

Snappy delegates rendering to an installed wkhtmltopdf executable. Verify the binary path, executable permissions, required shared libraries, fonts, and network access in the same container, VM, or host that runs PHP. A path that works on a laptop can fail under a web-server user or a minimal container.

  • Run the binary as the service account during deployment checks.
  • Confirm outbound DNS and HTTPS access when rendering remote URLs.
  • Install the fonts needed by your documents; missing fonts can change line wrapping and page count.
  • Set a process timeout and log stderr from wkhtmltopdf without returning it to the browser.
  • Keep renderer concurrency bounded. Each conversion consumes CPU and memory, so an unbounded queue can exhaust the host.

In a March 15, 2023 maintainer discussion, Snappy maintainer Antoine Lelaisant wrote that “wkhtmltopdf has been abandoned on January 2023.” That is dated project context, not proof that every packaged binary is unusable or that a particular replacement backend is available today. Pin and test the version you deploy, and evaluate a migration separately if long-term maintenance is a requirement.

Security: treat rendered HTML as untrusted input

KnpLabs warns that --enable-local-file-access can be dangerous when wkhtmltopdf processes untrusted HTML or JavaScript. Do not enable broad local access merely to make an image or stylesheet appear.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
PDF Extra 2024| Complete PDF Reader and Editor | Create, Edit, Convert, Combine, Comment, Fill & Sign PDFs | Lifetime License | 1 Windows PC | 1 User [PC Online code]
  • EDIT text, images & designs in PDF documents. ORGANIZE PDFs. Convert PDFs to Word, Excel & ePub.
  • READ and Comment PDFs – Intuitive reading modes & document commenting and mark up.
  • CREATE, COMBINE, SCAN and COMPRESS PDFs
  • FILL forms & Digitally Sign PDFs. PROTECT and Encrypt PDFs
  • LIFETIME License for 1 Windows PC or Laptop. 5GB MobiDrive Cloud Storage Included.
  • Prefer trusted, controlled URLs and sanitized HTML.
  • If local assets are unavoidable, expose only a tightly controlled directory and validate every input.
  • Run wkhtmltopdf with a low-privilege account in a sandbox or isolated container.
  • Restrict outbound network access where the document does not need arbitrary requests.
  • Limit document size, render time, redirects, and concurrency to reduce denial-of-service risk.

Remember that JavaScript in the source page can make network requests or delay completion. Set an explicit JavaScript policy and wait strategy appropriate to your templates.

Troubleshooting common failures

The browser downloads instead of displaying

Inspect the actual response headers. Replace attachment with inline, remove a framework download helper, and verify that no proxy rewrites the disposition. The client may still choose to download because inline rendering is not guaranteed.

The PDF is blank or truncated

Check wkhtmltopdf stderr and the HTTP status returned by remote assets. Confirm that the renderer can resolve DNS, trust the TLS certificate, and reach CSS, images, and fonts. Do not print notices or debug text before the PDF bytes.

“Command not found” or permission errors

Use an absolute executable path, verify execute permission, and run the same command as the PHP service user. In containers, install the binary and its libraries in the image rather than relying on a host path.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
MobiPDF Lifetime - Professional PDF Editor for Windows | Edit, Sign & Convert PDFs | Best Adobe Acrobat Pro Alternative | Lifetime License
  • Edit PDFs with Ease. Modify text, images, and layouts directly within your PDF documents.
  • Convert & Organize. Export PDFs to Word, Excel, or ePub, and organize files with ease.
  • Read & Annotate. Enjoy intuitive reading modes and powerful tools to comment, highlight, and mark up PDFs.
  • Create & Manage PDFs. Create new PDFs, combine multiple files, scan documents, and compress for easy sharing.
  • Fill & Sign Forms. Complete forms and digitally sign documents with secure e-signature tools.

Images or stylesheets are missing

Use absolute HTTPS URLs or a controlled asset base URL. If assets are local, review the security implications before considering restricted local-file access; sanitize input and sandbox the process.

Non-ASCII filenames are broken

Use Symfony’s header utilities, which generate a standards-compliant disposition with a safe fallback. Test accented characters and non-Latin names in the browsers and download clients you support.

Requests time out

Identify whether the delay is page JavaScript, a slow asset, network idle behavior, or renderer startup. Set bounded application and process timeouts, simplify the page, and move expensive conversions to a queue when users do not need a synchronous response.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If your real requirement is a clean screenshot or PDF of a URL rather than a PHP-rendered document, ScreenshotNeo provides a single HTTP request. It accepts consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and the response identifies the result with X-Page-Verdict and X-Billed headers. Its MCP server also lets Claude, Cursor, or another MCP client call take_screenshot, get_page_info, and capture_pdf.

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

See the ScreenshotNeo API documentation for all options, including PDF paper size, margins, orientation, page ranges, waits, selectors, custom headers and cookies, blocking rules, caching, signed links, asynchronous jobs, and bulk capture.

Best Value
PDF Pro 3 - PDF editor to create, edit, convert and merge PDFs - 100% Compatible with Adobe Acrobat - for Windows 11, 10, 8.1, 7
  • ALL-IN-ONE SOLUTION – read, edit, convert, merge and protect your PDF files
  • MAXIMUM FUNCIONALITY – create interactive forms, compare PDFs, bates numbering, find and replace text or colors, convert documents, OCR engine, comment, highlight, fill out and print forms, document protection and others
  • EASY TO INSTALL AND USE – well-structured user-interface, in-program instructions, free tech support whenever you need it
  • GREAT VALUE FOR MONEY - why spend a fortune if you can have maximum functionality at a reasonable price - this also fits the requirements of companies very well
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

There is a free allowance of 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots. Create a free ScreenshotNeo account to try it.

FAQ

Can I set both inline and attachment?

No. They express opposite handling preferences. Send one disposition value, or omit the header when you have no preference.

Should I base64-encode the PDF?

No. Return the raw binary bytes in the HTTP response. Base64 adds size and requires a separate decoding step.

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

Is wkhtmltopdf suitable for every modern web page?

No renderer handles every page identically. Test your templates, JavaScript, fonts, and external assets with the exact binary and operating environment you deploy.

Frequently Asked Questions

Can a PDF be opened in a new browser tab?

Return an inline PDF response and link to the endpoint with the desired target behavior, such as a new tab. The browser ultimately controls whether it opens a viewer or downloads the file.

Does Symfony automatically stream Snappy output?

A normal Response contains the generated bytes in memory. Use BinaryFileResponse when you have a file on disk and want file-oriented handling.

Quick Recap

Bestseller No. 1
PDF Converter Ultimate - Convert PDF files into Word, Excel, PowerPoint and others - PDF converter software with OCR recognition compatible with Windows 11 / 10 / 8.1 / 8 / 7
PDF Converter Ultimate - Convert PDF files into Word, Excel, PowerPoint and others - PDF converter software with OCR recognition compatible with Windows 11 / 10 / 8.1 / 8 / 7
Convert your PDF files into Word, Excel & Co. the easy way; Convert scanned documents thanks to our new 2022 OCR technology
$29.99
Bestseller No. 2
Doxillion Free Document Converter – Converts DOCX, DOC, PDF, WPS and Many More Files Quickly [Download]
Doxillion Free Document Converter – Converts DOCX, DOC, PDF, WPS and Many More Files Quickly [Download]
Convert over 50 document file formats.; Preview your files from Doxillion before converting them.
Bestseller No. 3
PDF Extra 2024| Complete PDF Reader and Editor | Create, Edit, Convert, Combine, Comment, Fill & Sign PDFs | Lifetime License | 1 Windows PC | 1 User [PC Online code]
PDF Extra 2024| Complete PDF Reader and Editor | Create, Edit, Convert, Combine, Comment, Fill & Sign PDFs | Lifetime License | 1 Windows PC | 1 User [PC Online code]
READ and Comment PDFs – Intuitive reading modes & document commenting and mark up.; CREATE, COMBINE, SCAN and COMPRESS PDFs
$99.99
Bestseller No. 4
MobiPDF Lifetime - Professional PDF Editor for Windows | Edit, Sign & Convert PDFs | Best Adobe Acrobat Pro Alternative | Lifetime License
MobiPDF Lifetime - Professional PDF Editor for Windows | Edit, Sign & Convert PDFs | Best Adobe Acrobat Pro Alternative | Lifetime License
Edit PDFs with Ease. Modify text, images, and layouts directly within your PDF documents.; Convert & Organize. Export PDFs to Word, Excel, or ePub, and organize files with ease.
$99.99
Bestseller No. 5
PDF Pro 3 - PDF editor to create, edit, convert and merge PDFs - 100% Compatible with Adobe Acrobat - for Windows 11, 10, 8.1, 7
PDF Pro 3 - PDF editor to create, edit, convert and merge PDFs - 100% Compatible with Adobe Acrobat - for Windows 11, 10, 8.1, 7
ALL-IN-ONE SOLUTION – read, edit, convert, merge and protect your PDF files
$29.99

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.

Read next

Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

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.