Title: background-image
Last modified: August 20, 2016

---

# background-image

 *  Resolved [Twanneman](https://wordpress.org/support/users/twanneman/)
 * (@twanneman)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/background-image-32/)
 * I’ve found this code to include a background-image :
 *     ```
       class MYPDF extends TCPDF {
       	public function Header() {
       		$bMargin = $this->getBreakMargin();
       		$auto_page_break = $this->AutoPageBreak;
       		$this->SetAutoPageBreak(false, 0);
       		$img_file = K_PATH_IMAGES.'background.jpg';
       		$this->Image($img_file, 0, 0, 210, 297, '', '', '', false, 300, '', false, false, 0);
       		$this->SetAutoPageBreak($auto_page_break, $bMargin);
       		$this->setPageMark();
       	}
       }
   
       $pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
       ```
   
 * I’ve paste these lines into the wp-post-to-pdf.php file > function generate_pdf_file
   after the lines :
 *     ```
       if(!class_exists('TCPDF'))				{ require_once(WPPT0PDF_PATH . '/tcpdf/tcpdf.php'); }
                   if(!class_exists('simple_html_dom'))	{ require_once(WPPT0PDF_PATH . '/simplehtmldom/simple-html-dom.php');}
       ```
   
 * But then the script stops working.
    I know alot of people want a background image
   for the generated PDF, could you please post an example ?
 * Kind regards, Twan
 * [http://wordpress.org/extend/plugins/wp-post-to-pdf/](http://wordpress.org/extend/plugins/wp-post-to-pdf/)

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Thread Starter [Twanneman](https://wordpress.org/support/users/twanneman/)
 * (@twanneman)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/background-image-32/#post-3361354)
 * never mind, already figured it out :
 * I’ve added the following line
 *     ```
       if(!class_exists('MYPDF'))				{ require_once(WPPT0PDF_PATH . '/tcpdf/background.php'); }
       ```
   
 * after :
 *     ```
       if(!class_exists('TCPDF'))				{ require_once(WPPT0PDF_PATH . '/tcpdf/tcpdf.php'); }
       ```
   
 * and placed these lines in a new file background.php located in the tcpdf folder:
 *     ```
       <?php
       // Extend the TCPDF class to create custom Header and Footer
       class MYPDF extends TCPDF {
           //Page header
           public function Header() {
               // get the current page break margin
               $bMargin = $this->getBreakMargin();
               // get current auto-page-break mode
               $auto_page_break = $this->AutoPageBreak;
               // disable auto-page-break
               $this->SetAutoPageBreak(false, 0);
               // set bacground image
       		$img_file = WPPT0PDF_PATH .'/tcpdf/images/background.jpg';
               $this->Image($img_file, 0, 0, 210, 297, '', '', '', false, 300, '', false, false, 0);
               // restore auto-page-break status
               $this->SetAutoPageBreak($auto_page_break, $bMargin);
               // set the starting point for the page content
               $this->setPageMark();
           }
       }
       ?>
       ```
   
 * The image file is 1181px by 1772px and located in the tcpfg/images folder
 *  [stheoret](https://wordpress.org/support/users/stheoret/)
 * (@stheoret)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/background-image-32/#post-3361789)
 * Could you provide me the complete file wp-post-to-pdf.php ???
 * I am following your steps but my website get me a 500 error …
 * I saw some parenthesis who are not in my original file and that you show in your
   explanations… might miss something…
 * So with this complete file, i think i’ll not have any other errors…
 * Thank’s for your help as i need this asap.
 * Stephane
 *  [stheoret](https://wordpress.org/support/users/stheoret/)
 * (@stheoret)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/background-image-32/#post-3361790)
 * Forget about my demand !
 * I have now the BACKGROUND IMAGE in the PDF !!!
 * I needed to use the updated package 2.3.6.
 * Everything is perfect now!
 * Thank you man for that precious coding!!!
 * Stephane
 *  Thread Starter [Twanneman](https://wordpress.org/support/users/twanneman/)
 * (@twanneman)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/background-image-32/#post-3361791)
 * No problem! I’m glad you solved it!

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘background-image’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/wp-post-to-pdf_f197af.svg)
 * [WP Post to PDF](https://wordpress.org/plugins/wp-post-to-pdf/)
 * [Support Threads](https://wordpress.org/support/plugin/wp-post-to-pdf/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-post-to-pdf/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-post-to-pdf/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-post-to-pdf/reviews/)

 * 4 replies
 * 2 participants
 * Last reply from: [Twanneman](https://wordpress.org/support/users/twanneman/)
 * Last activity: [12 years, 9 months ago](https://wordpress.org/support/topic/background-image-32/#post-3361791)
 * Status: resolved