Jump to content

Pages2Pdf


Wanze

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

 

Link to comment
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

Link to comment
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

Link to comment
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.

 

Link to comment
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.

Link to comment
Share on other sites

  • 2 weeks later...

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).

Link to comment
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.

Link to comment
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;
}

 

Link to comment
Share on other sites

  • 2 months later...

@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}\">";

 

Link to comment
Share on other sites

  • 1 month later...
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
Link to comment
Share on other sites

  • 1 month later...
  • 1 month later...

@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.

Link to comment
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.

Link to comment
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 ?

Link to comment
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
Link to comment
Share on other sites

  • 1 month later...

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
Link to comment
Share on other sites

  • 2 months later...

Hi

I have a sudden problem for pdf creation. Do I just have to increased memory? I change recently PHP version to 7.1, I don't know if it's related. However, my developpement server is 7.2 and I don't have this error.

Thanks

 

Allowed memory size of 33554432 bytes exhausted (tried to allocate 176128 bytes) search►

File: .../httpdocs/site/modules/WirePDF/WirePDF.module:76

76:     require_once(\ProcessWire\wire('files')->compile(dirname(\ProcessWire\wire("config")->paths->root . 'site/modules/WirePDF/WirePDF.module') . '/mpdf/mpdf.php',array('includes'=>true,'namespace'=>true,'modules'=>false,'skipIfNamespace'=>false)));
Link to comment
Share on other sites

  • 3 weeks later...

I love this module and it's perfect for generating reports and things for users. What I'd like to know is how I can get my pages2pdf template to also save a pdf file on the server, as well as sending it as a download to the user. Certain of these pdfs are of general interest and I'd like to keep a current copy sitting in a directory. Thanks.

Link to comment
Share on other sites

  • 4 months later...
On 2/19/2018 at 5:04 PM, flydev said:

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

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

 

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 :

 

Edit:   fixed by replacing mpdf with the version 6.1

How to replace ? Ive downloaded the latest mpdf but which files i have to replace in the Modules Folder ? 

Link to comment
Share on other sites

46 minutes ago, iNoize said:

How to replace ? Ive downloaded the latest mpdf but which files i have to replace in the Modules Folder ? 

Hi @iNoize

inside the Pages2Pdf folder module, rename the folder mpdf to mpdf.old then paste the folder mpdf-master downloaded from Github inside the Pages2Pdf folder and rename it to mpdf; Refresh the module.

That it.

 

FYI: This workaround worked without any issue with mPDF 6.1.0 in 2018. 

Edited by flydev
version
Link to comment
Share on other sites

22 hours ago, flydev said:

Hi @iNoize

inside the Pages2Pdf folder module, rename the folder mpdf to mpdf.old then paste the folder mpdf-master downloaded from Github inside the Pages2Pdf folder and rename it to mpdf; Refresh the module.

That it.

 

FYI: This workaround worked without any issue with mPDF 6.1.0 in 2018. 

Thanks now it works Which PHP Version schould I use ? I I want the 7.3  I have to take the latest mpdf ?? 

EDIT: Have stiill problems. If I edit something in the default_templates the Module dont use the new changes ? 
Something with cache or how can i  change this ? Also tried to delete the  module folder in the cache but where the module take the basic changes again ? 

Link to comment
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
×
×
  • Create New...