{"id":1523,"date":"2016-05-12T18:13:16","date_gmt":"2016-05-12T18:13:16","guid":{"rendered":"https:\/\/www.codexworld.com\/?p=1523"},"modified":"2025-08-10T11:13:17","modified_gmt":"2025-08-10T11:13:17","slug":"convert-html-to-pdf-php-dompdf","status":"publish","type":"post","link":"https:\/\/www.codexworld.com\/convert-html-to-pdf-php-dompdf\/","title":{"rendered":"Convert HTML to PDF in PHP with Dompdf"},"content":{"rendered":"<p>PDF is a file format created by Adobe Systems for illustrating text and images in a fixed-layout document. PDF is used to download a bunch of data or text content in the web application. The PDF file format is the perfect choice to download text or HTML content in a file. At the time of downloading web page content as a PDF file, it requires converting HTML to PDF. In this tutorial, we will show you how to <b>convert HTML to PDF<\/b> and generate PDF files using PHP.<\/p>\n<p>Dompdf is a PHP library that provides a simple way to convert HTML to PDF documents. Using the Dompdf library, you can easily generate a PDF from an HTML page in PHP. The example code will help you to implement PDF generation functionality in the web application and make it simple to <b>convert HTML to PDF in PHP<\/b> with Dompdf.<\/p>\n<h2>Dompdf Installation and Setup<\/h2>\n<p>Before getting started, <a href=\"https:\/\/github.com\/dompdf\/dompdf\/releases\" target=\"_blank\" rel=\"noopener\">download stable release<\/a> of the Dompdf library and include it in the project directory.<\/p>\n<p><span class=\"note\">Note that:<\/span> You don&#8217;t need to download the Dompdf library separately, all the required files are included in our source code package.<\/p>\n<h2>Instantiate Dompdf Class<\/h2>\n<p>To use the Dompdf class, you need to include the autoloader in the PHP script. Use the following PHP code to instantiate and use the dompdf class.<\/p>\n<pre><span style=\"color: #FF8000\">\/\/&nbsp;Include&nbsp;autoloader <br \/><\/span><span style=\"color: #007700\">require_once&nbsp;<\/span><span style=\"color: #DD0000\">'dompdf\/autoload.inc.php'<\/span><span style=\"color: #007700\">; <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Reference&nbsp;the&nbsp;Dompdf&nbsp;namespace <br \/><\/span><span style=\"color: #007700\">use&nbsp;<\/span><span style=\"color: #0000BB\">Dompdf<\/span><span style=\"color: #007700\">\\<\/span><span style=\"color: #0000BB\">Dompdf<\/span><span style=\"color: #007700\">; <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Instantiate&nbsp;and&nbsp;use&nbsp;the&nbsp;dompdf&nbsp;class <br \/><\/span><span style=\"color: #0000BB\">$dompdf&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;new&nbsp;<\/span><span style=\"color: #0000BB\">Dompdf<\/span><span style=\"color: #007700\">();<\/span><\/pre>\n<h2>Convert HTML to PDF in PHP using Dompdf library<\/h2>\n<p>In the following examples, we will generate PDF from HTML content with Dompdf in PHP.<\/p>\n<p><b><u>Basic Usage:<\/u><\/b><br \/>\nThe following example shows how to use Dompdf to convert HTML and generate PDF with minimal configuration.<\/p>\n<ul class=\"bullet_disk_list\">\n<li>Specify the HTML content in <b>loadHtml()<\/b> method of Dompdf class.<\/li>\n<li>Render HTML as PDF using <b>render()<\/b> method.<\/li>\n<li>Output the generated PDF to the Browser using <b>stream()<\/b> method.<\/li>\n<\/ul>\n<pre><span style=\"color: #FF8000\">\/\/&nbsp;Load&nbsp;HTML&nbsp;content <br \/><\/span><span style=\"color: #0000BB\">$dompdf<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">loadHtml<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'&lt;h1&gt;Welcome&nbsp;to&nbsp;CodexWorld.com&lt;\/h1&gt;'<\/span><span style=\"color: #007700\">); <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;(Optional)&nbsp;Setup&nbsp;the&nbsp;paper&nbsp;size&nbsp;and&nbsp;orientation <br \/><\/span><span style=\"color: #0000BB\">$dompdf<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">setPaper<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'A4'<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'landscape'<\/span><span style=\"color: #007700\">); <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Render&nbsp;the&nbsp;HTML&nbsp;as&nbsp;PDF <br \/><\/span><span style=\"color: #0000BB\">$dompdf<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">render<\/span><span style=\"color: #007700\">(); <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Output&nbsp;the&nbsp;generated&nbsp;PDF&nbsp;to&nbsp;Browser <br \/><\/span><span style=\"color: #0000BB\">$dompdf<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">stream<\/span><span style=\"color: #007700\">();<\/span><\/pre>\n<p><b><u>Advanced Usage:<\/u><\/b><br \/>\nWith the Dompdf library, you can easily enhance the functionality of PDF creation. The following code generates PDF from an HTML file (<code>pdf-content.html<\/code>).<\/p>\n<ul class=\"bullet_disk_list\">\n<li>Get content from HTML file using the <b>file_get_contents()<\/b> function in PHP.<\/li>\n<li>Load HTML content using <b>loadHtml()<\/b> method of Dompdf class.<\/li>\n<li>Control the PDF output using the <b>stream()<\/b> function of Dompdf class.\n<ul>\n<li><code>$filename<\/code> &#8211; (string) Name of the PDF file.<\/li>\n<li><code>$options<\/code> &#8211; (array) Header options.\n<ul>\n<li><code>Attachment<\/code> &#8211; 1=download and 0=preview<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<pre><span style=\"color: #FF8000\">\/\/&nbsp;Load&nbsp;content&nbsp;from&nbsp;html&nbsp;file <br \/><\/span><span style=\"color: #0000BB\">$html&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">file_get_contents<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">\"pdf-content.html\"<\/span><span style=\"color: #007700\">); <br \/><\/span><span style=\"color: #0000BB\">$dompdf<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">loadHtml<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$html<\/span><span style=\"color: #007700\">); <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;(Optional)&nbsp;Setup&nbsp;the&nbsp;paper&nbsp;size&nbsp;and&nbsp;orientation <br \/><\/span><span style=\"color: #0000BB\">$dompdf<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">setPaper<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'A4'<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #DD0000\">'landscape'<\/span><span style=\"color: #007700\">); <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Render&nbsp;the&nbsp;HTML&nbsp;as&nbsp;PDF <br \/><\/span><span style=\"color: #0000BB\">$dompdf<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">render<\/span><span style=\"color: #007700\">(); <br \/> <br \/><\/span><span style=\"color: #FF8000\">\/\/&nbsp;Output&nbsp;the&nbsp;generated&nbsp;PDF&nbsp;(1&nbsp;=&nbsp;download&nbsp;and&nbsp;0&nbsp;=&nbsp;preview) <br \/><\/span><span style=\"color: #0000BB\">$dompdf<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">stream<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">\"codexworld\"<\/span><span style=\"color: #007700\">,&nbsp;array(<\/span><span style=\"color: #DD0000\">\"Attachment\"&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #0000BB\">0<\/span><span style=\"color: #007700\">));<\/span><\/pre>\n<h2>Dompdf Useful Methods<\/h2>\n<p>Dompdf library provides various methods and options to configure PDF creation and customize PDF documents. Some of the useful methods of Dompdf class are given below that are commonly used to integrate HTML into PDF functionality.<\/p>\n<p><b>loadHtml():<\/b> Loads HTML content.<\/p>\n<ul class=\"bullet_disk_list\">\n<li><code>$str<\/code> (string) &#8211; Required. Specify HTML to load.<\/li>\n<li><code>$encoding<\/code> (string) &#8211; Optional. Specify encoding.<\/li>\n<\/ul>\n<p><b>loadHtmlFile():<\/b> Loads content from an HTML file.<\/p>\n<ul class=\"bullet_disk_list\">\n<li><code>$file<\/code> (string) &#8211; Required. Specify filename or url to load.<\/li>\n<\/ul>\n<p><b>output():<\/b> Returns the PDF as a string.<\/p>\n<ul class=\"bullet_disk_list\">\n<li><code>$options<\/code> (array) &#8211; Optional. Specify whether content stream compression will enable. (compress => 1 or 0)<\/li>\n<\/ul>\n<p><b>render():<\/b> Renders the HTML to PDF.<\/p>\n<p><b>setBasePath():<\/b> Sets the base path to include external stylesheets and images.<\/p>\n<ul class=\"bullet_disk_list\">\n<li><code>$basePath<\/code> (string) &#8211; The base path to be used when loading the external resources URLs.<\/li>\n<\/ul>\n<p><b>setPaper():<\/b> Sets the paper size &#038; orientation.<\/p>\n<ul class=\"bullet_disk_list\">\n<li><code>$size<\/code> (string|array) &#8211; &apos;letter&apos;, &apos;legal&apos;, &apos;A4&apos;, etc.<\/li>\n<li><code>$orientation<\/code> (string) &#8211; &apos;portrait&apos; or &apos;landscape&apos;.<\/li>\n<\/ul>\n<p><b>stream():<\/b> Streams the PDF to the client.<\/p>\n<ul class=\"bullet_disk_list\">\n<li><code>$filename<\/code> (string) &#8211; Specify name of the file to be streamed (without .pdf extension).\n<li><code>$options<\/code> (array) &#8211;\n<ul>\n<li>&apos;compress&apos; => 1 or 0 &#8211; enable content stream compression.<\/li>\n<li>&apos;Attachment&apos; => 1=download or 0=preview<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p class=\"seeAlso\"><span><\/span><a href=\"https:\/\/www.codexworld.com\/convert-html-to-pdf-using-javascript-jspdf\/\">Convert HTML to PDF using JavaScript<\/a><\/span><\/p>\n<h2>Conclusion<\/h2>\n<p>In this tutorial, we have tried to provide an easy way to <b>convert HTML to PDF with Dompdf using PHP<\/b>. Our example code shows the most commonly used configuration option to generate PDF in PHP. You can easily extend the functionality using the Dompdf configuration options as per your needs. Download the source code to get all the required files including the Dompdf library.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PDF is a file format created by Adobe Systems for illustrating text and images in a fixed-layout document. PDF is used to download a bunch of data or text content in the web application. The <\/p>\n","protected":false},"author":1,"featured_media":5159,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[4],"tags":[180,179,181,14],"class_list":["post-1523","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php","tag-dompdf","tag-html","tag-pdf","tag-php","cat-4-id","has_thumb"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Convert HTML to PDF in PHP with Dompdf - CodexWorld<\/title>\n<meta name=\"description\" content=\"Convert HTML to PDF in PHP using Dompdf library - Simple script to generate PDF from HTML content with Dompdf. Convert HTML to PDF in PHP with Dompdf.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.codexworld.com\/convert-html-to-pdf-php-dompdf\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Convert HTML to PDF in PHP with Dompdf - CodexWorld\" \/>\n<meta property=\"og:description\" content=\"Convert HTML to PDF in PHP using Dompdf library - Simple script to generate PDF from HTML content with Dompdf. Convert HTML to PDF in PHP with Dompdf.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.codexworld.com\/convert-html-to-pdf-php-dompdf\/\" \/>\n<meta property=\"og:site_name\" content=\"CodexWorld\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/codexworld\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/codexworld\" \/>\n<meta property=\"article:published_time\" content=\"2016-05-12T18:13:16+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-08-10T11:13:17+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.codexworld.com\/wp-content\/uploads\/2016\/05\/convert-html-to-pdf-with-dompdf-library-using-php-codexworld.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1366\" \/>\n\t<meta property=\"og:image:height\" content=\"768\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"CodexWorld\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@codexworldblog\" \/>\n<meta name=\"twitter:site\" content=\"@codexworldweb\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"CodexWorld\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/convert-html-to-pdf-php-dompdf\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/convert-html-to-pdf-php-dompdf\\\/\"},\"author\":{\"name\":\"CodexWorld\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#\\\/schema\\\/person\\\/9da51d8fa3cdefeb5ec9c69136d4baf0\"},\"headline\":\"Convert HTML to PDF in PHP with Dompdf\",\"datePublished\":\"2016-05-12T18:13:16+00:00\",\"dateModified\":\"2025-08-10T11:13:17+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/convert-html-to-pdf-php-dompdf\\\/\"},\"wordCount\":629,\"commentCount\":7,\"publisher\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/convert-html-to-pdf-php-dompdf\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2016\\\/05\\\/convert-html-to-pdf-with-dompdf-library-using-php-codexworld.png\",\"keywords\":[\"Dompdf\",\"HTML\",\"PDF\",\"PHP\"],\"articleSection\":[\"PHP\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.codexworld.com\\\/convert-html-to-pdf-php-dompdf\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/convert-html-to-pdf-php-dompdf\\\/\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/convert-html-to-pdf-php-dompdf\\\/\",\"name\":\"Convert HTML to PDF in PHP with Dompdf - CodexWorld\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/convert-html-to-pdf-php-dompdf\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/convert-html-to-pdf-php-dompdf\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2016\\\/05\\\/convert-html-to-pdf-with-dompdf-library-using-php-codexworld.png\",\"datePublished\":\"2016-05-12T18:13:16+00:00\",\"dateModified\":\"2025-08-10T11:13:17+00:00\",\"description\":\"Convert HTML to PDF in PHP using Dompdf library - Simple script to generate PDF from HTML content with Dompdf. Convert HTML to PDF in PHP with Dompdf.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/convert-html-to-pdf-php-dompdf\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.codexworld.com\\\/convert-html-to-pdf-php-dompdf\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/convert-html-to-pdf-php-dompdf\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2016\\\/05\\\/convert-html-to-pdf-with-dompdf-library-using-php-codexworld.png\",\"contentUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2016\\\/05\\\/convert-html-to-pdf-with-dompdf-library-using-php-codexworld.png\",\"width\":1366,\"height\":768,\"caption\":\"convert-html-to-pdf-with-dompdf-library-using-php-codexworld\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/convert-html-to-pdf-php-dompdf\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.codexworld.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Convert HTML to PDF in PHP with Dompdf\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#website\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/\",\"name\":\"CodexWorld\",\"description\":\"Web &amp; Mobile App Development Company\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.codexworld.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#organization\",\"name\":\"CodexWorld\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2014\\\/09\\\/codexworld-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2014\\\/09\\\/codexworld-logo.png\",\"width\":200,\"height\":19,\"caption\":\"CodexWorld\"},\"image\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/codexworld\",\"https:\\\/\\\/x.com\\\/codexworldweb\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/codexworld\",\"https:\\\/\\\/www.youtube.com\\\/codexworld\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#\\\/schema\\\/person\\\/9da51d8fa3cdefeb5ec9c69136d4baf0\",\"name\":\"CodexWorld\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g\",\"caption\":\"CodexWorld\"},\"description\":\"CodexWorld is a programming blog, one-stop destination for web professionals \u2014 developers, programmers, freelancers, and site owners.\",\"sameAs\":[\"http:\\\/\\\/www.codexworld.com\",\"https:\\\/\\\/www.facebook.com\\\/codexworld\",\"https:\\\/\\\/x.com\\\/codexworldblog\"],\"url\":\"https:\\\/\\\/www.codexworld.com\\\/author\\\/nitya192265\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Convert HTML to PDF in PHP with Dompdf - CodexWorld","description":"Convert HTML to PDF in PHP using Dompdf library - Simple script to generate PDF from HTML content with Dompdf. Convert HTML to PDF in PHP with Dompdf.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.codexworld.com\/convert-html-to-pdf-php-dompdf\/","og_locale":"en_US","og_type":"article","og_title":"Convert HTML to PDF in PHP with Dompdf - CodexWorld","og_description":"Convert HTML to PDF in PHP using Dompdf library - Simple script to generate PDF from HTML content with Dompdf. Convert HTML to PDF in PHP with Dompdf.","og_url":"https:\/\/www.codexworld.com\/convert-html-to-pdf-php-dompdf\/","og_site_name":"CodexWorld","article_publisher":"https:\/\/www.facebook.com\/codexworld","article_author":"https:\/\/www.facebook.com\/codexworld","article_published_time":"2016-05-12T18:13:16+00:00","article_modified_time":"2025-08-10T11:13:17+00:00","og_image":[{"width":1366,"height":768,"url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2016\/05\/convert-html-to-pdf-with-dompdf-library-using-php-codexworld.png","type":"image\/png"}],"author":"CodexWorld","twitter_card":"summary_large_image","twitter_creator":"@codexworldblog","twitter_site":"@codexworldweb","twitter_misc":{"Written by":"CodexWorld","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.codexworld.com\/convert-html-to-pdf-php-dompdf\/#article","isPartOf":{"@id":"https:\/\/www.codexworld.com\/convert-html-to-pdf-php-dompdf\/"},"author":{"name":"CodexWorld","@id":"https:\/\/www.codexworld.com\/#\/schema\/person\/9da51d8fa3cdefeb5ec9c69136d4baf0"},"headline":"Convert HTML to PDF in PHP with Dompdf","datePublished":"2016-05-12T18:13:16+00:00","dateModified":"2025-08-10T11:13:17+00:00","mainEntityOfPage":{"@id":"https:\/\/www.codexworld.com\/convert-html-to-pdf-php-dompdf\/"},"wordCount":629,"commentCount":7,"publisher":{"@id":"https:\/\/www.codexworld.com\/#organization"},"image":{"@id":"https:\/\/www.codexworld.com\/convert-html-to-pdf-php-dompdf\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2016\/05\/convert-html-to-pdf-with-dompdf-library-using-php-codexworld.png","keywords":["Dompdf","HTML","PDF","PHP"],"articleSection":["PHP"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.codexworld.com\/convert-html-to-pdf-php-dompdf\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.codexworld.com\/convert-html-to-pdf-php-dompdf\/","url":"https:\/\/www.codexworld.com\/convert-html-to-pdf-php-dompdf\/","name":"Convert HTML to PDF in PHP with Dompdf - CodexWorld","isPartOf":{"@id":"https:\/\/www.codexworld.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.codexworld.com\/convert-html-to-pdf-php-dompdf\/#primaryimage"},"image":{"@id":"https:\/\/www.codexworld.com\/convert-html-to-pdf-php-dompdf\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2016\/05\/convert-html-to-pdf-with-dompdf-library-using-php-codexworld.png","datePublished":"2016-05-12T18:13:16+00:00","dateModified":"2025-08-10T11:13:17+00:00","description":"Convert HTML to PDF in PHP using Dompdf library - Simple script to generate PDF from HTML content with Dompdf. Convert HTML to PDF in PHP with Dompdf.","breadcrumb":{"@id":"https:\/\/www.codexworld.com\/convert-html-to-pdf-php-dompdf\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.codexworld.com\/convert-html-to-pdf-php-dompdf\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codexworld.com\/convert-html-to-pdf-php-dompdf\/#primaryimage","url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2016\/05\/convert-html-to-pdf-with-dompdf-library-using-php-codexworld.png","contentUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2016\/05\/convert-html-to-pdf-with-dompdf-library-using-php-codexworld.png","width":1366,"height":768,"caption":"convert-html-to-pdf-with-dompdf-library-using-php-codexworld"},{"@type":"BreadcrumbList","@id":"https:\/\/www.codexworld.com\/convert-html-to-pdf-php-dompdf\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.codexworld.com\/"},{"@type":"ListItem","position":2,"name":"Convert HTML to PDF in PHP with Dompdf"}]},{"@type":"WebSite","@id":"https:\/\/www.codexworld.com\/#website","url":"https:\/\/www.codexworld.com\/","name":"CodexWorld","description":"Web &amp; Mobile App Development Company","publisher":{"@id":"https:\/\/www.codexworld.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.codexworld.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.codexworld.com\/#organization","name":"CodexWorld","url":"https:\/\/www.codexworld.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codexworld.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2014\/09\/codexworld-logo.png","contentUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2014\/09\/codexworld-logo.png","width":200,"height":19,"caption":"CodexWorld"},"image":{"@id":"https:\/\/www.codexworld.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/codexworld","https:\/\/x.com\/codexworldweb","https:\/\/www.linkedin.com\/company\/codexworld","https:\/\/www.youtube.com\/codexworld"]},{"@type":"Person","@id":"https:\/\/www.codexworld.com\/#\/schema\/person\/9da51d8fa3cdefeb5ec9c69136d4baf0","name":"CodexWorld","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g","caption":"CodexWorld"},"description":"CodexWorld is a programming blog, one-stop destination for web professionals \u2014 developers, programmers, freelancers, and site owners.","sameAs":["http:\/\/www.codexworld.com","https:\/\/www.facebook.com\/codexworld","https:\/\/x.com\/codexworldblog"],"url":"https:\/\/www.codexworld.com\/author\/nitya192265\/"}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2016\/05\/convert-html-to-pdf-with-dompdf-library-using-php-codexworld.png","jetpack_shortlink":"https:\/\/wp.me\/p6bxIh-oz","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts\/1523","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/comments?post=1523"}],"version-history":[{"count":15,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts\/1523\/revisions"}],"predecessor-version":[{"id":5858,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts\/1523\/revisions\/5858"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/media\/5159"}],"wp:attachment":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/media?parent=1523"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/categories?post=1523"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/tags?post=1523"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}