Jump to content

Pages2Pdf


Wanze

Recommended Posts

  • 4 weeks later...
3 minutes ago, adrian said:

I just installed this on a site a couple of days ago and got the same error. I took the lazy approach of just adding all the fonts from the mpdf github repo:
https://github.com/mpdf/mpdf/tree/development/ttfonts

Thanks adrian! I've saved this folder for future installations to make it faster. I was certain it was a cache issue but my real issue was webhost related. I fixed it and it works like the charm I knew it would!

(I'm sure I'll be back as I customize these files, but hopefully I'll think through all my possible user-errors first!)

Link to comment
Share on other sites

  • 2 weeks later...

Thanks for the great plugin!

I'm trying to put a piechart in a PDF page. I understand using Javascript is not supported in PDF but with Google Charts it's possible to create an image for print/PDF. So i thought maybe in my template i can first run the Javascript to render an image and use that image in de PDF. This unfortunately doen't work. Is there a way to run some javascript to render an element before the PDF is created?

Link to comment
Share on other sites

do you have some user input or are you creating the pdf completely on the server side (like cronjob)? if you have some user input you could create an image of the chart first (eg on button click) and then post this image to your php script and integrate it in your pdf

Link to comment
Share on other sites

1 hour ago, Timothy de Vos said:

Thanks for the great plugin!

I'm trying to put a piechart in a PDF page. I understand using Javascript is not supported in PDF but with Google Charts it's possible to create an image for print/PDF. So i thought maybe in my template i can first run the Javascript to render an image and use that image in de PDF. This unfortunately doen't work. Is there a way to run some javascript to render an element before the PDF is created?

You would need to store the piechart as image somewhere and use a regular HTML <img> tag to display it in the template of your PDF. Is it possible for Google Charts to store images on the file system? Though a server side app generating the piechart would probably be simpler in this case.

Link to comment
Share on other sites

18 hours ago, bernhard said:

do you have some user input or are you creating the pdf completely on the server side (like cronjob)? if you have some user input you could create an image of the chart first (eg on button click) and then post this image to your php script and integrate it in your pdf

I am able to create the image on a button click but how would I post it to the PDF template. I tried using $.post but when i try to var_dump the $POST in the PDF it returns an empty array.

Link to comment
Share on other sites

5 hours ago, Timothy de Vos said:

I am able to create the image on a button click but how would I post it to the PDF template. I tried using $.post but when i try to var_dump the $POST in the PDF it returns an empty array.

As mentioned in my post, as far as I know, you need to render your image in a regular <img> tag inside the PDF template. This means that you'd need to save the image before on the disk or use a base64 encoded string, though I don't know if the latter works in mpdf.

Link to comment
Share on other sites

Hi @Wanze

I am using the WirePDF module which works great! The only Problem I have is setting the path to a css fille inside the module settings. Somehow the css file didn't get load no matter which path I type in inside the "CSS File" textfield. 

At the moment my code to generate the pdfs looks like this (working):

$pdf = $modules->get('WirePDF');

if($urlpage->template->name == "jobs"){
	$template = wireRenderFile("partials/pdf_layouts/pdf_jobs_template.php", array(
								"urlpage" => $urlpage
							));
}else{
	$template = wireRenderFile("partials/pdf_layouts/pdf_doctors_template.php", array(
								"urlpage" => $urlpage
							));
}

$pdf->markupMain = $template;
$pdf->setTitle($urlpage->title);
$pdf->download($urlpage->title.".pdf", "D");

 

Link to comment
Share on other sites

ok i could make it to work when I remove this from the header of my css file:

@charset "UTF-8";
/* CSS Document */

And also changed the code to this:

$pdf = $modules->get('WirePDF');
$pdf->setTitle($urlpage->title);
$stylesheet = file_get_contents($config->paths->templates. "styles/pdf_styles.css"); // external css
$pdf->WriteHTML($stylesheet,1);
$pdf->WriteHTML($template,2);
$pdf->download($urlpage->title.".pdf", "D");

 

Link to comment
Share on other sites

On 6-12-2016 at 4:45 PM, Wanze said:

As mentioned in my post, as far as I know, you need to render your image in a regular <img> tag inside the PDF template. This means that you'd need to save the image before on the disk or use a base64 encoded string, though I don't know if the latter works in mpdf.

I got it to work! The problem was that I was using $.post in jQuery to sent the data to de PDF template. Since $.post doesn't actually goes to the page i added an extra event to load the page. But by doing this i emptied the $POST session... stupid. 

What i'm doing now is first creating a form and setting the img as value and then submitting the form.

        $("body").append($("<form></form>").attr({ "action": PDFurl, "method": "post", "id" : "postForm" })
            .append($('<input>').attr({ "type": "hidden", "name": "img", "value": imgChart.prop("outerHTML") }))
        ).find("#postForm").submit();

 

Link to comment
Share on other sites

  • 1 month later...

I get this error when trying to output images on the pdf template:

mPDF error: IMAGE Error (URL/TO/IMAGE): Error parsing temporary file image object created with GD library to parse PNG image

I am only using your WirePDF Wrapper.

Greetings Nukro

Link to comment
Share on other sites

  • 4 weeks later...

Hi Wanze,

Thank for your great mosule. I really love it. It works perfectly with English content. But when I write in Thai language, it display question sign like this ???????????? ????? ????.

I tried to follow this forum for a while and uploaded garuda.ttf font for thai language but it still not working.

Where did I miss, how to fix it , please help.

Link to comment
Share on other sites

  • 2 weeks later...

A little help if someone has the same problem: images on develpment site were included, but not on live site.

There is no error or any hint, but only a red "x" as placeholder for the image. Try to convert to base64 string included the image to the PDF. For me it even reduced the filesize :D

$imagedata = file_get_contents( "../assets/img/logo-pdf-invoice.png"); // alternatively specify an URL, if PHP settings allow
$base64Img = "data:image/png;base64," . base64_encode($imagedata);

 

  • Like 2
Link to comment
Share on other sites

Hi @Wanze,

I am trying something like this but am getting into one error. What I am doing is:

$markupMain = wireRenderFile( 'partials/pdf_invoice', [ 'invoice' => $invoice ] );
$pdf->markupMain = $markupMain;

The error I get is this:

PHP Warning: is_file(): File name is longer than the maximum allowed path length on this platform (260): ...

I looked into the WirePDF.module file and found out, that a check on the markup is tested with if/else on this steps:

  1. $markup instanceof TemplateFile?
  2. is_file($markup)?
  3. is_string($markup)?

Of course my markup is a long HTML string, but check on the markup at point 2 comes up with the warning. PDF is generated, so no problem at this end. Maybe I can ignore this?

Oh, and is it possible to update to a newer version of mPDF, so there could be a better PHP 7 compatibility? I tried to just copy the newer version into the folder, but it was not working, so I wonder what to change on the files.

Link to comment
Share on other sites

@godmok

Thanks for the hint on this, I will update this check with a threshold on the string length.

Regarding a newer version of mPDF: Actually the dev brach of the module already contains mPDF 6.1.0, thanks to the work of @gingebaker

However, I didn't find time to test it out yet. I really want to support a more recent mPDF version in the master.

Cheers

 

 

Link to comment
Share on other sites

  • 2 weeks later...

Hello @Wanze and everyone else,

i'm trying to get pages2pdf with @apeisas Padloper. They way I want to use it is:

 

$t = $this->modules->get("PadRender")->getPadTemplate("invoice.php"); # this simply returns a TemplateFile
$t->set("order", $order);
$pdf = $this->modules->get("WirePDF");
$pdf->pageOrientation = 'P';
$pdf->pageFormat = 'A4';
$pdf->markupMain = $t->render();
$pdf->save($this->config->paths->assets.'/pdf/'.$order->rechnungsnummer.'.pdf');

I'm having problems with the images in the template. Only a red "x" is displayed. I tried full httpUrl and even including the base64 data. No success.

Can anyone help out?

Thanks,

thomas

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