Wanze

Pages2Pdf

Recommended Posts

Hi Wanze,

Sorry for the late reply but I have since uninstalled the module and have used a plain 'file' field to solve my problem.

Thank you,

Matt

Share this post


Link to post
Share on other sites

Whoops, Ultra-PEBDAC.

(I was asking about the font issue that adrian kindly resolved below, but my real issue was that I was uploading files to the wrong server - we are in the midst of switching hosts!)

Edited by creativejay
It's Monday.

Share this post


Link to post
Share on other sites
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!)

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
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");

 

Share this post


Link to post
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");

 

Share this post


Link to post
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();

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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 1

Share this post


Link to post
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.

Share this post


Link to post
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

 

 

Share this post


Link to post
Share on other sites

Is there an easy way to remove the space occupied by the header? It's probably me or my setup but I can't seem to remove the space.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

@thomas

Can you show the code how you output the images in the PDF template? It should work fine to use $image->url.

Do you use pagefileSecure by any chance?

Cheers

Share this post


Link to post
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 Macrura
      This is a new module, hope to release soon, which allows extended field descriptions, in currently 2 ways.
      The main feature of the module is that you can have a short description and then a 'more...' link which drops down a longer block of text.
      This is achieved by separating the intro/visible text and the rest with 5 dashes.

      Example setup:

      the 2nd way is if you are using AdminThemeUiKit, you can show extended field instructions in a panel. The content of the panel is edited on a regular PW page. This use case would probably not be that common, but if you had a field that required some extended instructions for how to use, this could be useful; Also, since this allows you to target information and instructions down at the field level, it could reduce the amount of documentation needed on a global level, since it is a lot more context targeted.

    • By netcarver
      Part 1 of a 2 part Module & Service Reveal.
      I'm currently working on a new module: ModuleReleaseNotes that was inspired by the work I originally did on making Ryan's ProcessWireUpgrades module "release" aware. In the end, I decided to ditch the approach I was originally taking and instead work on a module that hooked in to the UpgradeConfirmation dialog and the module edit page.
      Aims
      My aims for this module are as follows...
      Make discovery of a module's changes prior to an upgrade a trivial task. Make breaking changes very obvious. Make reading of a module's support documentation post-install a trivial task. Make module authors start to think about how they can improve the change discovery process for their modules. Make sure the display of information from the module support files/commit messages doesn't introduce a vulnerability. Looking at these in turn...
      Making discovery of a module's changes prior to upgrade a trivial task.
      This is done by adding a "What's changed section" to the upgrade confirmation dialog.  This section takes a best-effort approach to showing what's changed between the installed version and the updated version that's available via the module repository.
      At present, it is only able to talk to github-hosted repositories in order to ask them for the release notes, the changelog file (if present) and a list of commits between the git tag that matches the installed version and the tag matching the latest version.
      It will display the Release Notes (if the author is using the feature), else it will display the commits between the tags (if tagging is used by the module author) else it will show the changelog file (if present) else it will show the latest N commits on the master branch (N, of course, being configurable to your liking.)
      An example of the Github Release Notes pulled in for you, taken from Mike Rockett's TextformatterTypographer Module...

      An example of a tag-to-tag commit list from the same module...

      An example of a changelog - formatted to show just the changes (formatting styles will change)...

      Finally, an example of a fallback list of commits - sorry Adrian ...

       
      Making breaking changes obvious.
      This is currently done by searching for a set of configurable search strings. Later versions may be able to support breaking change detection via use of Semantic Versioning - but this may require some way of signalling the use of this versioning standard on a module-by-module basis.
      For now, then, you can customise the default set of change markers. Here I have added my own alias to the list of breaking change markers and the changes section of the changelog is styled accordingly (these will be improved)...

       
      Make reading of a module's support documentation, post-install, a trivial task.
      This is done by making some of the support files (like the README, CHANGELOG and LICENSE files) readable from the module's information/settings screen. There is an option to control the initial open/closed state of this section...

      Here is Tracy's README file from within the module settings page... 

       
      Make module authors start to think about how they can improve the change discovery process for their modules.
      There are notes in each of the sections displayed on the upgrade confirmation page that help authors use each of the features...

       
      Make sure display of external information doesn't introduce a vulnerability.
      This is an ongoing concern, and is the thing that is most likely to delay or prevent this module's release. Currently, output is formatted either via Markdown + HTML Purifier (if it was originally a Markdown file) or via htmlspecialchars() if it has come from a plaintext file.
       
      Ongoing...
      For now, I've concentrated on integration with GitHub, as most people use that platform to host their code. I know a few people are hosting their repositories with BitBucket (PWFoo comes to mind) and some with GitLab (Mike Rockett?) and I would eventually like to have adaptor implementations for these providers (and perhaps GitKraken) - but for now, GitHub rules and the other hosts are unsupported.
      I hope to have this ready for general release within the next week.
    • By blynx
      Hej,
      A module which helps including Photoswipe and brings some modules for rendering gallery markup. Feedback highly appreciated

      Modules directory: http://modules.processwire.com/modules/markup-processwire-photoswipe
      .zip download: https://github.com/blynx/MarkupProcesswirePhotoswipe/archive/master.zip
      You can add a photoswipe enabled thumbnail gallery / lightbox to your site like this. Just pass an image field to the renderGallery method:
      <?php $pwpswp = $modules->get('Pwpswp'); echo $pwpswp->renderGallery($page->nicePictures); Options are provided like so:
      <?php $galleryOptions = [ 'imageResizerOptions' => [ 'size' => '500x500' 'quality' => 70, 'upscaling' => false, 'cropping' => false ], 'loresResizerOptions' => [ 'size' => '500x500' 'quality' => 20, 'upscaling' => false, 'cropping' => false ], 'pswpOptions' => (object) [ 'shareEl' => false, 'indexIndicatorSep' => ' von ', 'closeOnScroll' => false ] ]; echo $pswp->renderGallery($page->images, $galleryOptions); More info about all that is in the readme: https://github.com/blynx/MarkupProcesswirePhotoswipe
      What do you think? Any ideas, bugs, critique, requests?
      cheers
      Steffen
    • By mtwebit
      Tasker is a module to handle and execute long-running jobs in Processwire. It provides a simple API  to create tasks (stored as PW pages), to set and query their state (Active, Waiting, Suspended etc.), and to execute them via Cron, LazyCron or HTTP calls.
      Creating a task
      $task = wire('modules')->Tasker->createTask($class, $method, $page, 'Task title', $arguments); where $class and $method specify the function that performs the job, $page is the task's parent page and $arguments provide optional configuration for the task.
      Executing a task
      You need to activate a task first
      wire('modules')->Tasker->activateTask($task); then Tasker will automatically execute it using one of its schedulers: Unix cron, LazyCron or TaskerAdmin's REST API + JS client.
      Getting the job done
      Your method that performs the task looks like
      public function longTask($page, &$taskData, $params) { ... } where $taskData is a persistent storage and $params are run-time options for the task.
      Monitoring progress, management
      The TaskerAdmin module provides a Javascript-based front-end to list tasks, to change their state and to monitor their progress (using a JQuery progressbar and a debug log area). It also allows the on-line execution of tasks using periodic HTTP calls performed by Javascript.

       
      Monitoring task progress (and log messages if debug mode is active)

       
      Task data and log

      Detailed info (setup, task dependencies, time limits, REST API etc.) and examples can be found on GitHub.
      This is my first public PW module. I'm sure it needs improvement
       
    • By netcarver
      A very simple textformatter that was inspired by Diogo's RemoveHeight textformatter.
      This one strips the height from any images and either adds a custom class or adds a max-width:100% as an embedded style.
      Github: https://github.com/netcarver/TextformatterFluidImages
      PW Repo: To Be Confirmed.