Jump to content
Wanze

Pages2Pdf

Recommended Posts

Is it possible to include child pages in the PDF??

I have created a pricelist and each item of the pricelist is a single page. On the pricelist template I output all child pages with a foreach loop. The result is my pricing table.

Unfortunately on the PDF the content of the child pages is not visible, so I have an empty page.

Share this post


Link to post
Share on other sites

I've not used the Pages2PDF module by now, but you can use the WirePDF module, which is part of the installation, to render any html content you pass to it. 

  • Like 1

Share this post


Link to post
Share on other sites

Is it possible to include child pages in the PDF??

I have created a pricelist and each item of the pricelist is a single page. On the pricelist template I output all child pages with a foreach loop. The result is my pricing table.

Unfortunately on the PDF the content of the child pages is not visible, so I have an empty page.

You have the full ProcessWire API available in your Pages2Pdf templates.

Did you output the children also in the template inside "site/templates/pages2pdf"? If so, they should appear in the PDF files.

Only problem I can think of is that the PDF enginge can't handle your markup, you might need to simplify the HTML. But for testing purposes, you can also just list the prices-pages in a simple list. If it does still not work, please post the content of your pages2pdf "pricelist" template.

Cheers

  • Like 1

Share this post


Link to post
Share on other sites

Did you output the children also in the template inside "site/templates/pages2pdf"? If so, they should appear in the PDF files.

This was the problem. I have forgotten to include the child pages template. Thanks Wanze

  • Like 1

Share this post


Link to post
Share on other sites

Hi Wanze,

thanks for this cool module! this really did save some headscratching for a current project I'm working on.

Do you have a tip how I can include my ./template/_init.php file for the "pdf"template? I need to use some vars that are declared site-wide in this _init.php file.

I'm sure this can easily be achived, esp. after seeing that there's a hookable createPDF function… but I'm not sure how this "prepend file to template" would be addressed…? Sorry if this is something totally obvious, I'd glady take a rtfm link, as well ;-)

cheers
Tom

Share this post


Link to post
Share on other sites

Hi Tom,

Thanks. Simplest solution would be to include the file inside your PDF templates, like this:

// We are in a template file under /site/templates/pages2pdf/, include /site/templates/_init.php
include('../_init.php');

Cheers

  • Like 1

Share this post


Link to post
Share on other sites

Hi,

ok, I forgot to mention that I need to use some of the "_init.php" vars in the _header/_footer.php inside ./pages2pdf.

I tried to include the _init there, and then in the template as you suggested, but a simple var_dump for one of the "_init" variables returns empty.

to give you a bit of background; I use thiis approach: https://processwire.com/talk/topic/10447-using-translatable-strings-across-template-files/#entry99012

for the template translation thing, but somehow the templates inside pages2pdf are ignorant of the "_string.php" file.

I have some "translateble" strings in _header/footer.php, but they're ignorant of the translations. :-)

cheers

Tom

UPDATE: Ok, after some more debugging I see that the  include_once('../_init.php') works like you presumed, the vars are there. something else must interfer with the translation thing, at least it is not caused by a not-working include. sorry for the bother.

UPDATE 2: After even more debugging and testing; the _init needs to be included in all three php files: _header.php, page.php, _footer.php - it seems to be scoped to that file alone where it is included. I somehow was expectng that the incude in the _header.php alone would be enough, but after reflecting how the PDF is looking -- where _header and _footer are repeated on every "page" of the PDF -- it makes sense that this didn't work out. However, I think having three identical includes that are repeatetly called during the creation of the PDF is not really the best way to go about this, even if it now works… :-) ?

  • Like 1

Share this post


Link to post
Share on other sites

@Webrocker

Glad it works for you!

However, I think having three identical includes that are repeatetly called during the creation of the PDF is not really the best way to go about this, even if it now works…  :-) ?

I don't see a problem here if your include does not do some heavy stuff, in this case you should cache the results. But I think there's no easy alternative... ProcessWire does the same for you in the background when you're using the prependTemplate file option, it is just included "automaticaly" in every ProcessWire template. I could check if this setting is enabled and include the prepended file in the background, but this might not be desired in another situation :)

Share this post


Link to post
Share on other sites

WirePdf's $pdf->mpdf doesn't return the mpdf instance for me and a quick look through the code seems to confirm that. 

  • Like 1

Share this post


Link to post
Share on other sites

had also problems with that so i included it manually... i thought i was doing something wrong with those instructions of the module's page

For advanced usage, you can also get the mPDF instance from the module:

$pdf = $modules->get('WirePDF');
// Get mPDF instance
$mpdf = $pdf->mpdf;
// Set back mPDF instance
$pdf->mpdf = $mpdf;

Share this post


Link to post
Share on other sites

Hi Wanze,

It looks like the current version of this can't be installed using PW's built-in by class name feature, because it tries to install Pages2df before WirePDF. It works fine if you use the URL option and point it to the zip on Github though because that way it downloads and extracts and shows you both modules with the option to install WirePDF.

Share this post


Link to post
Share on other sites

Hi Adrian,

Thanks for the information. Do you know if I can solve this somehow? Seems like ProcessWire should look for the missing dependency as well when using the classname installation-mode, but I'm not sure if this is easy possible.

Cheers

Edit: Thanks LostKobrakai for opening the issue

Share this post


Link to post
Share on other sites

You could switch dependencies, where Pages2Pdf installs WirePDF, instead of requiring it to be installed previously.

  • Like 1

Share this post


Link to post
Share on other sites

Hi guys,

This is a bug. It should work if you add $this->initPDF() before this line: https://github.com/wanze/Pages2Pdf/blob/master/WirePDF.module#L91

I will fix it and update the module.

Cheers

That's really a bigger thing, as the whole mpdf instance is being overwritten on save, if one is using pageOrientation or something other "constructor argument".

Share this post


Link to post
Share on other sites

Hi there,

I can't guarantee that this is an issue with pages2pdf, but let me point to my last Forum post : https://processwire.com/talk/topic/11065-urlsegment-issue-string-vs-integer/

Footer inclusion seems to mess things up. Maybe I'm missing something, though. If so, I'm sorry. (It sounds surprising that I would be the only one facing such a problem).

Share this post


Link to post
Share on other sites

It would be a nice addition if one could directly use mpdf's functions on the wirepdf module instead of retrieving and setting the mpdf instance every time one does need a native functionality.

Share this post


Link to post
Share on other sites

I'm having problem with this module not using translations in template __("Text"). It's always default language for those strings. 


Ah sorry, I forgot that the pages2pdf template aren't translated yet :)

Share this post


Link to post
Share on other sites
That's really a bigger thing, as the whole mpdf instance is being overwritten on save, if one is using pageOrientation or something other "constructor argument".

I removed the check to constructor arguments with the latest release on the dev branch. However, you always need to set the config options before saving the PDF file.

It would be a nice addition if one could directly use mpdf's functions on the wirepdf module instead of retrieving and setting the mpdf instance every time one does need a native functionality.

This feature is available on the dev branch, you should now be able to call any method on the mPDF instance directly trough WirePDF (as long as the method does not exist as public method on WirePDF already). Technically setting back the mPDF instance was not needed before, I removed this from the ReadMe.

If you find any time to get a copy from the dev branch and check if everything works for you, that would be great! :)

Cheers

  • Like 2

Share this post


Link to post
Share on other sites

Where to direct a custom PDF File Path in the WirePDF config to, e.g. for folder templates? Don t get it running.

Share this post


Link to post
Share on other sites

@Spica,

I don't understand your question, are you trying to set the path to the template that defines the markup of the PDF?

$pdf = $modules->get('WirePDF');
$pdf->markupMain = $config->paths->templates . 'pdf_template.php';

Share this post


Link to post
Share on other sites

Sorry, typing error. I meant the CSS File Path in the WirePDF config mask declared with "Enter path and filename of a CSS file containing default styles to be used by mPDF for the HTML markup" for substituting the templates/pages2pdf/styles.css.

e.g ../../templates/vendor/my.css, or templates/vendor/my.css does not succeed.

Share this post


Link to post
Share on other sites

I think you need the full path to the file, e.g. /var/www/mysite/site/templates/myCss.css

If you don't know the path, check the output of "$config->paths->templates".

Let me know if it still does not work!

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By gebeer
      I am happy to present my new fieldtype FieldtypeImageFromPage. It is made up of 2 modules:
      Fieldtype Image Reference From Another Page is a Fieldtype that stores a reference to a single image from another page. The image can be selected with the associated Inputfield.
      Inputfield Select Image From Page is an Inputfield to select a single image from images on a predefined page and it's children.
      And there also is a helper module that takes care of cleanup tasks.
      This module evolved out of a discussion about my other Module FieldtypeImagePicker.  It caters for use cases where a set of images is being reused multiple times across a site. With this fieldtype these images can be administered through a chosen page. All images uploaded to that page will be available in the inputfield.
      When to use ?
      Let editors choose an image from a set of images that is being used site-wide. Ideal for images that are being re-used across the site.
      Suited for images that are used on multiple pages throughout the site (e.g. icons).
      Other than the native ProcessWire images field, the images here are not stored per page. Only references to images on another page are stored. This has several advantages:
      one central place to organize images when images change, you only have to update them in one place. All references will be updated, too. (Provided the name of the image that has changed stays the same) Features
      Images can be manipulated like native ProcessWire images (resizing, cropping etc.) Image names are fully searchable through the API Accidental image deletion is prevented. When you want to delete an image from one of the pages that hold your site-wide images, the module searches all pages that use that image. If any page contains a reference to the image you are trying to delete, deletion will be prevented. You will get an error message to help you edit those pages and remove references there before you can finally delete the image. How to install and setup
      Download and install this module like any other modules in ProcessWire Create a page in the page tree that will hold your images. This page's template must have an images field Upload some images to the page you created in step 2 Create a new field. As type choose 'Image Reference From Another Page'. Save the field. In 'Details' Tab of the field choose the page you created in step 2 Click Save button Choose the images field name for the field that holds your images (on page template from step 2) Click Save button again Choose whether you want to include child pages of page from step 2 to supply images Add the field to any template You are now ready to use the field View of the inputfield on the page edit screen:

      View of the field settings

      The module can be installed from this github repo. Some more info in the README there, too.
      In my tests it was fairly stable. After receiving your valued feedback, I will eventually add it to the modules directory.
      My ideas for further improvement:
      - add ajax loading of thumbnails
      Happy to hear your feedback!
       
    • By gebeer
      Although the PW backend is really intuitive, ever so often my clients need some assistance. Be it they are not so tech savvy or they are not working in the backend often.
      For those cases it is nice to make some help videos available to editors. This is what this module does.
      ProcessHelpVideos Module
      A Process module to display help videos for the ProcessWire CMS. It can be used to make help videos (screencasts) available to content editors.
      This module adds a 'Help Videos" section to the ProcessWire backend. The help videos are accessible through an automatically created page in the Admin page tree. You can add your help videos as pages in the page tree. The module adds a hidden page to the page tree that acts as parent page for the help video pages. All necessary fields and templates will be installed automatically. If there are already a CKEditor field and/or a file field for mp4 files installed in the system, the module will use those. Otherwise it will create the necessary fields. Also the necessary templates for the parent help videos page and it's children are created on module install. The module installs a permission process-helpvideos. Every user role that should have access to the help video section, needs this permission. I use the help video approach on quite a few production sites. It is stable so far and well received by site owners/editors. Up until now I installed required fields, templates and pages manually and then added the module. Now I added all this logic to the install method of the module and it should be ready to share.
      The module and further description on how to use it is available on github: https://github.com/gebeer/ProcessHelpVideos
      If you like to give it a try, I am happy to receive your comments/suggestions here.
    • By Robin S
      A module created in response to the topic here:
      Page List Select Multiple Quickly
      Modifies PageListSelectMultiple to allow you to select multiple pages without the tree closing every time you select a page.
      The screencast says it all:

       
      https://github.com/Toutouwai/PageListSelectMultipleQuickly
      https://modules.processwire.com/modules/page-list-select-multiple-quickly/
    • By gebeer
      Hello all,
      sharing my new module FieldtypeImagePicker. It provides a configurable input field for choosing any type of image from a predefined folder.
      The need for it came up because a client had a custom SVG icon set and I wanted the editors to be able to choose an icon in the page editor.
      It can also be used to offer a choice of images that are used site-wide without having to upload them to individual pages.
      There are no image manipulation methods like with the native PW image field.
      Module and full description can be found on github https://github.com/gebeer/FieldtypeImagePicker
      Kudos to @Martijn Geerts. I used his module FieldTypeSelectFile as a base to build upon.
      Here's how the input field looks like in the page editor:

      Hope it can be of use to someone.
      If you like to give it a try, I'm happy to hear your comments or suggestions for improvement. Eventually this will go in the module directory soon, too.
    • By bernhard
      @Sergio asked about the pdf creation process in the showcase thread about my 360° feedback/survey tool and so I went ahead and set my little pdf helper module to public.
      Description from PW Weekly:
       
      Modules Directory: https://modules.processwire.com/modules/rock-pdf/
      Download & Docs: https://github.com/BernhardBaumrock/RockPDF
       
      You can combine it easily with RockReplacer: 
      See also a little showcase of the RockPdf module in this thread:
       
×
×
  • Create New...