We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 8537
    • 26 Posts
    Hello,

    I'm facing a problem that I can't solve using the class fpdf within a snippet in evolution cms.
    When I'm using the fpdf class in a standalone file "mypdf.php" called with a redirect
    $modx->sendRedirect($modx->config['site_url'].'assets/snippets/mysnippet/mypdf.php');

    with this basic code in the php file :
    <?php
    include('fpdf.php');
    $PDF=new fpdf('P','mm','A4');
    $PDF->AddPage();
    $PDF->SetFont('Arial','',10);
    $PDF->Write(12, "mytext");
    $PDF->Output();
    ?>
    

    it works fine, but I can't use TVs, $_SESSION etc.

    So I tried to use a snippet with the same code inside, called from a doc with a blank template and the following settings :
    Ressource type : web page
    Content type : application/pdf
    content output : inline element

    ressource content : [!Pdf!]

    and the snippet :
    <?php
    include($modx->config['base_path'].'assets/snippets/mysnippet/'.fpdf.php');
    $PDF=new fpdf('P','mm','A4');
    $PDF->AddPage();
    $PDF->SetFont('Arial','',10);
    $PDF->Write(12, "mytext");
    $PDF->Output();
    

    and I get nothing but a blank file (if I set the doc content type as text/html, I get a blank page)
    I guess this has something to do with item 2 in http://www.fpdf.org/?lang=en but i just can't find the solution within modx evolution.

    I look at all posts that seemed to deal with this issue but did'nt find any solution.

    Can anyone help ?

    Thank's a lot !
      • 2912
      • 315 Posts
      I've tried fpdf and never gotten on with it. I use mPDF http://mpdf1.com/ which works great for my needs. It may be worth checking that one out?

      Here's some code I use to get it to work.
      // mPDF(type, papersize, , , left?, right?, top, bottom, ?, ?
      			// $mpdf = new mPDF('win-1252','A4','','',20,15,130,55,10,10); 
      			$mpdf = new mPDF('win-1252','A4','','',20,15,100,55,10,10); 
      			
      			$css = file_get_contents('assets/snippets/statements/style.css','r');
      			
      			$mpdf->watermarkTextAlpha = 0.1;
      			$mpdf->showWatermarkText = true;
      			$mpdf->WriteHTML('<watermarktext content="COMPANY NAME" />');
      			$mpdf->watermarkImageAlpha = 0.1;
      			$mpdf->showWatermarkImage = true;
      			$mpdf->SetWatermarkImage('companylogo.png');
      
      			$mpdf->SetTitle($modx->config['site_name']);
      			$mpdf->SetAuthor($modx->config['site_name']);
      
      			$mpdf->WriteHTML($css, 1);
      			$mpdf->WriteHTML($html, 2);
      			
      			$filename = $pagetitle.".pdf";
      			
      			$file = $filename;
      			$mpdf->Output($file, 'F');


      Sorry couldn't help you with your fpdf issue. As a last thought do you get the same result when writing out to a file? You never explained the process in which you want it to work.

      Mine is a snippet which produces a PDF document from a database and emails it. Are you trying to offer a "export page to PDF?" or something? There really shouldn't be any issue on using $_SESSIONS. TV's would be down to grabbing the TV from a document.
        BBloke