bernhard Posted June 22, 2018 Share Posted June 22, 2018 Attention: This is the thread for the archived open source version of RockPdf. This module is neither developed any further nor maintained nor will it get any fixes. Modules Directory: https://modules.processwire.com/modules/rock-pdf/ Download & Docs: https://github.com/BernhardBaumrock/RockPDF Please see the new version here: 13 4 Link to comment Share on other sites More sharing options...
szabesz Posted June 25, 2018 Share Posted June 25, 2018 Featured in ProcessWire Weekly #215. Thanks a lot for sharing @bernhard! 1 Link to comment Share on other sites More sharing options...
Mackski Posted July 5, 2018 Share Posted July 5, 2018 Thanks Benhard for this module, small modification i've updated the save() function to allow various output types as stated: https://mpdf.github.io/reference/mpdf-functions/output.html /* ########## output ########## */ /** * save output to: local file ($dest = "FILE") download ($dest = "DOWNLOAD") inline to browser (default - $dest = "INLINE") */ public function save($filename = 'output.pdf', $dest = "INLINE") { if(!$filename) $filename = 'output.pdf'; if($dest == "FILE") $filename = $this->getAbsolute($filename); // save to disk $this->mpdf->Output($filename, constant('\Mpdf\Output\Destination::'.$dest)); } // stream to browser $pdf->save(); $pdf->save('filename.pdf') $pdf->save('filename.pdf,'INLINE); // force download $pdf->save('myfile.pdf','DOWNLOAD'); // save locally $pdf->save('myfileserver.pdf','FILE'); 3 Link to comment Share on other sites More sharing options...
flydev Posted August 11, 2018 Share Posted August 11, 2018 You should add this module to the modules directory , it rocks ? 3 Link to comment Share on other sites More sharing options...
bernhard Posted August 11, 2018 Author Share Posted August 11, 2018 Thx @Mackski I've done a slightly different approach: You now have the option between three methods: save() show() download() The save() method will return the resulting file urls and paths on success: @flydev thx I've added it to the modules directory ? 7 Link to comment Share on other sites More sharing options...
renobird Posted August 28, 2018 Share Posted August 28, 2018 bernhard, I've been working on a project with mPDF and there are lots of variants to the PDF content and how they are saved/downloaded, etc... It got me thinking about making a PW helper module to make things a little more sane to deal with. I decided to see how others were dealing with PDF creation within ProcessWire, and whaddya know — what I was imagining already exists. Just wanted to say thank you! 5 Link to comment Share on other sites More sharing options...
bernhard Posted August 28, 2018 Author Share Posted August 28, 2018 Thank you! Happy to hear that and glad I could give something back to you, Reno - thanks for all your great contributions ? 4 Link to comment Share on other sites More sharing options...
bernhard Posted September 27, 2018 Author Share Posted September 27, 2018 Updated the module to make sure the filepath exists. I also added an example in the readme how to set a background: 4 Link to comment Share on other sites More sharing options...
ceberlin Posted October 13, 2018 Share Posted October 13, 2018 I have problems printing images embedded into a textarea if the config.php has this setting: $config->pagefileSecure=true ERROR: Could not find image file (.............. /site/assets/files/2922/unterschrift.jpg) The file actually is stored under this path: ............... /site/assets/files/-2922/unterschrift.jpg Link to comment Share on other sites More sharing options...
bernhard Posted October 13, 2018 Author Share Posted October 13, 2018 Thx for reporting! I can have a look next week or maybe you can do a pr or share your investigations until then? Link to comment Share on other sites More sharing options...
charger Posted October 17, 2018 Share Posted October 17, 2018 Did anyone else encounter problems with `show()` and `download()`? If I use them, all I get is blank pages resulting in an invalid PDF. The `save()` function works as expected though. I’m running PW 3.0.98 with PHP 7.1.12 and RockPdf 1.0.1 Link to comment Share on other sites More sharing options...
bernhard Posted October 17, 2018 Author Share Posted October 17, 2018 No problems here. Which Browser? Can you try whether using the original mpdf code works (without using my shortcuts)? Link to comment Share on other sites More sharing options...
charger Posted October 17, 2018 Share Posted October 17, 2018 Latest Chrome/Safari/Firefox on macOS 10.14 show all the same problem. The weird thing is it creates the correct amount of pages in the PDF, they’re just blank. Calling `$mpdf->Output($filename, \Mpdf\Output\Destination::DOWNLOAD);` directly results in the same error. 1 Link to comment Share on other sites More sharing options...
bernhard Posted October 17, 2018 Author Share Posted October 17, 2018 Hey @charger, thx for that info. Could you please check if that is the same in a non-pw setup? I mean creating a php file only for that purpose, importing mpdf, creating the pdf and trying the show() and download() equivalents of mpdf? Link to comment Share on other sites More sharing options...
charger Posted October 17, 2018 Share Posted October 17, 2018 @bernhard download() and show() both work outside of PW. 1 Link to comment Share on other sites More sharing options...
bernhard Posted October 18, 2018 Author Share Posted October 18, 2018 Interesting. I got some mime-type errors in the console from time to time. Maybe that could be the reason? No idea how I should track that down since everything is working fine on my side ? Link to comment Share on other sites More sharing options...
charger Posted October 18, 2018 Share Posted October 18, 2018 What kind of mime-type errors? And how could that be related to PW only but not the webserver or PHP in general? I also just checked it on the webserver (was on localhost before): same problem there. It’s weird that one option would work while the other two wouldn’t. I can’t make sense of it atm. Link to comment Share on other sites More sharing options...
bernhard Posted October 19, 2018 Author Share Posted October 19, 2018 Quote JqueryCore.js?v=1539002242:2 Resource interpreted as Document but transferred with MIME type application/pdf: "http://www.rockcrm.test/site/assets/files/1156/hn2018-029.pdf?modal=panel&pw_panel=1". PW can set the mime type, so I guess it could be related to it. But I've never used this feature, so I don't really have an idea. I also don't have time to look into that atm. Maybe someone is more experienced in this area and can help... Link to comment Share on other sites More sharing options...
bernhard Posted October 19, 2018 Author Share Posted October 19, 2018 Just a note if anybody gets in trouble when creating complex PDFs... It seems that there is some bug related to the tempdir that is created for the pdf. If the PDF takes long to render it can happen that this folder is deleted automatically before the PDF is done. Then you'll get an error. In my case this solved it: $pdf = $modules->get('RockPdf'); $pdf->settings([ 'tempDir' => $this->config->paths->root . 'site/assets/cache/WireTempDir/.RockPdf/test/', ]); For sure just a quickfix, but I'm busy... 2 Link to comment Share on other sites More sharing options...
charger Posted October 20, 2018 Share Posted October 20, 2018 22 hours ago, bernhard said: Just a note if anybody gets in trouble when creating complex PDFs... It seems that there is some bug related to the tempdir that is created for the pdf. If the PDF takes long to render it can happen that this folder is deleted automatically before the PDF is done. Then you'll get an error. In my case this solved it: $pdf = $modules->get('RockPdf'); $pdf->settings([ 'tempDir' => $this->config->paths->root . 'site/assets/cache/WireTempDir/.RockPdf/test/', ]); For sure just a quickfix, but I'm busy... Hmm, that didn’t help on my side. I still see the "Unable to remove" errors in the wire-temp-dir logfile, now they’re just referring to the newly set directory. And yes, these are more complex PDFs, but not overly complex (~3MB). Link to comment Share on other sites More sharing options...
Robin S Posted October 20, 2018 Share Posted October 20, 2018 22 hours ago, bernhard said: If the PDF takes long to render it can happen that this folder is deleted automatically before the PDF is done. FYI, you can set the age the temp directory lives for with the maxAge option: $files->tempDir('RockPdf', ['maxAge' => 600]); // or $files->tempDir('RockPdf', 600); 1 Link to comment Share on other sites More sharing options...
charger Posted October 20, 2018 Share Posted October 20, 2018 23 hours ago, bernhard said: PW can set the mime type, so I guess it could be related to it. But I've never used this feature, so I don't really have an idea. This will not work for me as I generate the PDF if there’s a "pdf" GET parameter found (this is e.g. how https://github.com/wanze/Pages2Pdf handles it as well). That’s why I was pursuing another way meanwhile: the wireSendFile() function (https://github.com/processwire/processwire/blob/master/wire/core/Functions.php#L257, https://github.com/wanze/Pages2Pdf/blob/master/Pages2Pdf.module#L312). Here’s the relevant code from my template file: $inputPdf = $input->get('pdf'); $inputPdfSan = $sanitizer->int($inputPdf); if ($inputPdfSan == 1) { $pdf = $modules->get('RockPdf'); $pdf->settings([ 'tempDir' => $this->config->paths->root . 'site/assets/cache/WireTempDir/.RockPdf/test/', ], 'mode' => 's', 'mirrorMargins' => 1, ]); $mpdf = $pdf->mpdf; $mpdf->WriteHTML('Hello World ' . date('H:i:s')); $filename = $page->name . '-pdf-' . $page->id . '.pdf'; $response = $pdf->save($filename); wireSendFile($response->path, array('forceDownload' => true)); } However, the problem remains: the PDFs do get saved correctly, but when trying to download them (either via wireSendFile() or RockPDF’s download()), they are blank or corrupted. Link to comment Share on other sites More sharing options...
charger Posted October 20, 2018 Share Posted October 20, 2018 20 minutes ago, Robin S said: FYI, you can set the age the temp directory lives for with the maxAge option: $files->tempDir('RockPdf', ['maxAge' => 600]); // or $files->tempDir('RockPdf', 600); Thanks for the hint, wasn’t aware of that. But if the default age for a temp folder is 120 seconds, then that should be plenty of time already. The PDF generation maybe takes around 3 seconds. Link to comment Share on other sites More sharing options...
bernhard Posted October 20, 2018 Author Share Posted October 20, 2018 52 minutes ago, Robin S said: YI, you can set the age the temp directory lives for with the maxAge option: Thx robin I know about that but somehow it didn't work. I need to see why and when that happens, but setting the maxage didn't solve it unfortunately. Link to comment Share on other sites More sharing options...
charger Posted October 22, 2018 Share Posted October 22, 2018 The following line in RockPdf.module.php returns a wrong URL if the PW installation lives in a subdirectory (subdirectory is applied twice): 'httpUrl' => rtrim($this->pages->get(1)->httpUrl, '/') . $url, Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now