Jump to content

RockPdf - mPDF helper module


Recommended Posts

@dotnetic  Yes as it looks, the browser seems to render the page correctly (I can't find any errors at least in "tracy" and in Chrome "DevTools").

My error that comes looks like this:

(first one = Chrome  // second one = Edge)

Chrome.png.c62910f2ff5bf1e157ec2ad8f9586e00.png       Edge.png.869d2df667eb6ec1485c9b78d44bb98e.png

Link to comment
Share on other sites

I've had this error sometimes and it was due to a broken pdf (don't know the reason). I don't understand why you want to use markup regions for rendering HTML of the pdf?? Are you trying to render a regular page HTML as PDF?? I don't think that's a good idea. In a regular HTML page you have lots of code that mPDF will at least not understand and in the worst case will break your pdf. So I'd recommend throwing custom HTML to mPDF instead of regular page markup. You'll have a lot more control over your pdf and a lot less troubles.

Link to comment
Share on other sites

2 hours ago, bernhard said:

I don't understand why you want to use markup regions for rendering HTML of the pdf??

you misunderstood me then, i don't want to use markup regions to render html.
I just thought that because I use the template "Regular" and this is based on markup regions, it is probably because of that? Because the same code works for another project where I have chosen a direct output. See in this thread on page 2.

I will shown below my actual structure....


2 hours ago, bernhard said:

Are you trying to render a regular page HTML as PDF??

actual in my output-pdf.php File I have only this code

$pdf = $modules->get('RockPdf');
$pdf->set('SetHeader', 'This is my header text');
$pdf->write('Hello World ' . date('H:i:s'));
$pdf->write('<!-- my custom comment -->');
// Output
$pdf->show(); // to directly show your file in the browser

so I think if I understood the question correctly, the answer is no?


ok maybe it's easier if i just post my code to show what i'm trying to do




(with activated URL segments in the backend to the "management.php" template)

// Login protection for this page by LoginRegisterPro
if($user->isLoggedin() != true) $session->redirect($config->urls->root.'user/', false);

// Checking the authorization to display the administration page
if($user->hasRole("editor") != true) $session->redirect($config->urls->root, false);

if(strlen($input->urlSegment2)) throw new Wire404Exception();

switch($input->urlSegment1) {
	case '':

		// Output to the content-body ?>
		<div id='content-body'>

			<? // The following code will later control the content that will appear on the PDF ?>

			Please select an entry:<br>
			<form class="uk-form-stacked" action="<?=$page->url;?>pdf/" target='_new' method="post">
				<input type="hidden" name="check" value="PDFdruck">
				<div class="uk-margin">
					<div class="uk-form-controls">
						<select class="uk-select" id="form-stacked-select" name="assignment"><?
							foreach($pages->find("template=lesson, date_from<=today, sort=-date_from, sort=-date_time") as $lessonID){
								echo"<option value='". $lessonID->id ."'>". $lessonID->date_from ." ". $lessonID->date_time ." clock</option>";
							} ?>
				<input type="submit" class="uk-button uk-button-secondary uk-button-small" value="Output status as PDF">

		<!-- content-body -->



	case 'pdf':
		// Display PDF in Browser
		include 'pdf.php';


		// Anything else? Throw a 404
		throw new Wire404Exception();



actual for testing (but even that unfortunately does not work...)


 * Outputs a PDF for independent printing
 * Version 2021-02-xx

// Code for the creation of a PDF
$pdf = $modules->get('RockPdf');
$pdf->set('SetHeader', 'This is my header text');

$pdf->write('Hello World ' . date('H:i:s'));
$pdf->write('<!-- my custom comment -->');

// Output
$pdf->show(); // to directly show your file in the browser


And that's it, with these specifications come the errors from above....



Link to comment
Share on other sites

I'd suggest the following:

First, disable markup regions to confirm that it works when markup regions are disabled. Then enable markup regions and to this:

// replace this
include 'pdf.php';

// by that:
echo "include PDF here";

Then load your page that should create the PDF and inspect the HTML (right click -> show sourcecode). What does the source code look like?

Link to comment
Share on other sites

  • 2 weeks later...
On 2/21/2021 at 12:14 PM, dotnetic said:

Your example pdf.php looks absolutely fine. Please try to save the PDF file via $pdf->save() or $pdf->download() and then take a look if the PDF is generated.


I have tried and the result is that 
$pdf->show() => does not work
$pdf->download() => does not work
$pdf->save() => works, puts the correctly generated PDF on the server

so it seems to be rather a problem with the output method "markup regions" which I use, respectively that I still have a wrong code structure here or?


On 2/22/2021 at 8:53 AM, bernhard said:

I'd suggest the following:

First, disable markup regions to confirm that it works when markup regions are disabled. Then enable markup regions and to this:

// replace this
include 'pdf.php';

// by that:
echo "include PDF here";

Then load your page that should create the PDF and inspect the HTML (right click -> show sourcecode). What does the source code look like?

Thanks bernhard, I went through the points one by one
1. I deactivate markup regions in config.php => output in browser works now! (However, the design no longer fits)

2a. I enable markup regions again and test the change from above (I'm not quite sure now if I should really just put the "echo" in the "case 'pdf': "? I do it, and it outputs my design (up to the header, then a white body, and the footer again at the bottom). The only thing it outputs to me at the bottom of the pw-region-debug line is "No regions" and the time of generation, nothing else.

2b. I interpret your echo to mean that I should paste the code from my pdf.php file here instead of the include command. Unfortunately the result is again the same as above with dotnetic's suggestion. The only code that works to create a PDF is save().

3. "... what does the source code look like?" => Unfortunately there is no real HTML code to look at or parse (except for the one in point 2a, but there it doesn't process anything....) so I can't share anything.

Sorry if I'm a bit clumsy here.... I am therefore very grateful for any help.

Link to comment
Share on other sites

  • 1 month later...

Hi @bernhard "rockpdf" works just fine for my needs but I still have two little problems:

1. I already have a little form with takes a few inputs (text values) which get nicely saved too when the pdf is generated and saved with "rockpdf" on the server sending me an email. I only do not know how to attach the output.pdf before submitting the email form. May you can help?

2. Not so important right know for me but I also realized "$pdf->show() => does not work"  like @Ralf mentioned just above does not work for me either on a very minimal example.

Link to comment
Share on other sites

Thanks @bernhard for the link but there is still a problem for me, because:

1. If use the examples of the provided link it works fine for sending an email with $m->... but I do not know how to save the pdf this way and therefore no pdf-file is attached

  If I use something like $pdf->save() I get a failure which tells me "... not allowed in this context ..."

2. Could may provided just very basic example code how that

$pdf->... in your module works together with $m->... you provided in the link above?

All I need would be: A pdf created by RockPdf which gets send as an attachment by $m->... (the link you provided ... )



Link to comment
Share on other sites

It's all in the docs:


Then simply use the path of the pdf as path of the attachment:

$file = $pdf->save();

$mail = new WireMail();


Link to comment
Share on other sites

  • 1 month later...

Hi to everybody!

I found this useful module and it works fine on desktop (either pc and mac, Chrome/Safari/Opera/FireFox/Vivaldi and IE), but sometimes I've encountered different behaviours on mobile (tested on Android and iOs, with Chrome, Firefox, Opera, and Safari).

Briefly, I built an html table in delayed output (a race ranking, one for each different race pages), I collect it into a variable and passed it throug a $_SESSION index to another page where it's grabbed with a ob_start()/ob_get_contents()/ob_end_clean() statement (no echos are present out of this one ob_start/ob_end).

Despite the desktop pdf output it's ok (I can show()/save()/download() the files and open them with Acrobat, and into docs properties I found each custom setting, e.g. title, author, application and so on) on mobile, instead, I encountered two kind of issues:

1) Most of  times, in Chrome, I was alerted of a non valid file, or FireFox it's not able to save pdf file.
2) Some times the file is outputted also on mobile and it's perfectly readble, but on save and on open by Acrobat App I found the content empty with the notice of the $_SESSION['nameofindex'] undefined.

N.B. Same results also calling directly mPdf after RockPdf and setting it's proper methods.
No problems with a "static" html code passed to the write() method, but I'm getting crazy figuring why it works fine on desktop and not on mobile (or it's ok also on mobile, but can't save a correct file) with $_SESSION.

Does anyone encontered same kinds of these strange behaviours?

Any suggestion about that?


Many thanks in advance.


Link to comment
Share on other sites

  • 3 weeks later...
On 9/14/2020 at 9:28 AM, bernhard said:

Thx @axelino and welcome to the forum 🙂 

I tried to test the library quickly but could not make it work. Could you please provide a PR and usage instructions for the readme so that I can check it quickly? Then I'm happy to add it to the module 🙂 

Hello @bernhard, sorry it took a little longer but I just submitted the Pull-Request.
Please take a look at it and let me know if further adjustments or info is needed.

Thank you! 🙂

Link to comment
Share on other sites

  • 4 weeks later...
1 hour ago, tires said:

I just want to have a simple "download this page as pdf" button on my page.

Why not just use the browser features with @media print in the css?

Link to comment
Share on other sites

13 minutes ago, MarkE said:

Why not just use the browser features with @media print in the css?

I am still using a css with "@media print".
What browser feature do you mean?

Link to comment
Share on other sites

  • 4 weeks later...
On 7/21/2021 at 12:18 AM, tires said:

I want to offer a download function to the website visitors ... not only for myself.

Is there really no way to get a simple "download as pdf" button?

Link to comment
Share on other sites

Hi @tires

Of course you can do that! See this example:

Place this in site/ready.php (with a current dev version of PW supporting url hooks - otherwise you need to create a custom endpoint for generating the pdf. Or you could use url segments and an if-statement as well):

$wire->addHook("/pdf", function($event) {
  $pdf = $event->modules->get('RockPdf');
  $pdf->write('Hello World');

Then add a button to your HTML template file:

<a href="/pdf">Your button/link label</a>

The content and rendering of the PDF is totally up to you.

  • Like 1
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
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Similar Content

    • By MarkE
      This fieldtype and inputfield bundle was built for storing measurement values within a field, rendering them in a variety of formats and converting them to other units or otherwise modifying them via the API.
      The API consists of a number of predefined functions, some of which include...
      render() for rendering the measurement object, valueAs() for converting the value to another unit value, convertTo() for converting the whole measurement object to different units, and add() and subtract() for for modifying the stored value by the value (converted as required) in another measurement. In the admin the inputfield includes a checkbox (which can be optionally disabled) for converting values on page save. For an example if a value was typed in as centimeters, the unit was changed to metres, and the page saved with this checkbox selected, said value would be automatically converted so that e.g. 170 cm becomes 1.7 m.

      A simple length field using Fieldtype Measurement and Inputfield Measurement.
      Combination units (e.g. feet and inches) are also supported.
      Please note that this module is 'proof of concept' at the moment - there are limited units available and quite a lot of code tidying to do. More units will be added shortly.
      See the GitHub at https://github.com/MetaTunes/FieldtypeMeasurement for full details and updates.
    • By tcnet
      File Manager for ProcessWire is a module to manager files and folders from the CMS backend. It supports creating, deleting, renaming, packing, unpacking, uploading, downloading and editing of files and folders. The integrated code editor ACE supports highlighting of all common programming languages.

      This module is probably the most powerful module. You might destroy your processwire installation if you don't exactly know what you doing. Be careful and use it at your own risk!
      ACE code editor
      This module uses ACE code editor available from: https://github.com/ajaxorg/ace

      This module uses the JavaScript dragscroll available from: http://github.com/asvd/dragscroll. Dragscroll adds the ability to drag the table horizontally with the mouse pointer.
      PHP File Manager
      This module uses a modified version of PHP File Manager available from: https://github.com/alexantr/filemanager
    • By tcnet
      This module implements the website live chat service from tawk.to. Actually the module doesn't have to do much. It just need to inserted a few lines of JavaScript just before the closing body tag </body> on each side. However, the module offers additional options to display the widget only on certain pages.
      Create an account
      Visit https://www.tawk.to and create an account. It's free! At some point you will reach a page where you can copy the required JavaScript-code.

      Open the module settings and paste the JavaScript-code into the field as shown below. Click "Submit" and that's all.

      Open the module settings
      The settings for this module are located int the menu Modules=>Configure=>LiveChatTawkTo.

    • By tcnet
      Session Viewer is a module for ProcessWire to list session files and display session data. This module is helpful to display the session data of a specific session or to kick out a logged in user by simply delete his session file. After installation the module is available in the Setup menu.

      The following conditions must be met for the module to work properly:
      Session files
      Session data must be stored in session files, which is the default way in ProcessWire. Sessions stored in the database are not supported by this module. The path to the directory where the session files are stored must be declared in the ProcessWire configuration which is by default: site/assets/sessions.
      Serialize handler
      In order to transform session data easier back to a PHP array, the session data is stored serialized. PHP offers a way to declare a custom serialize handler. This module supports only the default serialize handlers: php, php_binary and php_serialize. WDDX was dropped in PHP 7.4.0 and is therefore not supported by this module as well as any other custom serialize handler. Which serialize handler is actually used you can find out in the module configuration which is available under Modules=>Configure=>SessionViewer.

      Session data
      The session data can be displayed in two different ways. PHP's default output for arrays print_r() or by default for this module nice_r() offered on github: https://github.com/uuf6429/nice_r. There is a setting in the module configuration if someone prefers print_r(). Apart from the better handling and overview of the folded session data the output of nice_r() looks indeed nicer.

      ProcessWire module directory
    • By Robin S
      Repeater Easy Sort
      Adds a compact "easy-sort" mode to Repeater and Repeater Matrix, making those fields easier to sort when there are a large number of items.
      The module also enhances Repeater Matrix by allowing a colour to be set for each matrix type. This colour is used in the item headers and in the "add new" links, to help visually distinguish different matrix types in the inputfield.
      A Repeater field

      A Repeater Matrix field with custom header colours

      Easy-sort mode
      Each Repeater/Matrix item gets an double-arrow icon in the item header. Click this icon to enter easy-sort mode.
      While in easy-sort mode:
      The items will reduce in width so that more items can be shown on the screen at once. The minimum width is configurable in the field settings. Any items that were in an open state are collapsed, but when you exit easy-sort mode the previously open items will be reopened. You can drag an item left/right/up/down to sort it within the items. The item that you clicked the icon for is shown with a black background. This makes it easier to find the item you want to move in easy-sort mode. You can click an item header to open the item. An "Exit easy-sort mode" button appears at the bottom of the inputfield. Configuration
      In the field settings for Repeater and Repeater Matrix fields you can define a minimum width in pixels for items in easy-sort mode. While in easy-sort mode the items will be sized to neatly fill the available width on any screen size but will never be narrower than the width you set here.
      In the field settings for Repeater Matrix you can define a custom header colour for each matrix type using an HTML "color" type input. The default colour for this type of input is black, so when black is selected in the input it means that no custom colour will be applied to the header.
      The easy-sort mode is only possible on Repeater/Matrix fields that do not use the "item depth" option.
  • Create New...