Wanze

Pages2Pdf

Recommended Posts

Hi @dragan

16 minutes ago, dragan said:

Haven't used this module myself yet, but mpdf has a TOC function: https://mpdf.github.io/what-else-can-i-do/table-of-contents.html

looks good, I will play with it and see what I can do 

As of the prepend/append custom php files to the foreach pdf generation, nevermind - I've just found a way which is working just fine:

$pdf->markupMain = '';
$pdf->markupMain .= wireRenderFile($this->config->paths->ProcessBook2pdf . '/templates_book/_coverFront.php'); //front page
foreach($pageArray as $item) {
	$pdf->markupMain .= wireRenderFile($this->config->paths->ProcessBook2pdf . '/templates_book/default.php', ["page" => $item]); //actual book content
}
$pdf->markupMain .= wireRenderFile($this->config->paths->ProcessBook2pdf . '/templates_book/_coverBack.php'); // back page

 

Share this post


Link to post
Share on other sites

Stuck with pw-modal / pw-panel opening of generated pdf.

I have a pageArray containing selected pages, if I export the array in pdf from the current page (thus replacing the custom module page), it is all fine and correct.

If I use the same setting and try to export the pdf in modal window (by adding pw-modal in the button), well the modal window pops up but it show the frontend website 404 page, whereas in panel window (by adding pw-panel in the button) the pdf is rendered in panel but with missing pieces (not reading the $page instance!).

this is how I send the page array to feed the pages2pdf module:

foreach($pageArray as $item) {
	$pdf->markupMain .= wireRenderFile($this->config->paths->ProcessBook2pdf . '/templates_book/default_panel.php', ["page" => $item]);
}

therefore the problem is that even though I state ["page" => $item] from the pageArray, only in both modal and panel windows the $page variable in foreach loop is just the current module page!

@Wanze do you know why I cannot pass the pageArray to the pages2pdf to feed the modal/panel window? thanks

Share this post


Link to post
Share on other sites

Anyone already tried the module with admin page/Process modules ?

I can get it working, but only by hacking the module.

 

On 17/02/2018 at 5:41 PM, Federico said:

therefore the problem is that even though I state ["page" => $item] from the pageArray, only in both modal and panel windows the $page variable in foreach loop is just the current module page!

Not surprised here, did you tried with another var name ? ($page is a reserved word in ProcessWire)

 

 

@Wanze With PHP-7.0.10 I get those warning :

Quote

PHP Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; 
mPDF has a deprecated constructor in .../wwwroot/site/modules/Pages2Pdf/mpdf/mpdf.php:66

PHP Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; 
grad has a deprecated constructor in .../site/modules/Pages2Pdf/mpdf/classes/grad.php:3

PHP Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; 
form has a deprecated constructor in .../site/modules/Pages2Pdf/mpdf/classes/form.php:3

PHP Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; 
cssmgr has a deprecated constructor in .../site/modules/Pages2Pdf/mpdf/classes/cssmgr.php:3

 

Edit:   fixed by replacing mpdf with the version 6.1

Share this post


Link to post
Share on other sites

 

1 hour ago, flydev said:

Not surprised here, did you tried with another var name ? ($page is a reserved word in ProcessWire)

@flydev I've tried with different variable than $page, same results. Please note that ["page" => $item] inside the above foreach loop works correctly if I submit the form, as the pdf is generated correctly in the new browser tab, with all $page as $items taken from the the pageArray. I mean, all php functions are working OK when the form is submitted, but I can't submit the form on a modal window.

The point here is that if I add pw-panel to the button class, then the foreach loop doesn't even fire, totally skipped! so I guess the following argument:

- The pw-panel and pw-modal windows don't let php foreach to fire (most likely because there is no real form submit), they both work just fine with only direct php statements. Moreover, $page variable is just the current module page.

 

Share this post


Link to post
Share on other sites
On 12/26/2017 at 10:10 AM, Macrura said:

For anyone who is having the red x problem with images, I was able to solve these missing images by doing 2 things:

1) If you are on https, convert image references to absolute (i think this is because the library uses http when replacing image references ?)


$rootPath = $pages->get(1)->httpUrl;
$body = str_replace("/site/assets/", $rootPath . "site/assets/" , $page->body);

2) Manually create the temp folder ("WirePDF") inside site/assets/cache/ – this folder did not exist and therefore the core library was throwing image errors.

Once these 2 things were completed, now the PDFs generate with the images correctly

Doesn't work for me :( .. and this doesn't work either:

<img src='<?=$config->urls->templates."images/logo.png"?>'>
/* or usign the url directly either */
<img src='http://www.domain.com/site/templates/images/logo.png'>

Before work's and the path is correct because in the other templates prints well

Everything happened after updating the module.

Share this post


Link to post
Share on other sites

What happens if you exchange the png file with a jpeg file?

Share this post


Link to post
Share on other sites

Did anyone successfully use @page in the stylesheet to e.g. set page size or margins? I don’t see anything happen if I add the following code block to templates/pages2pdf/styles.css:

@page {
    size: A5;
    margin: 10mm;
}

I’m using the dev branch of Pages2Pdf (mPDF v6.1).

Share this post


Link to post
Share on other sites
5 hours ago, charger said:

I don’t see anything happen if I add the following code block to templates/pages2pdf/styles.css:


@page {
    size: A5;
    margin: 10mm;
}

I don't think this works. The size property for @page only accepts the values "auto", "portrait", "landscape" or an absolute width/height tuple. Named page formats aren't listed as supported.

Share this post


Link to post
Share on other sites
16 hours ago, BitPoet said:

I don't think this works. The size property for @page only accepts the values "auto", "portrait", "landscape" or an absolute width/height tuple. Named page formats aren't listed as supported.

You’re right. Bad example. But it also doesn’t work with width and height values like this:

@page {
    size: 100mm 150mm;
}

 

Share this post


Link to post
Share on other sites

@Wanze Would it be possible to support:

$config->pagefileSecure = true;

If it is already supported? What am I supposed to do? I'm getting "missing image" icons only:

496338021_Bildschirmfoto2018-06-20um17_06_20.png.14e862ed671d98916eaca3775e3b8172.png

If i disable `$config->pagefileSecure` everything's working fine and I see the images in the PDF.

Warning:
Don't try to use image resizing and dynamically disable `$config->pagefileSecure` while rendering PDF's.
It will create the image variations in an unprotected directory.

Quick Workaround:

$filePath = $image->size(0, 100)->filename;
$fileType = mime_content_type($filePath);
$fileContents = file_get_contents($filePath);
$base64 = base64_encode($fileContents);
$out[] = "<img src=\"data:image/{$fileType};base64,{$base64}\">";

 

Share this post


Link to post
Share on other sites
On 12/26/2017 at 9:10 AM, Macrura said:

For anyone who is having the red x problem with images, I was able to solve these missing images by doing 2 things:

1) If you are on https, convert image references to absolute (i think this is because the library uses http when replacing image references ?)


$rootPath = $pages->get(1)->httpUrl;
$body = str_replace("/site/assets/", $rootPath . "site/assets/" , $page->body);

2) Manually create the temp folder ("WirePDF") inside site/assets/cache/ – this folder did not exist and therefore the core library was throwing image errors.

Once these 2 things were completed, now the PDFs generate with the images correctly

This is still an issue.

  • Like 1

Share this post


Link to post
Share on other sites

@joer80 @marcura 

The problem with the missing images can be fixed if you use the path instead of the URL

$page->getUnformatted($fieldName)->first()->filename

This is also working when you use pageFileSecure setting in config.php for protected files.

Sadly when using the path instead of the URL, the image can not be shown in the webbrowser, but is available in the PDF.

Share this post


Link to post
Share on other sites

I'm trying for the first time the Pages2Pdf module because I would like to create a PDF from an array of custom data:

$custom_data = ["paragraph1"=>"text1", "paragraph2"=>"text2", "paragraph3"=>"text3"]

My (newbie) questions are:

  • How can I build the PDF file from the above data (maybe passing the data to a Pages2Pdf template file)?
  • Could/Should I use a template file located in the /site/templates/pages2pdf folder to make this?
  • Bonus: To reach my intent (note: I'm not creating PDF from Page data but from e.g. FormBuilder data entry), should I install and use both Pages2Pdf and WirePDF modules or can I just install and use the WirePDF one? should I use the Pages2Pdf at all?

Code examples are welcome.

Share this post


Link to post
Share on other sites

Hey @LAPS! Sorry, I can't really help you with your issue, but wanted to mention that I've merged your question into the Pages2PDF support thread.

Module-related questions should be posted to appropriate support threads whenever possible. This keeps things nice and clean on the forum side, and it's also the best way to get answers 🙂

Share this post


Link to post
Share on other sites

Hey @LAPS from my experience I can say that you would better go with @bernhards RockPDF. WirePDF and the included mPDF are outdated and don't work with PHP >= 7. RockPDF uses the latest version of mPDF and also provides a debugging feature.

However, I also updated mPDF in wirePDF and made the module itself compatible with the new settings but then switched to RockPDF. Eventually I will make a PR on the github repo.

  • Like 2

Share this post


Link to post
Share on other sites

Thanks for the great module!

When i use it for normal page sizes (A4,A3.. etc) it works fine but i don´t understand how i could get custom sizes for some templates.

We sponsor the local football club and want to helt them generate tickets.

The tickets look good but i dont find a way to get the custom sizes needed.

 

Edit:

How can i i create a file with multiple pages?

My code:

$options = array(
  'title' => 'Skapa PDF',
  'markup' => '<a href="{url}" target="_blank">{title}</a>',
  'page_id' => 1043, 1044, 1045, // Pass a page ID if you want to download the PDF for another page
);
$pdf = $modules->get('Pages2Pdf');
echo $pdf->render($options);

 

 

Edit again:

I added a custom pagesize in the mpdf.php file found i the mpdf folder under modules. 

I also solved the multipage problem with another template. 🙂

Edited by gottberg
Found the answers

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Anssi
      A simple module to enable easy navigation between the public and the admin side of the site. After installation a green bar will appear to the upper side of the screen, containing a few navigation elements and displaying the PW version number.
      Heavily inspired by @apeisa's great AdminBar (Thanks!). I needed a bit simpler tool for my projects and as a result, this was made. Available on GitHub .

    • By Sebi
      I've created a small module which lets you define a timestamp after which a page should be accessible. In addition you can define a timestamp when the release should end and the page should not be accessable any more.
      Github: https://github.com/Sebiworld/PageAccessReleasetime
      Usage
      PageAccessReleasetime can be installed like every other module in ProcessWire. Check the following guide for detailed information: How-To Install or Uninstall Modules
      After that, you will find checkboxes for activating the releasetime-fields at the settings-tab of each page. You don't need to add the fields to your templates manually.
      Check e.g. the checkbox "Activate Releasetime from?" and fill in a date in the future. The page will not be accessable for your users until the given date is reached.
      If you have $config->pagefileSecure = true, the module will protect files of unreleased pages as well.
      How it works
      This module hooks into Page::viewable to prevent users to access unreleased pages:
      public function hookPageViewable($event) { $page = $event->object; $viewable = $event->return; if($viewable){ // If the page would be viewable, additionally check Releasetime and User-Permission $viewable = $this->canUserSee($page); } $event->return = $viewable; } To prevent access to the files of unreleased pages, we hook into Page::isPublic and ProcessPageView::sendFile.
      public function hookPageIsPublic($e) { $page = $e->object; if($e->return && $this->isReleaseTimeSet($page)) { $e->return = false; } } The site/assets/files/ directory of pages, which isPublic() returns false, will get a '-' as prefix. This indicates ProcessWire (with activated $config->pagefileSecure) to check the file's permissions via PHP before delivering it to the client.
      The check wether a not-public file should be accessable happens in ProcessPageView::sendFile. We throw an 404 Exception if the current user must not see the file.
      public function hookProcessPageViewSendFile($e) { $page = $e->arguments[0]; if(!$this->canUserSee($page)) { throw new Wire404Exception('File not found'); } } Additionally we hook into ProcessPageEdit::buildForm to add the PageAccessReleasetime fields to each page and move them to the settings tab.
      Limitations
      In the current version, releasetime-protected pages will appear in wire('pages')->find() queries. If you want to display a list of pages, where pages could be releasetime-protected, you should double-check with $page->viewable() wether the page can be accessed. $page->viewable() returns false, if the page is not released yet.
      If you have an idea how unreleased pages can be filtered out of ProcessWire selector queries, feel free to write an issue, comment or make a pull request!
    • By David Karich
      Thanks to the great Pro module "RepeaterMatrix" I have the possibility to create complex repeater items. With it I have created a quite powerful page builder. Many different content modules, with many more possible design options. The RepeaterMatrix module supports the cloning of items, but only within the same page. Now I often have the case that very design-intensive pages and items are created. If you want to use this module on a different page (e.g. in the same design), you have to rebuild each item manually every time.
      With this proof of concept I have created a module which adds the feature to copy a repeater item to the clipboard so that you can paste this item to another page with the same repeater field. The module has been developed very rudimentarily so far. It is currently not possible to copy nested items. There is also no check of Min/Max. You can also only copy items that have the same field on different pages. And surely you can solve all this more elegantly with AJAX. But personally I lack the deeper understanding of the repeaters. Also missing on the Javascript side are event triggers for the repeaters, which would make it easier. Like e.g. RepeaterItemInitReady or similar.
      it would be great if @ryan would implement this functionality in the core of RepeaterMatrix. I think he has better ways to implement this. Or what do you think, Ryan?
      Everybody is welcome to work on this module and improve it, if it should not be integrated into the matrix core. Therefore I put it for testing and as download on GitHub: https://github.com/FlipZoomMedia/InputfieldRepeaterMatrixDublicate
      You can best see the functionality in the screencast: 
       
    • By anderson
      Hi,
      Please take a look at this:
      https://templatemag.com/demo/Good/
      The upper nav bar, including dropdowns like "pages" and "portfolios", what do you call this whole thing? At first I guess it's called "dropdown nav bar", but seems not.
      AND of course, what's the simplest way/module to achieve this in PW?
      Thanks in advance.
    • By Sebi2020
      Hey, I'm new and I created a simple module for tagging pages because I didn't found a module for it (sadly this is not a core feature). This module is licensed under the GPL3 and cames with absolutly no warranty at all. You should test the module before using it in production environments. Currently it's an alpha release. if you like the module or have ideas for improvements feel free to post a comment. Currently this fieldtype is only compatible with the Inputfield I've created to because I haven't found  an Inputfield yet, that returns arrays from a single html input.
      Greetings Sebi2020
      FieldtypeTags.zip.asc
      InputfieldTagify.zip
      InputfieldTagify.zip.asc
      FieldtypeTags.zip