Jump to content

[archived] RockPdf - mPDF helper module


bernhard

Recommended Posts

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


 

Spoiler

 

management.php
(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>";
							} ?>
						</select>
					</div>
				</div>
				<input type="submit" class="uk-button uk-button-secondary uk-button-small" value="Output status as PDF">
			</form>

		</div>
		<!-- content-body -->

		<?

	break;

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

	break;

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

?>

 

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

pdf.php


<?
/**
 * 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.

@dotnetic

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

  • 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...
  • 4 weeks later...

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');
  $pdf->download("download-button.pdf");
});

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

  • 8 months later...

Good morning
we have a strange Problem with Safari generating PDF Files. It takes ages and then we get following error.
Safari can't open „https://company.com/de/bedienungsanleitung/manual-output/?pid=3254&amp;pdf=.pdf“ nicht öffnen.  Fehler: „cannot parse response“ (NSURLErrorDomain:-1017)

Things are even more complicated. We generate a smaller PDF with the exact same call without any error.

Any one any idea on this?

Your help is much appreciated!

 

Link to comment
Share on other sites

Hey @bbeer,

Is this related to a specific module, or are you generating PDF with custom code? Asking because a) if it's related to a specific module I can merge this topic with the support thread for that module, and b) if it's custom code, we would have to know a bit more about how you're generating those PDF files.

NSURLErrorDomain:-1017 is an error code that apparently means the browser was unable to parse response. If it works on other browsers it could be a browser bug, or some sort of incompatibility between your PDF generation method / its result and the PDF parser in Safari.

Link to comment
Share on other sites

  • bernhard changed the title to [archived] RockPdf - mPDF helper module

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