We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 8609
    • 607 Posts
    ahhh, perfect! smiley

    thanks for sharing!!
      • 7455
      • 2,204 Posts
      Nice work does this also work for protected pages that needs a login? thats where i stranded with my doc2pdf snippet I made
        follow me on twitter: @dimmy01
        • 16183
        • 1,390 Posts
        Thx for sharing... smiley

        cheers/k
          • 16702 ☆ A M B ☆
          • 536 Posts
          Hey,


          you now jobs is great!
          Question of Questions is cyrillic...
          Can anybody help me?

          My BD is:
          Database Charset: utf8
          Database Collation Charset: utf8_general_ci
            palma non sine pulvere
            • 9122
            • 27 Posts
            Quote from: mrhaw at Jul 16, 2009, 02:57 AM

            @estring: Thank you!!!! Instead of using the CurrentDoc snippet [*id*] can do it!
            <a href="custom/html2pdf/create_pdf.php?docid=[*id*]">Save as PDF</a>


            I searched all over the place to find out how to get the id of the current document. I don’t know how I didn’t find [*id*].
            Thanks a bunch.
              • 20413
              • 2,877 Posts
              @estring: It’s changing name all the time "document variables, resource something but now it is -->
              http://svn.modxcms.com/docs/display/MODx096/Document+Object (Me like)

              [b]!ATTENTION![b]
              @Dimmy: It reads protected pages... In my case I have no "protected content" in content field so
              it doesn’t matter if anyone was fishing, but it would be nice to get this fixed!

              @Kristalin: Did you change the xml and html header in create_pdf.php?
                @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
                • 16702 ☆ A M B ☆
                • 536 Posts
                Quote from: mrhaw at Jul 16, 2009, 09:21 PM

                @Kristalin: Did you change the xml and html header in create_pdf.php?

                actually yes,
                i try:

                <?xml version="1.0" encoding="UTF-8"?>

                <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

                no results and then try with windows 1251 -cyrillic encoding - same results.

                another attempt is for "fonts" in create_pdf header i put:
                    $pdf->AddFont('Comic','','comic.php');

                this font i upload in FONT folder in my custom/html2pdf.
                for this comic.php i follow this steps:
                http://www.fpdf.org/en/tutorial/tuto7.htm

                in an interesting manner is when i use FPDF ALONE (no modx, no another scripts...direct input content) is work fine.

                !0x

                :)
                  palma non sine pulvere
                  • 16702 ☆ A M B ☆
                  • 536 Posts
                  common guys, help rolleyes huh

                  it`s !mportant
                    palma non sine pulvere
                    • 20413
                    • 2,877 Posts
                    @Kristalin As I had problems with swedish characters åäö
                    I solved it with utf8_decode() have you tried that?
                    $pagetitle = utf8_decode($goGet['pagetitle']); 


                    As for security I changed getValue to $modx->getDocumentObject()
                    and some more tricks:
                    Replace images with (image)
                    and whats inside of <!--NOPDF--> ... <!--NOPDF--> with (video) in my case

                    My snippet inside MODx:
                    <?php
                    if(isset($_GET['makepdf'])) {
                        $makepdf = $modx->documentObject['id'];
                        
                        require_once($modx->config['base_path'] .'myfolder/html2pdf/html2fpdf.php');
                        require_once($modx->config['base_path'] .'myfolder/html2pdf/sanitize.php');
                    
                        $goGet = $modx->getDocumentObject('id',$makepdf);
                        $pagetitle = utf8_decode($goGet['pagetitle']);    
                        $introtext = utf8_decode($goGet['introtext']);
                        $content = utf8_decode($goGet['content']);
                        $content2 = preg_replace("/<img[^>]+\>/i", "(image)", $content);
                        $content3 = preg_replace('#<!--NOPDF-->[^>]*>.*?<!--NOPDF-->#si', '(video)', $content2);
                    
                        $pdf=new HTML2FPDF();
                        $pdf->AddPage();
                        $strContent = '
                    <?xml version="1.0" encoding="UTF-8" ?>
                    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                    <html xmlns="http://www.w3.org/1999/xhtml">
                    <head>
                    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
                    <title>'.$pagetitle.' | My Site Name</title>
                    </head>
                    <body>
                    <strong>'.$pagetitle.' | My Site Name | '.$introtext.'</strong><br /><br /> 
                    '.$content3.'
                    </body>
                    </html>
                    ';
                    
                        $pdf_title = sanitize_paranoid_string($pagetitle) . '.pdf';
                        $pdf->WriteHTML($strContent);
                        $pdf->Output($pdf_title);
                        //echo "PDF file is generated successfully!";
                        header('Pragma: public');
                        header('Expires: 0');
                        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
                        header('Content-Type: application/pdf');
                        header('Content-Disposition: attachment; filename="'.$pagetitle.'.pdf"');
                        readfile($pdf_title);
                        unlink($pdf_title);
                    } 
                    else {
                        return;
                    }
                    ?>


                    after $strContent = it should be a: ’
                    $strContent = '

                    I can’t see it there?¿
                      @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
                      • 20413
                      • 2,877 Posts
                      Secure query => $modx->getDocumentObject() !! shocked laugh

                      Quote from: http://wiki.modxcms.com/index.php/API:getDocumentObject
                      Retrieves a Document from the database. Document permissions are verified.
                        @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