Examples

Here is our list of ready to run examples. Once you have downloaded the phpToPDF.php API you can download (or copy and paste) and run any of the following examples.

Basic Examples   -   Quick and easy to get you started
     •   Create PDF from a URL and save it to your server
     •   Create a Landscape & Black and White PDF from a URL and view it
     •   Create an A5 paper size PDF from a URL and download it

     •   Create PDF from HTML and save it to your server
     •   Create a Landscape & Black and White PDF from HTML and view it
     •   Create an A5 paper size PDF from HTML and download it

     •   Include a simple footer with page numbers

Real World Examples   -   Common situations and how to approach them using phpToPDF
     •   Generate a PDF invoice
     •   Create individual timesheet PDFs for all employees in your database
     •   Generate a PDF from an internal web-page (intranet) such as http://192.168.1.105/page.html
     •   Create a printer friendly PDF of an article (no images, black and white)
     •   Create an analytics report with a header, footer, and page numbers
     •   Create A Report With Page Breaks

Legacy Examples   -   The original (and still supported) 'simple' phpToPDF functions
     •   Save a PDF to your server from a URL
     •   Save a PDF to your server from HTML

Basic Examples   -   Quick and easy to get you started

Create PDF from a URL and save it to your server

We generate a PDF from a website (url) (http://google.com) and save it to the current directory on your server ('' = current directory). The PDF name will be 'url_google.pdf'.
We then display a link to that newly generated PDF.

Source Code:   [Login to Download]

Having Trouble Saving?     The 'save_directory' option must point to a WRITABLE directory.   [?]

You may also need to change the 'save_directory' to a full path and edit the 'a href download' link location
Example:     "save_directory" => '/var/www/html/ptp/examples'     and     href="/ptp/examples/...

<?php
 
// INCLUDE THE phpToPDF.php FILE
require("phpToPDF.php"); 

// SET YOUR PDF OPTIONS
// FOR ALL AVAILABLE OPTIONS, VISIT HERE:  http://phptopdf.com/documentation/
$pdf_options = array(
  
"source_type" => 'url',
  
"source" => 'http://google.com',
  
"action" => 'save',
  
"save_directory" => '',
  
"file_name" => 'url_google.pdf');

// CALL THE phptopdf FUNCTION WITH THE OPTIONS SET ABOVE
phptopdf($pdf_options);

// OPTIONAL - PUT A LINK TO DOWNLOAD THE PDF YOU JUST CREATED
echo ("<a href='url_google.pdf'>Download Your PDF</a>");
?>




Create a Landscape & Black and White PDF from a URL and view it

We generate a Black & White (monochrome) landscape PDF from a website (url) (http://slashdot.org/) and display it (view).

Source Code:   [Login to Download]

<?php
 
// INCLUDE THE phpToPDF.php FILE
require("phpToPDF.php"); 

// SET YOUR PDF OPTIONS -- FOR ALL AVAILABLE OPTIONS, VISIT HERE:  http://phptopdf.com/documentation/
$pdf_options = array(
  
"source_type" => 'url',
  
"source" => 'http://slashdot.org/',
  
"action" => 'view',
  
"color" => 'monochrome',
  
"page_orientation" => 'landscape');

// CALL THE phpToPDF FUNCTION WITH THE OPTIONS SET ABOVE
phptopdf($pdf_options);

?>




Create an A5 paper size PDF from a URL and download it

We generate an 'A5' sized PDF from a website (url) (http://fifa.com) and have it downloaded (download). The PDF name will be 'url_fifa_A5.pdf'.

Source Code:   [Login to Download]

<?php
 
// INCLUDE THE phpToPDF.php FILE
require("phpToPDF.php"); 

// SET YOUR PDF OPTIONS -- FOR ALL AVAILABLE OPTIONS, VISIT HERE:  http://phptopdf.com/documentation/
$pdf_options = array(
  
"source_type" => 'url',
  
"source" => 'http://fifa.com',
  
"action" => 'download',
  
"page_size" => 'A5',
  
"file_name" => 'url_fifa_A5.pdf');

// CALL THE phpToPDF FUNCTION WITH THE OPTIONS SET ABOVE
phptopdf($pdf_options);

?>




Create PDF from HTML and save it to your server

We generate a PDF from HTML (stored in $my_html variable) and save it to the current directory on your server ('' = current directory). The PDF name will be 'html_01.pdf'.
We then display a link to that newly generated PDF.

Source Code:   [Login to Download]

Having Trouble Saving?     The 'save_directory' option must point to a WRITABLE directory.   [?]

You may also need to change the 'save_directory' to a full path and edit the 'a href download' link location
Example:     "save_directory" => '/var/www/html/ptp/examples'     and     href="/ptp/examples/...

<?php
 
// INCLUDE THE phpToPDF.php FILE
require("phpToPDF.php"); 

// PUT YOUR HTML IN A VARIABLE
$my_html="<HTML>
<h2>Test HTML 01</h2><br><br>
<div style=\"display:block; padding:20px; border:2pt solid:#FE9A2E; background-color:#F6E3CE; font-weight:bold;\">
phpToPDF is pretty cool!
</div><br><br>
For more examples, visit us here --> http://phptopdf.com/examples/
</HTML>"
;

// SET YOUR PDF OPTIONS
// FOR ALL AVAILABLE OPTIONS, VISIT HERE:  http://phptopdf.com/documentation/
$pdf_options = array(
  
"source_type" => 'html',
  
"source" => $my_html,
  
"action" => 'save',
  
"save_directory" => '',
  
"file_name" => 'html_01.pdf');

// CALL THE phpToPDF FUNCTION WITH THE OPTIONS SET ABOVE
phptopdf($pdf_options);

// OPTIONAL - PUT A LINK TO DOWNLOAD THE PDF YOU JUST CREATED
echo ("<a href='html_01.pdf'>Download Your PDF</a>");
?>




Create a Landscape & Black and White PDF from HTML and view it

We generate a Black & White (monochrome) landscape PDF from (html) and display it (view).

Source Code:   [Login to Download]

<?php
 
// INCLUDE THE phpToPDF.php FILE
require("phpToPDF.php"); 

// PUT YOUR HTML IN A VARIABLE
$my_html="<HTML>
<h2>Test HTML 02</h2><br><br>
<div style=\"display:block; padding:20px; border:2pt solid:#FE9A2E; background-color:#F6E3CE; font-weight:bold;\">
phpToPDF is pretty cool! <br><br>
[This was orange, but I set the PDF option to monochrome (Black & White)]
</div><br><br>
For more examples, visit us here --> http://phptopdf.com/examples/
</HTML>"
;

// SET YOUR PDF OPTIONS -- FOR ALL AVAILABLE OPTIONS, VISIT HERE:  http://phptopdf.com/documentation/
$pdf_options = array(
  
"source_type" => 'html',
  
"source" => $my_html,
  
"action" => 'view',
  
"color" => 'monochrome',
  
"page_orientation" => 'landscape');

// CALL THE phpToPDF FUNCTION WITH THE OPTIONS SET ABOVE
phptopdf($pdf_options);

?>




Create an A5 paper size PDF from a URL and download it

We generate an 'A5' sized PDF from (html) and display it (view). The PDF name will be 'html_03.pdf'.

Source Code:   [Login to Download]

<?php
 
// INCLUDE THE phpToPDF.php FILE
require("phpToPDF.php"); 

// PUT YOUR HTML IN A VARIABLE
$my_html="<HTML>
<h2>Test HTML 03</h2><br><br>
<div style=\"display:block; padding:20px; border:2pt solid:#FE9A2E; background-color:#F6E3CE; font-weight:bold;\">
phpToPDF is pretty cool! <br><br>
Now this paper size is 'A5'.  It can be any paper-size!
</div><br><br>
For more examples, visit us here --> http://phptopdf.com/examples/
</HTML>"
;

// SET YOUR PDF OPTIONS -- FOR ALL AVAILABLE OPTIONS, VISIT HERE:  http://phptopdf.com/documentation/
$pdf_options = array(
  
"source_type" => 'html',
  
"source" => $my_html,
  
"action" => 'download',
  
"file_name" => 'html_03.pdf',
  
"page_size" => 'A5');

// CALL THE phpToPDF FUNCTION WITH THE OPTIONS SET ABOVE
phptopdf($pdf_options);

?>




Include a simple footer with page numbers

We generate PDF from (html) and include a simple footer with page numbers and save it to the current directory on your server ('' = current directory). The PDF name will be 'simple_page_nums.pdf'.

Source Code:   [Login to Download]

Having Trouble Saving?     The 'save_directory' option must point to a WRITABLE directory.   [?]

You may also need to change the 'save_directory' to a full path and edit the 'a href download' link location
Example:     "save_directory" => '/var/www/html/ptp/examples'     and     href="/ptp/examples/...

<?php
 
// INCLUDE THE phpToPDF.php FILE
require("phpToPDF.php"); 

// PUT YOUR HTML IN A VARIABLE -- I fill this up with text to take up about 4 pages
$my_html="<HTML>
<h2>phpToPDF - Page Numbers In Footer</h2><br><br>
<div style=\"display:block; padding:20px; border:2pt solid:#FE9A2E; background-color:#F6E3CE;\">
In our PDF Options array, we set: &nbsp; &nbsp; <xmp>footer => 'Page phptopdf_on_page_number of phptopdf_pages_total'</xmp><br><br>
Read More Here: &nbsp; &nbsp; &nbsp; http://phptopdf.com/documentation/#page_numbers
</div><br><br>
For more examples, visit us here --> http://phptopdf.com/examples/ <br><br><br><br><br>
<div style=\"margin:750px 0px 750px 0px;\">Lorem ipsum dolor sit amet</div>
<div style=\"margin:750px 0px 750px 0px;\">Lorem ipsum dolor sit amet</div>
<div style=\"margin:750px 0px 750px 0px;\">Lorem ipsum dolor sit amet</div>
<div style=\"margin:750px 0px 750px 0px;\">Lorem ipsum dolor sit amet</div>
<div style=\"margin:750px 0px 750px 0px;\">Lorem ipsum dolor sit amet</div>
<div style=\"margin:750px 0px 750px 0px;\">Lorem ipsum dolor sit amet</div>
<div style=\"margin:750px 0px 750px 0px;\">Lorem ipsum dolor sit amet</div>
</HTML>"
;

// SET YOUR PDF OPTIONS
// FOR ALL AVAILABLE OPTIONS, VISIT HERE:  http://phptopdf.com/documentation/
$pdf_options = array(
  
"source_type" => 'html',
  
"source" => $my_html,
  
"footer" => 'Page phptopdf_on_page_number of phptopdf_pages_total',
  
"action" => 'save',
  
"save_directory" => '',
  
"file_name" => 'simple_page_nums.pdf');

// CALL THE phpToPDF FUNCTION WITH THE OPTIONS SET ABOVE
phptopdf($pdf_options);

// OPTIONAL - PUT A LINK TO DOWNLOAD THE PDF YOU JUST CREATED
echo ("<a href='simple_page_nums.pdf'>Download Your PDF</a>");
?>




Real World Examples   -   Common situations and how to approach them using phpToPDF

Generate a PDF invoice

We generate a PDF invoice (html source) and save it to the current directory on your server ('' = current directory). The PDF name will be 'pdf_invoice.pdf'.
We then display a link to that newly generated PDF.

Source Code:   [Login to Download]

Having Trouble Saving?     The 'save_directory' option must point to a WRITABLE directory.   [?]

You may also need to change the 'save_directory' to a full path and edit the 'a href download' link location
Example:     "save_directory" => '/var/www/html/ptp/examples'     and     href="/ptp/examples/...

<?php
 
// INCLUDE THE phpToPDF.php FILE
require("phpToPDF.php"); 

// PUT YOUR HTML IN A VARIABLE
$my_html="<html lang=\"en\">
  <head>
    <meta charset=\"UTF-8\">
    <title>Sample Invoice</title>
    <link rel=\"stylesheet\" href=\"http://phptopdf.com/bootstrap.css\">
    <style>
      @import url(http://fonts.googleapis.com/css?family=Bree+Serif);
      body, h1, h2, h3, h4, h5, h6{
      font-family: 'Bree Serif', serif;
      }
    </style>
  </head>
  
  <body>
    <div class=\"container\">
      <div class=\"row\">
        <div class=\"col-xs-6\">
          <h1>
            <a href=\"http://phptopdf.com\">            
            Logo here
            </a>
          </h1>
        </div>
        <div class=\"col-xs-6 text-right\">
          <h1>INVOICE</h1>
          <h1><small>Invoice #001</small></h1>
        </div>
      </div>
      <div class=\"row\">
        <div class=\"col-xs-5\">
          <div class=\"panel panel-default\">
            <div class=\"panel-heading\">
              <h4>From: <a href=\"#\">Your Name</a></h4>
            </div>
            <div class=\"panel-body\">
              <p>
                Address <br>
                details <br>
                more <br>
              </p>
            </div>
          </div>
        </div>
        <div class=\"col-xs-5 col-xs-offset-2 text-right\">
          <div class=\"panel panel-default\">
            <div class=\"panel-heading\">
              <h4>To : <a href=\"#\">Client Name</a></h4>
            </div>
            <div class=\"panel-body\">
              <p>
                Address <br>
                details <br>
                more <br>
              </p>
            </div>
          </div>
        </div>
      </div>
      <!-- / end client details section -->
      <table class=\"table table-bordered\">
        <thead>
          <tr>
            <th>
              <h4>Service</h4>
            </th>
            <th>
              <h4>Description</h4>
            </th>
            <th>
              <h4>Hrs/Qty</h4>
            </th>
            <th>
              <h4>Rate/Price</h4>
            </th>
            <th>
              <h4>Sub Total</h4>
            </th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td>Article</td>
            <td><a href=\"#\">Title of your article here</a></td>
            <td class=\"text-right\">-</td>
            <td class=\"text-right\">$200.00</td>
            <td class=\"text-right\">$200.00</td>
          </tr>
          <tr>
            <td>Template Design</td>
            <td><a href=\"#\">Details of project here</a></td>
            <td class=\"text-right\">10</td>
            <td class=\"text-right\">75.00</td>
            <td class=\"text-right\">$750.00</td>
          </tr>
          <tr>
            <td>Development</td>
            <td><a href=\"#\">WordPress Blogging theme</a></td>
            <td class=\"text-right\">5</td>
            <td class=\"text-right\">50.00</td>
            <td class=\"text-right\">$250.00</td>
          </tr>
        </tbody>
      </table>
      <div class=\"row text-right\">
        <div class=\"col-xs-2 col-xs-offset-8\">
          <p>
            <strong>
            Sub Total : <br>
            TAX : <br>
            Total : <br>
            </strong>
          </p>
        </div>
        <div class=\"col-xs-2\">
          <strong>
          $1200.00 <br>
          N/A <br>
          $1200.00 <br>
          </strong>
        </div>
      </div>
      <div class=\"row\">
        <div class=\"col-xs-5\">
          <div class=\"panel panel-info\">
            <div class=\"panel-heading\">
              <h4>Bank details</h4>
            </div>
            <div class=\"panel-body\">
              <p>Your Name</p>
              <p>Bank Name</p>
              <p>SWIFT : --------</p>
              <p>Account Number : --------</p>
              <p>IBAN : --------</p>
            </div>
          </div>
        </div>
        <div class=\"col-xs-7\">
          <div class=\"span7\">
            <div class=\"panel panel-info\">
              <div class=\"panel-heading\">
                <h4>Contact Details</h4>
              </div>
              <div class=\"panel-body\">
                <p>
                  Email : you@example.com <br><br>
                  Mobile : -------- <br><br><br>
                </p>
                <h4>Payment should be made by Bank Transfer</h4>
              </div>
            </div>
          </div>
        </div>
      </div>
      <br><br>
      This is a sample invoice.<br><br>
      In this example the css style is pulled from phptopdf.com/bootstrap.css
      You could also put all CSS in the header wrapped in <xmp> < style > </xmp> tags
    </div>
  </body>
</html>"
;

// SET YOUR PDF OPTIONS -- FOR ALL AVAILABLE OPTIONS, VISIT HERE:  http://phptopdf.com/documentation/
$pdf_options = array(
  
"source_type" => 'html',
  
"source" => $my_html,
  
"action" => 'save',
  
"save_directory" => '',
  
"file_name" => 'pdf_invoice.pdf');

// CALL THE phpToPDF FUNCTION WITH THE OPTIONS SET ABOVE
phptopdf($pdf_options);

// OPTIONAL - PUT A LINK TO DOWNLOAD THE PDF YOU JUST CREATED
echo ("<a href='pdf_invoice.pdf'>Download Your PDF</a>");
?>




Create individual timesheet PDFs for all employees in your database

We generate a PDF timesheets for each of the employees in our array. In a real situation, you would gather your array data from a database. We generate each timesheet PDF based on dynamic data (html source) and save it to the current directory on your server ('' = current directory). The PDF names will be 'pdf_timesheet_bob_green.pdf', 'pdf_timesheet_james_red.pdf', etc.
We then display a link to the newly generated PDFs.

Source Code:   [Login to Download]

Having Trouble Saving?     The 'save_directory' option must point to a WRITABLE directory.   [?]

You may also need to change the 'save_directory' to a full path and edit the 'a href download' link location
Example:     "save_directory" => '/var/www/html/ptp/examples'     and     href="/ptp/examples/...

<?php
 
// INCLUDE THE phpToPDF.php FILE
require("phpToPDF.php"); 


///////////////////////////////////////////////////////////////////
// SAMPLE DATA -- YOU WOULD SELECT DATA FROM YOUR DATABASE HERE
// MySQL, etc --> SELECT * FROM EMPLOYEES....
$employees =   array( array( id => 1
                             
name => "James Red",
                             
hours => 36,
                             
rate => 12.25
                            ),
                     array( 
id => 2
                            
name => "Bob Green",
                            
hours => 25,                            
                            
rate => 14.00,
                          ),
                     array( 
id => 3
                            
name => "Mark Yellow",
                            
hours => 12,
                            
rate => 8.50,
                          ),
                     array( 
id => 4
                            
name => "Kevin Blue",
                            
hours => 38,
                            
rate => 24.00,
                          ),
                     array( 
id => 5
                            
name => "Mike Pink",
                            
hours => 40,
                            
rate => 16.00,
                          ),
                     array( 
id => 6
                            
name => "John White",
                            
hours => 29,
                            
rate => 9.25,
                          ),                                                                         
             );
///////////////////////////////////////////////////////////////////





$pdf_download_links="";





///////////////////////////////////////////////////////////////////
// LOOP THROUGH EACH RECORD AND CREATE INDIVIDUAL PDF FOR EACH
//
// EACH PDF WILL BE SAVED AS pdf_timesheet_$name.pdf
//
foreach ($employees as $row) {
    
// GATHER THE VARIABLES
    
$on_id=$row['id'];
    
$on_name=$row['name'];
    
$on_hours=$row['hours'];
    
$on_rate=number_format($row['rate'], 2'.'',');
    
/////////////////////////
    
$on_total_pay=number_format($on_hours*$on_rate2'.'',');
    
$on_safe_name=strtolower(str_replace(' ''_'$on_name));
    
$on_filename="pdf_timesheet_$on_safe_name.pdf";





    
// PUT YOUR HTML IN A VARIABLE
    
$my_html="<html lang=\"en\">
      <head>
        <meta charset=\"UTF-8\">
        <title>Sample Invoice</title>
        <link rel=\"stylesheet\" href=\"http://phptopdf.com/bootstrap.css\">
        <style>
          @import url(http://fonts.googleapis.com/css?family=Bree+Serif);
          body, h1, h2, h3, h4, h5, h6{
          font-family: 'Bree Serif', serif;
          }
        </style>
      </head>
      
      <body>
        <div class=\"container\">
          <div class=\"row\">
            <div class=\"col-xs-6\">
              <h1>
                <a href=\"http://phptopdf.com\">            
                Logo here
                </a>
              </h1>
            </div>
            <div class=\"col-xs-6 text-right\">
              <h1>Timesheet</h1>
              <h1><small>Week Of Jan 01 - Jan 07</small></h1>
            </div>
          </div>
          <div class=\"row\">
            <div class=\"col-xs-5\">
              <div class=\"panel panel-default\">
                <div class=\"panel-heading\">
                  <h4>For: &nbsp; <a href=\"#\">
$on_name</a></h4>
                </div>
                <div class=\"panel-body\">
                  <p>
                  </p>
                </div>
              </div>
            </div>
            <div class=\"col-xs-5 col-xs-offset-2 text-right\">
              <!-- <div class=\"panel panel-default\">
                <div class=\"panel-heading\">
                  <h4>To : <a href=\"#\">Client Name</a></h4>
                </div>
                <div class=\"panel-body\">
                  <p>
                    Address <br>
                    details <br>
                    more <br>
                  </p>
                </div>
              </div> -->
            </div>
          </div>
          <!-- / end client details section -->
          <table class=\"table table-bordered\">
            <thead>
              <tr>
                <th class=\"text-center\">
                  <h4>Hours</h4>
                </th>
                <th class=\"text-center\">
                  <h4>Rate</h4>
                </th>
                <th class=\"text-center\">
                  <h4>Total</h4>
                </th>
              </tr>
            </thead>
            <tbody>
              <tr>
                <td class=\"text-right\">
$on_hours</td>
                <td class=\"text-right\">
$on_rate</td>
                <td class=\"text-right\">
$on_total_pay</td>
              </tr>
            </tbody>
          </table>
          </div>
          <br><br>
          This is a sample timesheet.  An indivdual timesheet is created for each employee (6 in this example).<br><br>
          In this example the css style is pulled from phptopdf.com/bootstrap.css
          You could also put all CSS in the header wrapped in <xmp> < style > </xmp> tags
        </div>
      </body>
    </html>"
;







// SET YOUR PDF OPTIONS -- FOR ALL AVAILABLE OPTIONS, VISIT HERE:  http://phptopdf.com/documentation/
$pdf_options = array(
  
"source_type" => 'html',
  
"source" => $my_html,
  
"action" => 'save',
  
"save_directory" => '',
  
"file_name" => $on_filename);

// CALL THE phpToPDF FUNCTION WITH THE OPTIONS SET ABOVE
phptopdf($pdf_options);





$pdf_download_links.="<a href='$on_filename'>Download Timesheet For:  $on_name</a><br><br>";
}





// OPTIONAL - PUT A LINK TO DOWNLOAD THE PDFs YOU JUST CREATED
echo ("<h2>Download Timesheets</h2>$pdf_download_links");
?>




Generate a PDF from an internal web-page (intranet) such as http://192.168.1.105/page.html

This demonstrates the ability to generate a PDF from a local LAN only webpage. First we need to get the contents of the LAN page into html using 1 of 2 methods - either cURL or file_get_contents.
Then we generate a PDF from that HTML now in a $my_html variable. We then display a link to the newly generated PDFs.

Source Code:   [Login to Download]

Having Trouble Saving?     The 'save_directory' option must point to a WRITABLE directory.   [?]

You may also need to change the 'save_directory' to a full path and edit the 'a href download' link location
Example:     "save_directory" => '/var/www/html/ptp/examples'     and     href="/ptp/examples/...

<?php
 
// INCLUDE THE phpToPDF.php FILE
require("phpToPDF.php"); 


 
// SINCE AN INTERNAL / LAN WEBPAGE IS NOT ABLE TO BE ACCESSED FROM phptopdf.com
 // THE STANDARD source_type => URL, source => http://192.168.1.1/page.html WILL NOT WORK.  
 // YOU WILL NEED TO USE THE HTML source_type AFTER GETTING YOUR INTERNAL / LAN PAGE
 // INTO AN HTML VARIABLE.   THERE ARE TWO METHODS TO DO THIS.  AT LEAST 1 SHOULD WORK FOR YOU.

 // If you are having a problem, turn this setting in your php.ini to on (1).   allow_url_fopen = 1




// CHANGE THIS TO YOUR INTERNAL URL LIKE http://192.168.1.1/page.html
 
$internal_url 'http://17.178.96.59';
 




 
// UNCOMMENT / COMMENT AS NEEDED TO TOGGLE BETWEEN THE TWO METHODS


 // METHOD 1 [using file_get_contents]
    
$my_html file_get_contents($internal_url);
    
//die("<xmp>$my_html</xmp>");  // uncomment this to test the result of file_get_contents



    
 // METHOD 2 [using cURL]
/*    
    $ch = curl_init($internal_url);  
    curl_setopt($ch, CURLOPT_HEADER, 0);  
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  
    $my_html = curl_exec($ch);
    //die("<xmp>$my_html</xmp>");   // uncomment this to test the result of cURL
*/


// SET YOUR PDF OPTIONS -- FOR ALL AVAILABLE OPTIONS, VISIT HERE:  http://phptopdf.com/documentation/
$pdf_options = array(
  
"source_type" => 'html',
  
"source" => $my_html,
  
"action" => 'save',
  
"save_directory" => '',
  
"file_name" => 'internal_LAN.pdf');

// CALL THE phpToPDF FUNCTION WITH THE OPTIONS SET ABOVE
phptopdf($pdf_options);

// OPTIONAL - PUT A LINK TO DOWNLOAD THE PDF YOU JUST CREATED
echo ("<a href='internal_LAN.pdf'>Download Your PDF</a>");
?>




Create a printer friendly PDF of an article (no images, black and white)

We generate a black and white (monochrome) PDF with no images (omit_images) from a website (url) and save it to the current directory on your server ('' = current directory). The PDF name will be 'printer_friendly.pdf'.
We then display a link to that newly generated PDF.

Source Code:   [Login to Download]

Having Trouble Saving?     The 'save_directory' option must point to a WRITABLE directory.   [?]

You may also need to change the 'save_directory' to a full path and edit the 'a href download' link location
Example:     "save_directory" => '/var/www/html/ptp/examples'     and     href="/ptp/examples/...

<?php
 
// INCLUDE THE phpToPDF.php FILE
require("phpToPDF.php"); 

// SET YOUR PDF OPTIONS -- FOR ALL AVAILABLE OPTIONS, VISIT HERE:  http://phptopdf.com/documentation/
$pdf_options = array(
  
"source_type" => 'url',
  
"source" => 'http://aeon.co/magazine/nature-and-cosmos/why-is-einstein-the-poster-boy-for-genius/',
  
"action" => 'save',
  
"save_directory" => '',
  
"file_name" => 'printer_friendly.pdf',
  
"color" => 'monochrome',
  
"omit_images" => 'yes');

// CALL THE phpToPDF FUNCTION WITH THE OPTIONS SET ABOVE
phptopdf($pdf_options);

// OPTIONAL - PUT A LINK TO DOWNLOAD THE PDF YOU JUST CREATED
echo ("<a href='printer_friendly.pdf'>Download Your PDF</a>");
?>




Create an analytics report with a header, footer, and page numbers

This shows how to use a header and a footer with page numbers.
We have our report in an html variable. We then also have our header and footers in variables as well.
The header includes a logo image as well as text.; the footer simply shows the Page # of # Pages.
All headers and footers can be simple text or fully customizable using HTML.
We then save it to the current directory on your server ('' = current directory).

You can include page numbers anywhere in the header or footer using these two text variables:
phptopdf_on_page_number   &   phptopdf_pages_total   Read More About Page Numbers Here

Source Code:   [Login to Download]

Having Trouble Saving?     The 'save_directory' option must point to a WRITABLE directory.   [?]

You may also need to change the 'save_directory' to a full path and edit the 'a href download' link location
Example:     "save_directory" => '/var/www/html/ptp/examples'     and     href="/ptp/examples/...

<?php
 
// INCLUDE THE phpToPDF.php FILE
require("phpToPDF.php"); 

// PUT YOUR HTML IN A VARIABLE
$my_html "<html>
<head>
<link href=\"http://phptopdf.com/bootstrap.css\" rel=\"stylesheet\">
<link href=\"http://getbootstrap.com/examples/dashboard/dashboard.css\" rel=\"stylesheet\">
 <script type=\"text/javascript\" src=\"https://www.google.com/jsapi\"></script>
    <script type=\"text/javascript\">
      google.load('visualization', '1.0', {'packages':['corechart']});
      google.setOnLoadCallback(drawChart);

      function drawChart() {
        var data = new google.visualization.DataTable();
        data.addColumn('string', 'Topping');
        data.addColumn('number', 'Slices');
        data.addRows([
          ['Selection 1', 3],
          ['Selection 2', 1],
          ['Selection 3', 1],
          ['Selection 4', 1],
          ['Selection 5', 2]
        ]);

        var options = {'title':'Example Chart',
                       'width':800,
                       'height':600};

        var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
        chart.draw(data, options);
      }
    </script>    
</head>
<body>

 <div class=\"container-fluid\">
      <div class=\"row\">
        <div class=\"main\">
          <h1>Example Report</h1>
          <h3>with Page Numbers, Header and Footer - phpToPDF.com</h3>
          <br><br><br>
          <p>This is an example cover page</p>
      </div>
    </div>
  </div>
  
  <div style=\"display:block; height:850px;\">
      <br><br>
    </div>  

<h1 class=\"page-header\">This is an example table for this report</h1>
<h2 class=\"sub-header\">Example Table</h2>
<table class=\"table table-striped\">
              <thead>
                <tr>
                  <th>#</th>
                  <th>Header</th>
                  <th>Header</th>
                  <th>Header</th>
                  <th>Header</th>
                </tr>
              </thead>
              <tbody>
                <tr>
                  <td>1,001</td>
                  <td>Lorem</td>
                  <td>ipsum</td>
                  <td>dolor</td>
                  <td>sit</td>
                </tr>
                <tr>
                  <td>1,002</td>
                  <td>amet</td>
                  <td>consectetur</td>
                  <td>adipiscing</td>
                  <td>elit</td>
                </tr>
                <tr>
                  <td>1,003</td>
                  <td>Integer</td>
                  <td>nec</td>
                  <td>odio</td>
                  <td>Praesent</td>
                </tr>
                <tr>
                  <td>1,003</td>
                  <td>libero</td>
                  <td>Sed</td>
                  <td>cursus</td>
                  <td>ante</td>
                </tr>
                <tr>
                  <td>1,004</td>
                  <td>dapibus</td>
                  <td>diam</td>
                  <td>Sed</td>
                  <td>nisi</td>
                </tr>
                <tr>
                  <td>1,005</td>
                  <td>Nulla</td>
                  <td>quis</td>
                  <td>sem</td>
                  <td>at</td>
                </tr>
                <tr>
                  <td>1,006</td>
                  <td>nibh</td>
                  <td>elementum</td>
                  <td>imperdiet</td>
                  <td>Duis</td>
                </tr>
                <tr>
                  <td>1,007</td>
                  <td>sagittis</td>
                  <td>ipsum</td>
                  <td>Praesent</td>
                  <td>mauris</td>
                </tr>
                <tr>
                  <td>1,008</td>
                  <td>Fusce</td>
                  <td>nec</td>
                  <td>tellus</td>
                  <td>sed</td>
                </tr>
                <tr>
                  <td>1,009</td>
                  <td>augue</td>
                  <td>semper</td>
                  <td>porta</td>
                  <td>Mauris</td>
                </tr>
                <tr>
                  <td>1,010</td>
                  <td>massa</td>
                  <td>Vestibulum</td>
                  <td>lacinia</td>
                  <td>arcu</td>
                </tr>
                <tr>
                  <td>1,011</td>
                  <td>eget</td>
                  <td>nulla</td>
                  <td>Class</td>
                  <td>aptent</td>
                </tr>
                <tr>
                  <td>1,012</td>
                  <td>taciti</td>
                  <td>sociosqu</td>
                  <td>ad</td>
                  <td>litora</td>
                </tr>
                <tr>
                  <td>1,013</td>
                  <td>torquent</td>
                  <td>per</td>
                  <td>conubia</td>
                  <td>nostra</td>
                </tr>
                <tr>
                  <td>1,014</td>
                  <td>per</td>
                  <td>inceptos</td>
                  <td>himenaeos</td>
                  <td>Curabitur</td>
                </tr>
                <tr>
                  <td>1,015</td>
                  <td>sodales</td>
                  <td>ligula</td>
                  <td>in</td>
                  <td>libero</td>
                </tr>
         <tr>
                  <td>1,001</td>
                  <td>Lorem</td>
                  <td>ipsum</td>
                  <td>dolor</td>
                  <td>sit</td>
                </tr>
                <tr>
                  <td>1,002</td>
                  <td>amet</td>
                  <td>consectetur</td>
                  <td>adipiscing</td>
                  <td>elit</td>
                </tr>
                <tr>
                  <td>1,003</td>
                  <td>Integer</td>
                  <td>nec</td>
                  <td>odio</td>
                  <td>Praesent</td>
                </tr>
                <tr>
                  <td>1,003</td>
                  <td>libero</td>
                  <td>Sed</td>
                  <td>cursus</td>
                  <td>ante</td>
                </tr>
                <tr>
                  <td>1,004</td>
                  <td>dapibus</td>
                  <td>diam</td>
                  <td>Sed</td>
                  <td>nisi</td>
                </tr>
                <tr>
                  <td>1,005</td>
                  <td>Nulla</td>
                  <td>quis</td>
                  <td>sem</td>
                  <td>at</td>
                </tr>
                <tr>
                  <td>1,006</td>
                  <td>nibh</td>
                  <td>elementum</td>
                  <td>imperdiet</td>
                  <td>Duis</td>
                </tr>
                <tr>
                  <td>1,007</td>
                  <td>sagittis</td>
                  <td>ipsum</td>
                  <td>Praesent</td>
                  <td>mauris</td>
                </tr>
                <tr>
                  <td>1,008</td>
                  <td>Fusce</td>
                  <td>nec</td>
                  <td>tellus</td>
                  <td>sed</td>
                </tr>
                <tr>
                  <td>1,009</td>
                  <td>augue</td>
                  <td>semper</td>
                  <td>porta</td>
                  <td>Mauris</td>
                </tr>
                <tr>
                  <td>1,010</td>
                  <td>massa</td>
                  <td>Vestibulum</td>
                  <td>lacinia</td>
                  <td>arcu</td>
                </tr>
                <tr>
                  <td>1,011</td>
                  <td>eget</td>
                  <td>nulla</td>
                  <td>Class</td>
                  <td>aptent</td>
                </tr>
                <tr>
                  <td>1,012</td>
                  <td>taciti</td>
                  <td>sociosqu</td>
                  <td>ad</td>
                  <td>litora</td>
                </tr>
                <tr>
                  <td>1,013</td>
                  <td>torquent</td>
                  <td>per</td>
                  <td>conubia</td>
                  <td>nostra</td>
                </tr>
                <tr>
                  <td>1,014</td>
                  <td>per</td>
                  <td>inceptos</td>
                  <td>himenaeos</td>
                  <td>Curabitur</td>
                </tr>
                <tr>
                  <td>1,015</td>
                  <td>sodales</td>
                  <td>ligula</td>
                  <td>in</td>
                  <td>libero</td>
                </tr>
         <tr>
                  <td>1,001</td>
                  <td>Lorem</td>
                  <td>ipsum</td>
                  <td>dolor</td>
                  <td>sit</td>
                </tr>
                <tr>
                  <td>1,002</td>
                  <td>amet</td>
                  <td>consectetur</td>
                  <td>adipiscing</td>
                  <td>elit</td>
                </tr>
                <tr>
                  <td>1,003</td>
                  <td>Integer</td>
                  <td>nec</td>
                  <td>odio</td>
                  <td>Praesent</td>
                </tr>
                <tr>
                  <td>1,003</td>
                  <td>libero</td>
                  <td>Sed</td>
                  <td>cursus</td>
                  <td>ante</td>
                </tr>
                <tr>
                  <td>1,004</td>
                  <td>dapibus</td>
                  <td>diam</td>
                  <td>Sed</td>
                  <td>nisi</td>
                </tr>
                <tr>
                  <td>1,005</td>
                  <td>Nulla</td>
                  <td>quis</td>
                  <td>sem</td>
                  <td>at</td>
                </tr>
                <tr>
                  <td>1,006</td>
                  <td>nibh</td>
                  <td>elementum</td>
                  <td>imperdiet</td>
                  <td>Duis</td>
                </tr>
                <tr>
                  <td>1,007</td>
                  <td>sagittis</td>
                  <td>ipsum</td>
                  <td>Praesent</td>
                  <td>mauris</td>
                </tr>
                <tr>
                  <td>1,008</td>
                  <td>Fusce</td>
                  <td>nec</td>
                  <td>tellus</td>
                  <td>sed</td>
                </tr>
                <tr>
                  <td>1,009</td>
                  <td>augue</td>
                  <td>semper</td>
                  <td>porta</td>
                  <td>Mauris</td>
                </tr>
                <tr>
                  <td>1,010</td>
                  <td>massa</td>
                  <td>Vestibulum</td>
                  <td>lacinia</td>
                  <td>arcu</td>
                </tr>
                <tr>
                  <td>1,011</td>
                  <td>eget</td>
                  <td>nulla</td>
                  <td>Class</td>
                  <td>aptent</td>
                </tr>
                <tr>
                  <td>1,012</td>
                  <td>taciti</td>
                  <td>sociosqu</td>
                  <td>ad</td>
                  <td>litora</td>
                </tr>
                <tr>
                  <td>1,013</td>
                  <td>torquent</td>
                  <td>per</td>
                  <td>conubia</td>
                  <td>nostra</td>
                </tr>
                <tr>
                  <td>1,014</td>
                  <td>per</td>
                  <td>inceptos</td>
                  <td>himenaeos</td>
                  <td>Curabitur</td>
                </tr>
                <tr>
                  <td>1,015</td>
                  <td>sodales</td>
                  <td>ligula</td>
                  <td>in</td>
                  <td>libero</td>
                </tr>
        <tr>
                  <td>1,007</td>
                  <td>sagittis</td>
                  <td>ipsum</td>
                  <td>Praesent</td>
                  <td>mauris</td>
                </tr>
                <tr>
                  <td>1,008</td>
                  <td>Fusce</td>
                  <td>nec</td>
                  <td>tellus</td>
                  <td>sed</td>
                </tr>
                <tr>
                  <td>1,009</td>
                  <td>augue</td>
                  <td>semper</td>
                  <td>porta</td>
                  <td>Mauris</td>
                </tr>
                <tr>
                  <td>1,010</td>
                  <td>massa</td>
                  <td>Vestibulum</td>
                  <td>lacinia</td>
                  <td>arcu</td>
                </tr>
                <tr>
                  <td>1,011</td>
                  <td>eget</td>
                  <td>nulla</td>
                  <td>Class</td>
                  <td>aptent</td>
                </tr>
                <tr>
                  <td>1,012</td>
                  <td>taciti</td>
                  <td>sociosqu</td>
                  <td>ad</td>
                  <td>litora</td>
                </tr>
                <tr>
                  <td>1,013</td>
                  <td>torquent</td>
                  <td>per</td>
                  <td>conubia</td>
                  <td>nostra</td>
                </tr>
                <tr>
                  <td>1,014</td>
                  <td>per</td>
                  <td>inceptos</td>
                  <td>himenaeos</td>
                  <td>Curabitur</td>
                </tr>
                <tr>
                  <td>1,015</td>
                  <td>sodales</td>
                  <td>ligula</td>
                  <td>in</td>
                  <td>libero</td>
                </tr>
              </tbody>
            </table>
      
    <div style=\"display:block; height:650px;\">
      <br><br>
    </div>

  <div class=\"container-fluid\">
    <div class=\"row\">
      <div class=\"main\">
        Some test text here about the chart below.   Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.<br><br>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
        <div id=\"chart_div\"></div>
    </div> 
    </div> 
  </div>  

    <script src=\"https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js\"></script>
    <script src=\"http://getbootstrap.com/dist/js/bootstrap.min.js\"></script>
    <script src=\"http://getbootstrap.com/assets/js/docs.min.js\"></script>
      </body>
      </html>"
;



// PUT YOUR HTML HEADER IN A VARIABLE
$my_html_header="
<div style=\"display:block; background-color:#f2f2f2; padding:10px; border-bottom:2pt solid #cccccc; color:#6e6e6e; font-size:.85em; font-family:verdana;\">
  <div style=\"float:left; width:33%; text-align:left;\">
      <img src=\"http://dummyimage.com/128x32/6E6E6E/ffffff.png&text=LOGO\">
  </div>
  <div style=\"float:left; width:33%; text-align:center;\">
      My Sample Header
  </div>
  <div style=\"float:left; width:33%; text-align:right;\">
      Report: January - April
  </div>
  <br style=\"clear:left;\"/>
</div>"
;


// PUT YOUR HTML FOOTER IN A VARIABLE (AND I USE PAGE NUMBERS)
$my_html_footer="
<div style=\"display:block;\">
  <div style=\"float:left; width:33%; text-align:left;\">
          &nbsp; 
  </div>
  <div style=\"float:left; width:33%; text-align:center;\">
         Page phptopdf_on_page_number of phptopdf_pages_total
  </div>
  <div style=\"float:left; width:33%; text-align:right;\">
          &nbsp;
   </div>
   <br style=\"clear:left;\"/>
</div>"
;




// SET YOUR PDF OPTIONS -- FOR ALL AVAILABLE OPTIONS, VISIT HERE:  http://phptopdf.com/documentation/
$pdf_options = array(
  
"source_type" => 'html',
  
"source" => $my_html,
  
"action" => 'save',
  
"save_directory" => '',
  
"file_name" => 'sample_pdf_report.pdf',
  
"header" => $my_html_header,
  
"footer" => $my_html_footer);


// CALL THE phpToPDF FUNCTION WITH THE OPTIONS SET ABOVE
phptopdf($pdf_options);

// OPTIONAL - PUT A LINK TO DOWNLOAD THE PDF YOU JUST CREATED
echo ("<a href='sample_pdf_report.pdf'>Download Your PDF</a>");
?>




Create a report that forces multiple page breaks (new pages)

Forcing page breaks is something that is done by simply calling a DIV with the with the class set as phpToPDF-page-break in your HTML source. During PDF generation we create page breaks wherever we see the phpToPDF-page-break DIV class.
In this example, we then save it to the current directory on your server ('' = current directory).

You can force page breaks anywhere in your source.

Source Code:   [Login to Download]





Legacy Examples   -   The original 'simple' phpToPDF functions

Save a PDF to your server from a URL

We generate a PDF from a website (url) (http://google.com) and save it to the current directory on the server. The PDF name will be 'legacy_url_example.pdf'.
We then display a link to that newly generated PDF.

Source Code:   [Login to Download]

<?php
 
// INCLUDE THE phpToPDF.php FILE
 
require("phpToPDF.php"); 
 
 
// GENERATE PDF FILE FROM SPECIFIED URL, SAVES TO CURRENT DIRECTORY ('/')
 
phptopdf_url('http://google.com/','''legacy_url_example.pdf');
  
 
// OPTIONAL - PUT A LINK TO DOWNLOAD THE PDF YOU JUST CREATED
 
echo ("<a href='legacy_url_example.pdf'>Download Your PDF</a>");
?> 




Save a PDF to your server from HTML

We generate a PDF from html and save it to the current directory on the server. The PDF name will be 'legacy_html_example.pdf'.
We then display a link to that newly generated PDF.

Source Code:   [Login to Download]

<?php
 
// INCLUDE THE phpToPDF.php FILE
 
require("phpToPDF.php"); 
 
 
// GENERATE PDF FILE FROM SPECIFIED URL, SAVES TO CURRENT DIRECTORY ('')
 
phptopdf_html('<html>Hello World!<br><br>HTML Test using phpToPDF</html>','''legacy_html_example.pdf');
  
 
// OPTIONAL - PUT A LINK TO DOWNLOAD THE PDF YOU JUST CREATED
 
echo ("<a href='legacy_html_example.pdf'>Download Your PDF</a>");
?>