We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3330
    • 3 Posts
    Anything new with this? I’m looking for an HTML to PDF converter for MODx.
      • 4172
      • 5,888 Posts
      I use tcpdf. It works well for me.
      What I have done to get it run:

      1. Create a Template with nothing than
      [!tcpdf!]

      as content.
      2. Create a Ressource with this template.
      3. Create a snippet with name tcpdf:

      <?php
      
      //collect here your output in $output, use $modx->runsnippet or what else for generating your html-output.
      
      
      $basePath = $modx->config['base_path'];
      $pluginpath = $basePath.'assets/classes/tcpdf/';
      
      if ($_GET['contentType']=='pdf'){
      include $pluginpath.'examples/myexample.php';
      }
      else{
      	return $output;
      }
      ?>

      4. Create myexample.php with something like that:

      <?php
      //============================================================+
      // File name   : example_001.php
      // Begin       : 2008-03-04
      // Last Update : 2009-03-18
      // 
      // Description : Example 001 for TCPDF class
      //               Default Header and Footer
      // 
      // Author: Nicola Asuni
      // 
      // (c) Copyright:
      //               Nicola Asuni
      //               Tecnick.com s.r.l.
      //               Via Della Pace, 11
      //               09044 Quartucciu (CA)
      //               ITALY
      //               www.tecnick.com
      //               [email protected]
      //============================================================+
      
      /**
       * Creates an example PDF TEST document using TCPDF
       * @package com.tecnick.tcpdf
       * @abstract TCPDF - Example: Default Header and Footer
       * @author Nicola Asuni
       * @copyright 2004-2009 Nicola Asuni - Tecnick.com S.r.l (www.tecnick.com) Via Della Pace, 11 - 09044 - Quartucciu (CA) - ITALY - www.tecnick.com - [email protected]
       * @link http://tcpdf.org
       * @license http://www.gnu.org/copyleft/lesser.html LGPL
       * @since 2008-03-04
       */
      //(dirname( __FILE__ )."/../../rennergebnis/includes/getdatas.php");
      require_once(dirname( __FILE__ ).'/../config/lang/de.php');
      require_once(dirname( __FILE__ ).'/../tcpdf.php');
      
      // create new PDF document
      //$pdf = new BLOCKPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); 
      
      $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); 
      
      // set document information
      $pdf->SetCreator(PDF_CREATOR);
      $pdf->SetAuthor('Nicola Asuni');
      $pdf->SetTitle('TCPDF Example 001');
      $pdf->SetSubject('TCPDF Tutorial');
      $pdf->SetKeywords('TCPDF, PDF, example, test, guide');
      
      // set default header data
      $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
      
      // set header and footer fonts
      $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
      $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
      
      // set default monospaced font
      $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
      
      
      //set margins
      $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
      $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
      $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
      
      //set auto page breaks
      $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
      
      //set image scale factor
      $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); 
      
      //set some language-dependent strings
      $pdf->setLanguageArray($l); 
      
      $pdf->SetFont('helvetica', '', 9); 
      
      
      // add a page
      $pdf->AddPage();
      
      
      $pdf->writeHTML($output);
      
      // ---------------------------------------------------------
      
      //Close and output PDF document 
      $pdf->Output('myexample.pdf', 'I');
      if(isset($_GET['savepdf'])){
      $pdf->Output($modx->config['base_path']."assets/files/pdfdownloads/".$_GET['savepdf'].".pdf", "F"); 	
      }
      
      
      //============================================================+
      // END OF FILE                                                 
      //============================================================+
      ?>


      5.create a plugin for setting the right contentType:

      <?php
      
      $e = & $modx->event;
      switch($e->name)
      {
         case 'OnLoadWebDocument':
      	   if (isset($_GET['contentType']) && $_GET['contentType']=='pdf') {
      		  $modx->contentTypes[$modx->documentObject['id']]='application/pdf';
      		}
         break;
      }
      
      ?>
      
      


      6. link to this document for example with:

      <a href="[~501~]&task=rennergebnis&contentType=pdf" target="_blank">PDF-Ausgabe</a>
      <a href="[~501~]&task=rennergebnis&contentType=pdf&savepdf=Rennergebnis_[+regatta_jahr+]" target="_blank">Als PDF-Download speichern </a>
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 6726
        • 7,075 Posts
        Excellent, I think it would warrant making this a public resource package, many want on the fly PDF generation but don’t know this is available...
          .: COO - Commerce Guys - Community Driven Innovation :.


          MODx est l&#39;outil id
        • Definitely!
            Ryan Thrash, MODX Co-Founder
            Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
            • 20413
            • 2,877 Posts
            I use this ---> http://modxcms.com/forums/index.php/topic,2513.msg227789.html#msg227789
            I have it set up the same way with a snippet in a template. By using templates I was able
            to restrict it, beacuse it made pdf’s out of restricted docs.
              @hawproductions | http://mrhaw.com/

              Infograph: MODX Advanced Install in 7 steps:
              http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

              Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
              http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
            • Hello Bruno,

              can you make detailed example?
              I make everything but new window for me is white...

              THANK YOU
              Kristalin
                palma non sine pulvere
                • 20413
                • 2,877 Posts
                Think you need to install and set right paths --> http://sourceforge.net/projects/tcpdf/files/
                  @hawproductions | http://mrhaw.com/

                  Infograph: MODX Advanced Install in 7 steps:
                  http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

                  Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
                  http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
                • Quote from: mrhaw at Sep 01, 2009, 06:22 AM

                  Think you need to install and set right paths --> http://sourceforge.net/projects/tcpdf/files/

                  i thing my problem is not in file`s huh

                  What i make:

                  1. create empty template with name: pdfconverter
                  2. create a new document with name pdfgenerator (ID 479):
                  template: pdfconverter
                  content: [!tcpdf!] /that is snippet/
                  3. create snippet with name: tcpdf
                  this code:
                  <?php
                  
                  //collect here your output in $output, use $modx->runsnippet or what else for generating your html-output.
                  
                  
                  $basePath = $modx->config['base_path'];
                  $pluginpath = $basePath.'assets/classes/tcpdf/';
                  
                  if ($_GET['contentType']=='pdf'){
                  include $pluginpath.'examples/myexample.php';
                  }
                  else{
                  	return $output;
                  }
                  ?>

                  4. Create myexample.php with:
                  this code:
                  <?php
                  //============================================================+
                  // File name   : example_001.php
                  // Begin       : 2008-03-04
                  // Last Update : 2009-03-18
                  // 
                  // Description : Example 001 for TCPDF class
                  //               Default Header and Footer
                  // 
                  // Author: Nicola Asuni
                  // 
                  // (c) Copyright:
                  //               Nicola Asuni
                  //               Tecnick.com s.r.l.
                  //               Via Della Pace, 11
                  //               09044 Quartucciu (CA)
                  //               ITALY
                  //               www.tecnick.com
                  //               [email protected]
                  //============================================================+
                  
                  /**
                   * Creates an example PDF TEST document using TCPDF
                   * @package com.tecnick.tcpdf
                   * @abstract TCPDF - Example: Default Header and Footer
                   * @author Nicola Asuni
                   * @copyright 2004-2009 Nicola Asuni - Tecnick.com S.r.l (www.tecnick.com) Via Della Pace, 11 - 09044 - Quartucciu (CA) - ITALY - www.tecnick.com - [email protected]
                   * @link http://tcpdf.org
                   * @license http://www.gnu.org/copyleft/lesser.html LGPL
                   * @since 2008-03-04
                   */
                  //(dirname( __FILE__ )."/../../rennergebnis/includes/getdatas.php");
                  require_once(dirname( __FILE__ ).'/../config/lang/de.php');
                  require_once(dirname( __FILE__ ).'/../tcpdf.php');
                  
                  // create new PDF document
                  $pdf = new BLOCKPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); 
                  
                  // set document information
                  $pdf->SetCreator(PDF_CREATOR);
                  $pdf->SetAuthor('Nicola Asuni');
                  $pdf->SetTitle('TCPDF Example 001');
                  $pdf->SetSubject('TCPDF Tutorial');
                  $pdf->SetKeywords('TCPDF, PDF, example, test, guide');
                  
                  // set default header data
                  $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
                  
                  // set header and footer fonts
                  $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
                  $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
                  
                  // set default monospaced font
                  $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
                  
                  
                  //set margins
                  $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
                  $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
                  $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
                  
                  //set auto page breaks
                  $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
                  
                  //set image scale factor
                  $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); 
                  
                  //set some language-dependent strings
                  $pdf->setLanguageArray($l); 
                  
                  $pdf->SetFont('helvetica', '', 9); 
                  
                  
                  // add a page
                  $pdf->AddPage();
                  
                  
                  $pdf->writeHTML($output);
                  
                  // ---------------------------------------------------------
                  
                  //Close and output PDF document 
                  $pdf->Output('myexample.pdf', 'I');
                  if(isset($_GET['savepdf'])){
                  $pdf->Output($modx->config['base_path']."assets/files/pdfdownloads/".$_GET['savepdf'].".pdf", "F"); 	
                  }
                  
                  
                  //============================================================+
                  // END OF FILE                                                 
                  //============================================================+
                  ?>

                  and upload this file in /ccc/cccc/public_html/dentalbg/assets/classes/tcpdf/examples
                  5.create a plugin with name: contentType:
                  this code:
                  <?php
                  
                  $e = & $modx->event;
                  switch($e->name)
                  {
                     case 'OnLoadWebDocument':
                  	   if (isset($_GET['contentType']) && $_GET['contentType']=='pdf') {
                  		  $modx->contentTypes[$modx->documentObject['id']]='application/pdf';
                  		}
                     break;
                  }
                  
                  ?>
                  

                  6. link to document-479:
                  this code:
                  <a href="[~479~]&task=rennergebnis&contentType=pdf" target="_blank">DOWN PDF</a>


                  where is problem?

                  P.S. i upload folder tcpdf in assets/classes
                    palma non sine pulvere
                    • 4172
                    • 5,888 Posts
                    1. if you have [!tcpdf!] in your content, you need [*content*] in your template, or only [!tcpdf!] in your template

                    2. do you have some html-content collected in $output?

                    3. this dosn’t matter, but you do not need &task=rennergebnis, this is only for my environment where I can have different tasks in my snippet, which collects the output.

                    4. try your link first without &contentType=pdf. If you get some html-content then try <a href="[~479~]&contentType=pdf" target="_blank">DOWN PDF</a>

                    5. did you check OnLoadWebDocument for your plugin?

                    6. Aah, and do not use <?php .............................. ?> in your plugin, only the code between!

                    7. I had a bug in myexample.php change:

                    //$pdf = new BLOCKPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); 
                    
                    $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); 


                    I have extented TCPDF to BLOCKPDF, where I can have <tcpdf method="Block" params="begin" /> in my html to stop TCPDF split blocks over two pages
                      -------------------------------

                      you can buy me a beer, if you like MIGX

                      http://webcmsolutions.de/migx.html

                      Thanks!
                    • Quote from: Bruno17 at Sep 01, 2009, 07:32 AM

                      1. if you have [!tcpdf!] in your content, you need [*content*] in your template, or only [!tcpdf!] in your template
                      i try twice - nope

                      Quote from: Bruno17 at Sep 01, 2009, 07:32 AM

                      2. do you have some html-content collected in $output?

                      i thing here is my problem because when i try with direct link ( <a href="[~479~]" target="_blank">DOWN PDF</a> ) to document 479 again white screen and question is what need i make to remove this problem?

                      Quote from: Bruno17 at Sep 01, 2009, 07:32 AM

                      3. this dosn’t matter, but you do not need &task=rennergebnis, this is only for my environment where I can have different tasks in my snippet, which collects the output.

                      ok

                      Quote from: Bruno17 at Sep 01, 2009, 07:32 AM

                      4. try your link first without &contentType=pdf. If you get some html-content then try <a href="[~479~]&contentType=pdf" target="_blank">DOWN PDF</a>

                      white screen and nope in source code

                      Quote from: Bruno17 at Sep 01, 2009, 07:32 AM

                      5. did you check OnLoadWebDocument for your plugin?

                      OK - checked

                      Quote from: Bruno17 at Sep 01, 2009, 07:32 AM

                      6. Aah, and do not use <?php .............................. ?> in your plugin, only the code between!
                      OK - remove tags <?php ?> in plugin

                      Quote from: Bruno17 at Sep 01, 2009, 07:32 AM

                      7. I had a bug in myexample.php change:
                      //$pdf = new BLOCKPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); 
                      $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); 

                      OK, changed
                      Quote from: Bruno17 at Sep 01, 2009, 07:32 AM

                      I have extented TCPDF to BLOCKPDF, where I can have <tcpdf method="Block" params="begin" /> in my html to stop TCPDF split blocks over two pages

                      but same situation...
                        palma non sine pulvere