We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4172
    • 5,888 Posts
    try this and link to your page with and without &contentType=pdf:

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

      you can buy me a beer, if you like MIGX

      http://webcmsolutions.de/migx.html

      Thanks!
    • Quote from: Bruno17 at Sep 01, 2009, 08:41 AM

      try this and link to your page with and without &contentType=pdf:

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


      yep, i have output:
      " This is my Test - Output "
        palma non sine pulvere
        • 8843
        • 1 Posts
        Up up,plz say "THANK" to usefultopic, Love u all smiley

        installing electric radiant floor heating systems cost heat hydronic need help for installing radiant floor heating systems, wondering the costs? installing electric radiant floor heating systems cost heat hydronic
        • Hello,


          can someone help me for export PDF (with Cyrillic chars)?
          THANKS!
            palma non sine pulvere
            • 30585
            • 833 Posts
            Quote from: PaulGregory at Nov 06, 2006, 12:10 PM

            I will be releasing a PDF plug-in/hack based on an open-source third-party PHP-based HTML-PDF conversion routine later this month, after 0.9.5 is released.

            Hey guys,

            Any news yet on that snippet?
              A MODx Fanatic
              • 19369
              • 1,098 Posts
              Hi Bruno,
              I have installed tcpdf but I have a problem. When I click the link
              <a href="[~34~]&contentType=pdf" target="_blank">DOWN PDF</a>


              I see the PDF but not the content of the page. What I see is a Red Logo and this: TCPDF Example
              by Nicola Asuni - Tecnick.com
              www.tcpdf.org


              Where do you think is the mistake?

              Thanks in advance.
                • 4172
                • 5,888 Posts
                did you fill $output in your snippet with some html?
                  -------------------------------

                  you can buy me a beer, if you like MIGX

                  http://webcmsolutions.de/migx.html

                  Thanks!
                  • 19369
                  • 1,098 Posts
                  Tanks for the reply Bruno, I am pretty sure that I’m doing something very stupid. Here’s what I’ve tried so far:

                  1) I have added the $output in the snippet like this
                  $output = $modx->documentObject['content']; 

                  In my template I have this link <a href="[~34~]&contentType=pdf" target="_blank">DOWN PDF</a>. The resource 34 is empty, inside there is only the template set with the snippet call [!tcpdf!].

                  2) If I put some content in resource 34 I see the content inside the PDF so it’s working somehow, but if I change the id, for example <a href="[~1~]&contentType=pdf" target="_blank">DOWN PDF</a> (ID 1 is the home page), it doesn’t work.
                    • 4172
                    • 5,888 Posts
                    pdf is of course only generated on page 34 (where you have your [!tcpdf!] snippet-call).

                    what you can try is create a link:

                    <a href="[~34~]&contentType=pdf&docid=1" target="_blank">DOWN PDF</a>


                    then in your snippet:

                    $doc['content']='<p>no docid was given to generate pdf-content</p>';
                    if (isset($_GET['docid'])){
                    $id=$modx->db->escape($_GET['docid']);
                    $doc = $modx->getPageInfo($id,1,'content'); 
                    }
                    $output = $doc['content']; 
                      -------------------------------

                      you can buy me a beer, if you like MIGX

                      http://webcmsolutions.de/migx.html

                      Thanks!
                      • 19369
                      • 1,098 Posts
                      Thanks so much Bruno, now it works!

                      Here is my snippet and the link if somebody needs it

                      The Snippet
                      <?php
                      //collect here your output in $output, use $modx->runsnippet or what else for generating your html-output.
                      
                      $doc['content']='<p>no docid was given to generate pdf-content</p>';
                      if (isset($_GET['docid'])){
                      $id=$modx->db->escape($_GET['docid']);
                      $doc = $modx->getPageInfo($id,1,'content'); 
                      $title = $modx->getPageInfo($id,1,'longtitle'); 
                      
                      }
                      $output = "<h1>".$title['longtitle']."</h1><br/>".$doc['content']; 
                      
                      $basePath = $modx->config['base_path'];
                      $pluginpath = $basePath.'assets/classes/tcpdf/';
                      
                      if ($_GET['contentType']=='pdf'){
                      include $pluginpath.'examples/myexample.php';
                      }
                      else{
                      	return $output;
                      }
                      ?>
                      


                      The Link:
                      <a href="[~34~]&contentType=pdf&docid=[*id*]" target="_blank">DOWNLOAD PDF</a>

                      (34 is the resource with the [!tcpdf!] call)

                      I have noticed that when I save the PDF in the computer the PDF name is always the URL alias of page ID 34.
                      I think that line 5918 in tcpdf.php is responsible for this. I will post here the solution if I find one.
                      header('Content-Disposition: attachment; filename="'.basename($name).'";');