This page contains various examples of using the HTML to PDF API in PHP. The examples are complete and fully functional. Read more about how to convert HTML to PDF in PHP.
<?php require "pdfcrowd.php"; try { // Create an API client instance. $client = new \Pdfcrowd\HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // Specify the mapping of HTML content width to the PDF page width. // To fine-tune the layout, you can specify an exact viewport width, such as '960px'. $client->setContentViewportWidth("balanced"); // Run the conversion and save the result to a file. $client->convertUrlToFile("http://www.example.com", "example.pdf"); } catch(\Pdfcrowd\Error $why) { error_log("Pdfcrowd Error: {$why}\n"); throw $why; } ?>
<?php require "pdfcrowd.php"; try { // Create an API client instance. $client = new \Pdfcrowd\HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // Run the conversion and store the result in the `pdf` variable. $pdf = $client->convertUrl("http://www.example.com"); // at this point the "pdf" variable contains PDF raw data and // can be sent in an HTTP response, saved to a file, etc. } catch(\Pdfcrowd\Error $why) { error_log("Pdfcrowd Error: {$why}\n"); throw $why; } ?>
<?php require "pdfcrowd.php"; try { // Create an API client instance. $client = new \Pdfcrowd\HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // Create an output stream for the conversion result $output_stream = fopen("example.pdf", "wb"); // Check for a file creation error. if (!$output_stream) throw new \Exception(error_get_last()['message']); // run the conversion and write the result to the output stream. $client->convertUrlToStream("http://www.example.com", $output_stream); // Close the output stream. fclose($output_stream); } catch(\Pdfcrowd\Error $why) { error_log("Pdfcrowd Error: {$why}\n"); throw $why; } ?>
<?php require "pdfcrowd.php"; try { // Create an API client instance. $client = new \Pdfcrowd\HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // Specify the mapping of HTML content width to the PDF page width. // To fine-tune the layout, you can specify an exact viewport width, such as '960px'. $client->setContentViewportWidth("balanced"); // Run the conversion and save the result to a file. $client->convertFileToFile("/path/to/MyLayout.html", "MyLayout.pdf"); } catch(\Pdfcrowd\Error $why) { error_log("Pdfcrowd Error: {$why}\n"); throw $why; } ?>
<?php require "pdfcrowd.php"; try { // Create an API client instance. $client = new \Pdfcrowd\HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // Run the conversion and store the result in the `pdf` variable. $pdf = $client->convertFile("/path/to/MyLayout.html"); // at this point the "pdf" variable contains PDF raw data and // can be sent in an HTTP response, saved to a file, etc. } catch(\Pdfcrowd\Error $why) { error_log("Pdfcrowd Error: {$why}\n"); throw $why; } ?>
<?php require "pdfcrowd.php"; try { // Create an API client instance. $client = new \Pdfcrowd\HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // Create an output stream for the conversion result $output_stream = fopen("MyLayout.pdf", "wb"); // Check for a file creation error. if (!$output_stream) throw new \Exception(error_get_last()['message']); // run the conversion and write the result to the output stream. $client->convertFileToStream("/path/to/MyLayout.html", $output_stream); // Close the output stream. fclose($output_stream); } catch(\Pdfcrowd\Error $why) { error_log("Pdfcrowd Error: {$why}\n"); throw $why; } ?>
<?php require "pdfcrowd.php"; try { // Create an API client instance. $client = new \Pdfcrowd\HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // Specify the mapping of HTML content width to the PDF page width. // To fine-tune the layout, you can specify an exact viewport width, such as '960px'. $client->setContentViewportWidth("balanced"); // Run the conversion and save the result to a file. $client->convertStringToFile("<html><body><h1>Hello World!</h1></body></html>", "HelloWorld.pdf"); } catch(\Pdfcrowd\Error $why) { error_log("Pdfcrowd Error: {$why}\n"); throw $why; } ?>
<?php require "pdfcrowd.php"; try { // Create an API client instance. $client = new \Pdfcrowd\HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // Run the conversion and store the result in the `pdf` variable. $pdf = $client->convertString("<html><body><h1>Hello World!</h1></body></html>"); // at this point the "pdf" variable contains PDF raw data and // can be sent in an HTTP response, saved to a file, etc. } catch(\Pdfcrowd\Error $why) { error_log("Pdfcrowd Error: {$why}\n"); throw $why; } ?>
<?php require "pdfcrowd.php"; try { // Create an API client instance. $client = new \Pdfcrowd\HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // Create an output stream for the conversion result $output_stream = fopen("HelloWorld.pdf", "wb"); // Check for a file creation error. if (!$output_stream) throw new \Exception(error_get_last()['message']); // run the conversion and write the result to the output stream. $client->convertStringToStream("<html><body><h1>Hello World!</h1></body></html>", $output_stream); // Close the output stream. fclose($output_stream); } catch(\Pdfcrowd\Error $why) { error_log("Pdfcrowd Error: {$why}\n"); throw $why; } ?>
<?php require "pdfcrowd.php"; try { // Create an API client instance. $client = new \Pdfcrowd\HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // Specify the mapping of HTML content width to the PDF page width. // To fine-tune the layout, you can specify an exact viewport width, such as '960px'. $client->setDebugLog(true); // Run the conversion and save the result to a file. $client->convertFileToFile("/path/to/MyLayout.html", "MyLayout.pdf"); // print URL of the debug log echo "Debug log url: " . $client->getDebugLogUrl() . "\n"; // print the number of conversion credits remaining in your account echo "Remaining credit count: " . $client->getRemainingCreditCount() . "\n"; // print the number of credits used for the conversion echo "Consumed credit count: " . $client->getConsumedCreditCount() . "\n"; // print the unique identifier for the conversion echo "Job id: " . $client->getJobId() . "\n"; // print total number of pages in the output document echo "Page count: " . $client->getPageCount() . "\n"; // print size of the output data in bytes echo "Output size: " . $client->getOutputSize() . "\n"; } catch(\Pdfcrowd\Error $why) { error_log("Pdfcrowd Error: {$why}\n"); throw $why; } ?>
<?php require "pdfcrowd.php"; try { // Create an API client instance. $client = new \Pdfcrowd\HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // Configure the conversion. $client->setPageSize("Letter"); $client->setOrientation("landscape"); $client->setNoMargins(true); // Run the conversion and save the result to a file. $client->convertUrlToFile("http://www.example.com", "letter_landscape.pdf"); } catch(\Pdfcrowd\Error $why) { error_log("Pdfcrowd Error: {$why}\n"); throw $why; } ?>
<?php require "pdfcrowd.php"; try { // Create an API client instance. $client = new \Pdfcrowd\HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // Configure the conversion. $client->setHeaderHeight("15mm"); $client->setFooterHeight("10mm"); $client->setHeaderHtml("<a class='pdfcrowd-source-url' data-pdfcrowd-placement='href-and-content'></a>"); $client->setFooterHtml("<center><span class='pdfcrowd-page-number'></span></center>"); $client->setMarginTop("0"); $client->setMarginBottom("0"); // Run the conversion and save the result to a file. $client->convertUrlToFile("http://www.example.com", "header_footer.pdf"); } catch(\Pdfcrowd\Error $why) { error_log("Pdfcrowd Error: {$why}\n"); throw $why; } ?>
<?php require "pdfcrowd.php"; try { // Create an API client instance. $client = new \Pdfcrowd\HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // Configure the conversion. $client->setEnablePdfForms(true); // Run the conversion and save the result to a file. $client->convertStringToFile("<html><body>Enter name:<input type=text></body></html>", "form.pdf"); } catch(\Pdfcrowd\Error $why) { error_log("Pdfcrowd Error: {$why}\n"); throw $why; } ?>
<?php require "pdfcrowd.php"; try { // Create an API client instance. $client = new \Pdfcrowd\HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // Configure the conversion. $client->setScaleFactor(300); // Run the conversion and save the result to a file. $client->convertUrlToFile("http://www.example.com", "zoom_300.pdf"); } catch(\Pdfcrowd\Error $why) { error_log("Pdfcrowd Error: {$why}\n"); throw $why; } ?>
<?php require "pdfcrowd.php"; try { // Create an API client instance. $client = new \Pdfcrowd\HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // Configure the conversion. $client->setAuthor("Pdfcrowd"); $client->setTitle("Hello World"); $client->setSubject("Demo"); $client->setKeywords("Pdfcrowd,demo"); // Run the conversion and save the result to a file. $client->convertUrlToFile("http://www.example.com", "with_metadata.pdf"); } catch(\Pdfcrowd\Error $why) { error_log("Pdfcrowd Error: {$why}\n"); throw $why; } ?>
<?php require "pdfcrowd.php"; try { // Create an API client instance. $client = new \Pdfcrowd\HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // Configure the conversion. $client->setPageLayout("single-page"); $client->setPageMode("full-screen"); $client->setInitialZoomType("fit-page"); $client->setOrientation("landscape"); $client->setNoMargins(true); // Run the conversion and save the result to a file. $client->convertUrlToFile("https://pdfcrowd.com/api/", "slide_show.pdf"); } catch(\Pdfcrowd\Error $why) { error_log("Pdfcrowd Error: {$why}\n"); throw $why; } ?>
<?php require "pdfcrowd.php"; try { // Create an API client instance. $client = new \Pdfcrowd\HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // Configure the conversion. $client->setElementToConvert("#main"); // Run the conversion and save the result to a file. $client->convertUrlToFile("https://pdfcrowd.com/api/", "html_part.pdf"); } catch(\Pdfcrowd\Error $why) { error_log("Pdfcrowd Error: {$why}\n"); throw $why; } ?>
<?php require "pdfcrowd.php"; try { // Create an API client instance. $client = new \Pdfcrowd\HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // Configure the conversion. $client->setCustomJavascript("el=document.createElement('h2'); el.textContent='Hello from Pdfcrowd API'; el.style.color='red'; el_before=document.getElementsByTagName('h1')[0]; el_before.parentNode.insertBefore(el, el_before.nextSibling)"); // Run the conversion and save the result to a file. $client->convertUrlToFile("http://www.example.com", "html_inject.pdf"); } catch(\Pdfcrowd\Error $why) { error_log("Pdfcrowd Error: {$why}\n"); throw $why; } ?>
<?php require "pdfcrowd.php"; try { // Create an API client instance. $client = new \Pdfcrowd\HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // Configure the conversion. $client->setContentViewportWidth("large"); $client->setNoMargins(true); // Run the conversion and save the result to a file. $client->convertUrlToFile("https://getbootstrap.com/", "bootstrap.pdf"); } catch(\Pdfcrowd\Error $why) { error_log("Pdfcrowd Error: {$why}\n"); throw $why; } ?>
<?php require "pdfcrowd.php"; require "vendor/autoload.php"; try { // Create an API client instance. $client = new \Pdfcrowd\HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // Create a ZIP archive. $options = new ZipStream\Option\Archive(); $in_stream = fopen("php://memory", "rw"); $options->setOutputStream($in_stream); $zip = new ZipStream\ZipStream("stream.zip", $options); // Add HTML content to the archive. $zip->addFile("index.html", "<html> <head> <style> @font-face { font-family: 'OpenSans'; src: url(fonts/OpenSans.ttf) format('truetype'); } h1 { font-family: OpenSans; } </style> </head> <body> <h1>Hello World</h1> <img src='images/logo.png'> </body> </html>"); # Add required local files to the archive. $zip->addFileFromPath("fonts/OpenSans.ttf", "/your-path-to/fonts/OpenSans.ttf"); $zip->addFileFromPath("images/logo.png", "/your-path-to/images/logo.png"); $zip->finish(); fseek($in_stream, 0); // Create an output stream for the conversion result $output_stream = fopen("HelloFromZip.pdf", "wb"); // Check for a file creation error. if (!$output_stream) throw new \Exception(error_get_last()['message']); // run the conversion and write the result to the output stream. $client->convertStreamToStream($in_stream, $output_stream); // Close the output stream. fclose($output_stream); } catch(\Pdfcrowd\Error $why) { error_log("Pdfcrowd Error: {$why}\n"); throw $why; } ?>
<?php require "pdfcrowd.php"; try { // Create an API client instance. $client = new \Pdfcrowd\HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // Configure the conversion. $client->setCustomJavascript("libPdfcrowd.highlightHtmlElements({backgroundColor: 'rgba(255, 191, 0, 0.1)', borderColor:null})"); // Run the conversion and save the result to a file. $client->convertUrlToFile("http://www.example.com", "highlight_background.pdf"); } catch(\Pdfcrowd\Error $why) { error_log("Pdfcrowd Error: {$why}\n"); throw $why; } ?>
<?php require "pdfcrowd.php"; try { // Create an API client instance. $client = new \Pdfcrowd\HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // Configure the conversion. $client->setCustomJavascript("libPdfcrowd.highlightHtmlElements({borderColor: 'orange', backgroundColor: null, padding: '4px', margin: '4px'})"); // Run the conversion and save the result to a file. $client->convertUrlToFile("http://www.example.com", "highlight_borders.pdf"); } catch(\Pdfcrowd\Error $why) { error_log("Pdfcrowd Error: {$why}\n"); throw $why; } ?>
<?php require "pdfcrowd.php"; try { // Create an API client instance. $client = new \Pdfcrowd\HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // Configure the conversion. $client->setDataString('{ "name": "World", "product": "Pdfcrowd API" }'); // Run the conversion and save the result to a file. $client->convertStringToFile("Hello {{ name }} from {{ product }}", "output.pdf"); } catch(\Pdfcrowd\Error $why) { error_log("Pdfcrowd Error: {$why}\n"); throw $why; } ?>
<?php require "pdfcrowd.php"; try { // Create an API client instance. $client = new \Pdfcrowd\HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // Configure the conversion. $client->setDataString('<?xml version="1.0" encoding="UTF-8"?> <data> <name>World</name> <product>Pdfcrowd API</product> </data>'); // Run the conversion and save the result to a file. $client->convertStringToFile("Hello {{ data.name }} from {{ data.product }}", "output.pdf"); } catch(\Pdfcrowd\Error $why) { error_log("Pdfcrowd Error: {$why}\n"); throw $why; } ?>
<?php require "pdfcrowd.php"; try { // Create an API client instance. $client = new \Pdfcrowd\HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // Configure the conversion. $client->setDataString("name: World product: Pdfcrowd API"); // Run the conversion and save the result to a file. $client->convertStringToFile("Hello {{ name }} from {{ product }}", "output.pdf"); } catch(\Pdfcrowd\Error $why) { error_log("Pdfcrowd Error: {$why}\n"); throw $why; } ?>
<?php require "pdfcrowd.php"; try { // Create an API client instance. $client = new \Pdfcrowd\HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // Configure the conversion. $client->setDataString("name,product World,Pdfcrowd API"); // Run the conversion and save the result to a file. $client->convertStringToFile("Hello {{ name }} from {{ product }}", "output.pdf"); } catch(\Pdfcrowd\Error $why) { error_log("Pdfcrowd Error: {$why}\n"); throw $why; } ?>
<?php require 'pdfcrowd.php'; // The recommended method is POST. if($_SERVER['REQUEST_METHOD'] == 'POST') { try { // Create an API client instance. $client = new \Pdfcrowd\HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // Run the conversion. $pdf = $client->convertUrl("http://www.example.com"); // Set HTTP response headers. header("Content-Type: application/pdf"); header("Cache-Control: no-cache"); header("Accept-Ranges: none"); header("Content-Disposition: attachment; filename*=UTF-8''" . rawurlencode("example.pdf")); echo $pdf; } catch(\Pdfcrowd\Error $why) { // Report the error. header("Content-Type: text/plain"); http_response_code($why->getCode()); echo "Pdfcrowd Error: {$why}"; } } ?>
<?php require 'pdfcrowd.php'; // The recommended method is POST. if($_SERVER['REQUEST_METHOD'] == 'POST') { try { // Create an API client instance. $client = new \Pdfcrowd\HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // Run the conversion. $pdf = $client->convertFile("/path/to/MyLayout.html"); // Set HTTP response headers. header("Content-Type: application/pdf"); header("Cache-Control: no-cache"); header("Accept-Ranges: none"); header("Content-Disposition: attachment; filename*=UTF-8''" . rawurlencode("MyLayout.pdf")); echo $pdf; } catch(\Pdfcrowd\Error $why) { // Report the error. header("Content-Type: text/plain"); http_response_code($why->getCode()); echo "Pdfcrowd Error: {$why}"; } } ?>
<?php require 'pdfcrowd.php'; // The recommended method is POST. if($_SERVER['REQUEST_METHOD'] == 'POST') { try { // Create an API client instance. $client = new \Pdfcrowd\HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // Run the conversion. $pdf = $client->convertString("<html><body><h1>Hello World!</h1></body></html>"); // Set HTTP response headers. header("Content-Type: application/pdf"); header("Cache-Control: no-cache"); header("Accept-Ranges: none"); header("Content-Disposition: attachment; filename*=UTF-8''" . rawurlencode("HelloWorld.pdf")); echo $pdf; } catch(\Pdfcrowd\Error $why) { // Report the error. header("Content-Type: text/plain"); http_response_code($why->getCode()); echo "Pdfcrowd Error: {$why}"; } } ?>
<?php // The recommended method is POST. Route::post('/', function () { try { // Create an API client instance. $client = new \Pdfcrowd\HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // Run the conversion and store the result in the `pdf` variable. $pdf = $client->convertUrl("http://www.example.com"); // Send the result and set HTTP response headers. return response($pdf) ->header("Content-Type", "application/pdf") ->header("Cache-Control", "no-cache") ->header("Accept-Ranges", "none") ->header("Content-Disposition", "attachment; filename*=UTF-8''" . rawurlencode("example.pdf")); } catch(\Pdfcrowd\Error $why) { // Send the error in the HTTP response. return response($why->getMessage(), $why->getCode()) ->header("Content-Type", "text/plain"); } }); ?>
<?php // The recommended method is POST. Route::post('/', function () { try { // Create an API client instance. $client = new \Pdfcrowd\HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // Run the conversion and store the result in the `pdf` variable. $pdf = $client->convertFile("/path/to/MyLayout.html"); // Send the result and set HTTP response headers. return response($pdf) ->header("Content-Type", "application/pdf") ->header("Cache-Control", "no-cache") ->header("Accept-Ranges", "none") ->header("Content-Disposition", "attachment; filename*=UTF-8''" . rawurlencode("MyLayout.pdf")); } catch(\Pdfcrowd\Error $why) { // Send the error in the HTTP response. return response($why->getMessage(), $why->getCode()) ->header("Content-Type", "text/plain"); } }); ?>
<?php // The recommended method is POST. Route::post('/', function () { try { // Create an API client instance. $client = new \Pdfcrowd\HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // Run the conversion and store the result in the `pdf` variable. $pdf = $client->convertString("<html><body><h1>Hello World!</h1></body></html>"); // Send the result and set HTTP response headers. return response($pdf) ->header("Content-Type", "application/pdf") ->header("Cache-Control", "no-cache") ->header("Accept-Ranges", "none") ->header("Content-Disposition", "attachment; filename*=UTF-8''" . rawurlencode("HelloWorld.pdf")); } catch(\Pdfcrowd\Error $why) { // Send the error in the HTTP response. return response($why->getMessage(), $why->getCode()) ->header("Content-Type", "text/plain"); } }); ?>
<?php namespace App\Controller; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\HttpFoundation\Response; class DemoController { /** * @Route("/", methods={"POST"}) * The recommended method is POST. */ public function convert() { try { // Create an API client instance. $client = new \Pdfcrowd\HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // Run the conversion and store the result in the `pdf` variable. $pdf = $client->convertUrl("http://www.example.com"); // Send the result and set HTTP response headers. return new Response( $pdf, Response::HTTP_OK, ["Content-Type" => "application/pdf", "Cache-Control" => "no-cache", "Accept-Ranges" => "none", "Content-Disposition" => "attachment; filename*=UTF-8''" . rawurlencode("example.pdf")]); } catch(\Pdfcrowd\Error $why) { // Send the error in the HTTP response. return new Response($why->getMessage(), $why->getCode(), ["Content-Type" => "text/plain"]); } } }
<?php namespace App\Controller; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\HttpFoundation\Response; class DemoController { /** * @Route("/", methods={"POST"}) * The recommended method is POST. */ public function convert() { try { // Create an API client instance. $client = new \Pdfcrowd\HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // Run the conversion and store the result in the `pdf` variable. $pdf = $client->convertFile("/path/to/MyLayout.html"); // Send the result and set HTTP response headers. return new Response( $pdf, Response::HTTP_OK, ["Content-Type" => "application/pdf", "Cache-Control" => "no-cache", "Accept-Ranges" => "none", "Content-Disposition" => "attachment; filename*=UTF-8''" . rawurlencode("MyLayout.pdf")]); } catch(\Pdfcrowd\Error $why) { // Send the error in the HTTP response. return new Response($why->getMessage(), $why->getCode(), ["Content-Type" => "text/plain"]); } } }
<?php namespace App\Controller; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\HttpFoundation\Response; class DemoController { /** * @Route("/", methods={"POST"}) * The recommended method is POST. */ public function convert() { try { // Create an API client instance. $client = new \Pdfcrowd\HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // Run the conversion and store the result in the `pdf` variable. $pdf = $client->convertString("<html><body><h1>Hello World!</h1></body></html>"); // Send the result and set HTTP response headers. return new Response( $pdf, Response::HTTP_OK, ["Content-Type" => "application/pdf", "Cache-Control" => "no-cache", "Accept-Ranges" => "none", "Content-Disposition" => "attachment; filename*=UTF-8''" . rawurlencode("HelloWorld.pdf")]); } catch(\Pdfcrowd\Error $why) { // Send the error in the HTTP response. return new Response($why->getMessage(), $why->getCode(), ["Content-Type" => "text/plain"]); } } }