We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • Yes the image is in the PDF... Here’s a copy of the basic template. See if it works for you perhaps?
      Ross Sivills - MD AugmentBLU Edinburgh, Scotland UK
      AugmentBLU - MODX Partner

      BLUcart - MODX Revolution E-Commerce & Shopping Cart
    • I need a little help on how to make this work properly.

      Document 50 is my parent and it has a simple ditto call so all the PDF’s are listed and that is it.... no reference to makepdf

      Document 51 is my first PDF, I have it set to blank template, application/pdf, and the call of [!MakePDF? &parent=`55` !]. I then put some text in to test.

      On viweing the ditto page and clicking the link, the pdf does open as it should but it shows [!MakePDF? &parent=`55` !] test test in the PDF?

      I put the test test in but why is the [!MakePDF? &parent=`55` !] showing up? Have i done something completely wrong with this?

      Also using friendly URLS, if i use an alias it comes up as page.pdf.html


      Thanks!
        Ross Sivills - MD AugmentBLU Edinburgh, Scotland UK
        AugmentBLU - MODX Partner

        BLUcart - MODX Revolution E-Commerce & Shopping Cart
      • Nimja

        Could you clarify that the latest version of this works and tell me exactly how you set the folders up and which call went on what page and their settings. I can’t get this to work correctly. It keeps erroring in my acrobat and half the text disappears.

        Thanks!
          Ross Sivills - MD AugmentBLU Edinburgh, Scotland UK
          AugmentBLU - MODX Partner

          BLUcart - MODX Revolution E-Commerce & Shopping Cart
        • Nimja hasn’t been active for the last month by the looks of it and I was wondering if anyone else could help with this snippet?
            Ross Sivills - MD AugmentBLU Edinburgh, Scotland UK
            AugmentBLU - MODX Partner

            BLUcart - MODX Revolution E-Commerce & Shopping Cart
            • 21560
            • 145 Posts
            I don’t visit this forum very much if I’m not working on my site, sorry for that.

            There are some tests you can do if you’re familiar with PHP. First of all, if you comment the pieces that export to PDF, you can see any errors that arise.

            Common errors; Wrong dir, includes not working, etc.

            Most of them should be easily fixed.

            Have you tried that?

              [font=Times]Comics, stories, music, graphics, games and more! http://Nimja.com
              • 36571
              • 145 Posts
              This is a very useful addition to modx. Good work Nimja.

              I was wondering if there was a way to create a PDF based on an individual page, rather than a parent. This would presumable require the snippet to set id dynamically.

              Or perhaps it could be done through filtering all the children of a parent except the one that you want.

              Please let me know if this can be done.

              Cheers.
                • 21560
                • 145 Posts
                Modifying the snippet to just export 1 page to PDF is quite easy. Basically, you just use the MODx function to retrieve the content of a specific page instead of a parent
                getDocument(int $id[, string $fields[, int $published[, int $deleted]]]);

                This will simply give you an object with all the contents of a single document. Then, instead of using my complicated loop, just parse the content any way you want to. Depending on the page, you might want to use a different PDF library, more suited for HTML2PDF for example. My plain text one is chosen for one simple reason.

                Volume.

                I have 450 pages in my PDF, but it has to be dynamically generated (still fixing typos etc.) and there was only one libray that could handle it, which is the one in my example. In fact, above 50 pages is where most other libraries faltered.

                Hope this is informative. smiley
                  [font=Times]Comics, stories, music, graphics, games and more! http://Nimja.com
                  • 36571
                  • 145 Posts
                  Thanks for the reply Nimja.

                  Yes I tried to rewrite your function using getDocuments:

                  	//Use MODX function to get children.
                  	//$parents = split(',', $parent);
                  	//$pages = Array();
                  	//foreach($parents as $par) {
                  	//	$pages = array_merge($par,$modx->getDocumentChildren($par, 1, 0, $fields, $where, $sortBy, $sortHow, $limit));
                  $pages = $modx->getDocuments($parent, 1, 0, $fields, $where, $sortBy, $sortHow, $limit));
                  	}


                  But it does not seem to render at all.

                  Any ideas?
                    • 21560
                    • 145 Posts
                    Ah, no. It means you’ll have to rewrite a bit. Let me show you.

                    Replace
                    	//Use MODX function to get children.
                    	$parents = split(',', $parent);
                    	$pages = Array();
                    	foreach($parents as $par) {
                    		$pages = array_merge($pages,$modx->getDocumentChildren($par, 1, 0, $fields, $where, $sortBy, $sortHow, $limit));
                    	}


                    With
                    	//Use MODX function to get documents
                    	$parents = split(',', $parent);
                    	$pages = Array();
                    	foreach($parents as $par) {
                    		$page = $modx->getDocument($par, $fields, 1, 0);
                    		array_push($pages, $page);
                    	}


                    What this will do is retrieve the page with the ID you give to the function (seperated by comma’s if you want to give more id’s).
                    Technically speaking, what we did is replace the merge with a push function, as the result of the get-document is not an array of documents, but simply one document object.

                    Now, documents are represented as arrays as well, that’s just how PHP works. So, the $pages ’array’ holds several $page ’arrays’ in both situations. But in the first it’s based on the parents (which retrieve one-or-more documents) and in the second it’s based on the actual document (Which will always retrieve only one)

                    Anyway, with this minimal edit, it should do what you require (and more!) though ’filters’ will no longer work, obviously, as you’re retrieving specific ID’s.
                      [font=Times]Comics, stories, music, graphics, games and more! http://Nimja.com
                      • 36571
                      • 145 Posts
                      Awesome! Thanks.

                      I will test this out today and report back.

                      Also, is there a way of setting the ID dynamically? What I want to do is to have a link in the page template like "Create PDF of this page" that the user can click on, and the snippet then renders the PDF of that page automatically.

                      Is it just a case of passing the id variable using the URL (as is possible with Ditto) or will it require some recoding?