bbeer Posted April 22, 2022 Share Posted April 22, 2022 Hi teppo we use RockPDF Version 2.0.5 Link to comment Share on other sites More sharing options...
Luigi Posted September 1, 2022 Share Posted September 1, 2022 I'm trying to implement this module at the moment and I also have the problem with the download() and the show() function in my existing site. save() is working fine. I tried it in a new installation, too and there it worked fine with all three functions. I took a look into the generated PDF files and I found the problem. The module adds the HTML Code from the page to the pdf file when using download() and show(). This does not happen with save() I tried to circumvent this with using the save() and then with this code to start the download: if (file_exists($file)) { header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="'.$page->title.'.pdf"'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($file)); readfile($file); exit; } With this code, the HTML code is also added to the PDF file but the HTML is not in the PDF File when it's saved on the server with save(). I don't know how to prohibit that My solution for now is to implement the code for the PDF download before any oder HTML code is added which works for me. But If anybody knows how to solve this problem that would be great. Link to comment Share on other sites More sharing options...
wbmnfktr Posted January 16, 2023 Share Posted January 16, 2023 In case you are looking for a nice and easy replacement for Pages2PDF as you might face problems with it due to PHP 8 - this might help you to get started and helped me today to get a site up and running again. Thanks to @bernhard for this module. <?php namespace ProcessWire; // file: templates/invoice.php $pdf = $modules->get('RockPdf'); $pdf->settings([ 'mode' => 'utf-8', 'format' => [210, 297], 'img_dpi' => 300, 'default_font' => 'DejaVuSans', ]); // Pseudo header $pdf->write(wireRenderFile('pages2pdf/_header.php')); // Footer $pdf->set('SetHTMLFooter', wireRenderFile('pages2pdf/_footer.php')); // Body content $pdf->write(wireRenderFile('pages2pdf/invoice.php')); // Styleshee $stylesheet = file_get_contents('pages2pdf/pdf.css'); $pdf->write("<style>$stylesheet</style>"); // Actions $pdf->show(); In this example I re-use my already existing pages2pdf-templates and even CSS. It's a super simple PDF, so I really don't have to deal with page margins and such in this case. So you might want to read the docs of mPDF and RockPDF to get this working in your project. There is a lot more you can do in terms of settings and such which can be found in this post for example: 4 Link to comment Share on other sites More sharing options...
Luigi Posted January 19, 2023 Share Posted January 19, 2023 On 1/16/2023 at 8:15 PM, wbmnfktr said: In case you are looking for a nice and easy replacement for Pages2PDF as you might face problems with it due to PHP 8 - this might help you to get started and helped me today to get a site up and running again. Thanks to @bernhard for this module. <?php namespace ProcessWire; // file: templates/invoice.php $pdf = $modules->get('RockPdf'); $pdf->settings([ 'mode' => 'utf-8', 'format' => [210, 297], 'img_dpi' => 300, 'default_font' => 'DejaVuSans', ]); // Pseudo header $pdf->write(wireRenderFile('pages2pdf/_header.php')); // Footer $pdf->set('SetHTMLFooter', wireRenderFile('pages2pdf/_footer.php')); // Body content $pdf->write(wireRenderFile('pages2pdf/invoice.php')); // Styleshee $stylesheet = file_get_contents('pages2pdf/pdf.css'); $pdf->write("<style>$stylesheet</style>"); // Actions $pdf->show(); In this example I re-use my already existing pages2pdf-templates and even CSS. It's a super simple PDF, so I really don't have to deal with page margins and such in this case. So you might want to read the docs of mPDF and RockPDF to get this working in your project. There is a lot more you can do in terms of settings and such which can be found in this post for example: Expand I'm already using it and I like it a lot more than pages2pdf. The download function isn't working for me but I was able to circumvent that problem with a little bit of extra code to create and then to start the download of the pdf. 1 Link to comment Share on other sites More sharing options...
gebeer Posted January 20, 2023 Share Posted January 20, 2023 @bernhard could you please add PHP 8 as dependency for the latest Version 2.1.0. Thank you. Was updating a website today that still runs on 7.4 and got composer errors because mpdf requires PHP>=8.0. 2 Link to comment Share on other sites More sharing options...
bernhard Posted January 20, 2023 Author Share Posted January 20, 2023 Sure, done! Thx for the input ? 3 Link to comment Share on other sites More sharing options...
Jon Posted January 24, 2024 Share Posted January 24, 2024 Iam using the following code to generate my PDF in ready.php however after adding the pdf->settings I get a 500 error, Any ideas? $pdf = $modules->get('RockPdf'); $pdf->settings([ 'fontdata' => (new \Mpdf\Config\FontVariables())->getDefaults()['fontdata'] + [ "far" => [ 'R' => "fa-regular-400.ttf", 'I' => "fa-regular-400.ttf", ], ], ]) $pdf->addFont(['Roboto-Regular' => 'site/templates/fonts/Roboto-Regular.ttf',]) ->load("site/templates/test-document.php", ['page' => $pages->get(1053),]) ->save(preview: true); Link to comment Share on other sites More sharing options...
gebeer Posted January 24, 2024 Share Posted January 24, 2024 On 1/24/2024 at 1:00 AM, Jon said: Iam using the following code to generate my PDF in ready.php however after adding the pdf->settings I get a 500 error, Any ideas? $pdf = $modules->get('RockPdf'); $pdf->settings([ 'fontdata' => (new \Mpdf\Config\FontVariables())->getDefaults()['fontdata'] + [ "far" => [ 'R' => "fa-regular-400.ttf", 'I' => "fa-regular-400.ttf", ], ], ]) $pdf->addFont(['Roboto-Regular' => 'site/templates/fonts/Roboto-Regular.ttf',]) ->load("site/templates/test-document.php", ['page' => $pages->get(1053),]) ->save(preview: true); Expand EDIT: which version of RockPdf are you using, free or new commercial (https://www.baumrock.com/en/processwire/modules/rockpdf/)? What is the error message your getting? Not sure you can invoke a new instance of \Mpdf\Config\FontVariables() and then use the getDefaults() method right away. In the mpdf docs they do it like $defaultConfig = (new Mpdf\Config\ConfigVariables())->getDefaults(); $fontDirs = $defaultConfig['fontDir']; $defaultFontConfig = (new Mpdf\Config\FontVariables())->getDefaults(); $fontData = $defaultFontConfig['fontdata']; $mpdf = new \Mpdf\Mpdf([ 'fontDir' => array_merge($fontDirs, [ __DIR__ . '/custom/font/directory', ]), 'fontdata' => $fontData + [ // lowercase letters only in font key 'frutiger' => [ 'R' => 'Frutiger-Normal.ttf', 'I' => 'FrutigerObl-Normal.ttf', ] ], 'default_font' => 'frutiger' ]); 1 Link to comment Share on other sites More sharing options...
Jon Posted January 24, 2024 Share Posted January 24, 2024 Thanks gebeer, I am using the latest pro version. It works ok with the below code however, if I remove the addFont() line, it results in a 500 error. $pdf = $modules->get('RockPdf'); $pdf->settings([ 'mode' => 'utf-8', 'fontdata' => [ 'roboto' => [ 'R' => 'Roboto-Regular.ttf', 'I' => 'Roboto-Regular.ttf', ], 'robotothin' => [ 'R' => 'Roboto-Thin.ttf', 'I' => 'Roboto-Thin.ttf', ], 'far' => [ 'R' => "fa-regular-400.ttf", 'I' => "fa-regular-400.ttf", ], ], 'default_font' => 'roboto' ]); $pdf->addFont(['Roboto-Regular' => 'site/templates/fonts/Roboto-Regular.ttf',]) ->load("site/templates/test.php", ['page' => $pages->get(1053),]) ->save(preview: true); } Link to comment Share on other sites More sharing options...
gebeer Posted January 25, 2024 Share Posted January 25, 2024 On 1/24/2024 at 11:27 PM, Jon said: It works ok with the below code however, if I remove the addFont() line, it results in a 500 error. Expand What does the error say? Have you turned on debug mode, are you using tracy debugger? Have you lookes in the error logs? 1 Link to comment Share on other sites More sharing options...
bernhard Posted January 25, 2024 Author Share Posted January 25, 2024 On 1/24/2024 at 11:27 PM, Jon said: Thanks gebeer, I am using the latest pro version. Expand Hey @Jon thx for the purchase and sorry for the trouble. I was confused because you posted your question in the old thread with old code. I'll update this threads title to make it more obvious! Anyways your code looks still strange. Why are you defining your fonts twice? Please have a look at the docs (https://www.baumrock.com/en/processwire/modules/rockpdf/docs/fonts/) and use one of the listed fonts exactly like shown in the examples. Once that works try your own font. If it breaks then, share your code and also your font (if possible) so that I can try to reproduce the problem. Thx PS: Where is that code that you posted? It has an additional bracket at the end... 1 Link to comment Share on other sites More sharing options...
Jon Posted January 27, 2024 Share Posted January 27, 2024 Thanks Both, I had trouble getting font awesome icons to work using the doc and found your earlier example in this thread. In turn, it seems I have ended up with old and new code. I have resolved the issue by following the docs and font awesome icons are now showing correctly. Code below for reference $pdf = $modules->get('RockPdf'); $pdf ->addFont(['R' => 'site/templates/fonts/fa-regular-400.ttf', 'I' => 'site/templates/fonts/fa-regular-400.ttf', 'B' => 'site/templates/fonts/fa-regular-400.ttf', ], 'far') ->addFont(['R' => 'site/templates/fonts/Roboto-Regular.ttf', 'B' => 'site/templates/fonts/Roboto-Black.ttf', ], 'roboto') ->load("site/templates/change_management.php") ->save(preview: true); 2 Link to comment Share on other sites More sharing options...
bernhard Posted January 27, 2024 Author Share Posted January 27, 2024 On 1/27/2024 at 1:02 AM, Jon said: I had trouble getting font awesome icons to work using the doc and found your earlier example in this thread. In turn, it seems I have ended up with old and new code. I have resolved the issue by following the docs and font awesome icons are now showing correctly. Code below for reference Expand Hey @Jon sorry for the trouble, but I have a little present for you ? v1.5.0 adds support for directly using fontawesome icon markup like <i class="fa-brands fa-youtube"></i> The release is less than 10 minutes young and ready for download at https://www.baumrock.com/en/releases/rockpdf/ Docs are already there as well: https://www.baumrock.com/en/processwire/modules/rockpdf/docs/fontawesome/ Hope that helps you and many others ? 3 Link to comment Share on other sites More sharing options...
Jon Posted January 28, 2024 Share Posted January 28, 2024 @bernhard That's brilliant. Thank you for the update! 1 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