Wanze

Module
Pages2Pdf

221 posts in this topic

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);

 

1 person likes this

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

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 cosmicsafari
      Hi All,
      Fairly new to ProcessWire so apologies if this is a daft question, but I am having a go creating my first module. I have set it up and enabled it as per the docs.
      However I have created another class within the same module directory, which was going to be used in the main module file but I can't get it to work for the life of me and I believe its due to me not fully understanding the namespace side of things.
      Example:
      MyModule.module.php
      <?php namespace ProcessWire; class MyModule extends WireData implements Module { public static function getModuleInfo() { return array( 'title' => 'Test Module', 'version' => 1, 'summary' => 'Test module', 'href' => '', 'singular' => true, 'autoload' => true, 'icon' => 'exchange', ); } public function newMethod( $testMessage ) { $foo = new Foo($testMessage); $foo->getFoo(); } } Foo.php
      <?php namespace ProcessWire; class Foo { protected $foo; public function __construct($foo) { $this->foo = $foo; } public function getFoo() { return $this->foo; } } Now as I understand it both these files should exist under the ProcessWire namespace, so in theory I should be able to use Foo within MyModule without any use statements as they both exist at the same level within the ProcessWire namespace?
      However when I try something like so:
      $myModule = $modules->getModule('MyModule'); $myModule->myMethod('Foo'); I would have thought this should return 'Foo', however I keep running into errors like:
      Any help would be appreciated.
    • By Max Allan Niklasson
      Hi, I think this is my first topic, even though I've been working with PW a few years. But now, I'm trying to restructure my way of coding, cause many templates (like activities for birding societies) are re appearing in multiple different websites. Since this, I've been working on redo this into a module, but as far as I have read I cannot store the templates (related to specific module) in the module's folder. It has to be in the templates folder?
       
    • By kongondo
      Menu Builder
       
      Modules Directory
      Project Page
      Read Me (How to install, use, etc..)

      If you want a navigation that mirrors your ProcessWire page tree, the system allows you to easily create recursive menus using either vanilla PHP or Soma's great MarkupSimpleNavigation. In some cases, however, you may wish to create menus that:
      1. Do not mirror you site's page tree (hirarchies and ancestry); and
      2. You can add custom links (external to your site) to.

      That is primarily where Menu Builder comes in. It is also helpful if you:
      3. Prefer creating menus via drag and drop
      4. Have a need for menus (or other listings) that will be changing regularly or that you want to allow your admin users to edit.

      The issue of custom menus is not new here in the forums. The difference is that this module allows you to easily create such menus via drag and drop in the Admin. Actually, you can even use it to just create some list if you wanted to. In the backend, the module uses the jQueryUI plugin nestedSortable by Manuele J Sarfatti for the drag and drop and is inspired in part by the WP Custom Menu feature.
       
      Please read the Read Me completely before using this module. 
      For Complex or highly-customised menus, it is recommended to use the getMenuItems() method as detailed in this post.
       
      Features
      Ability to create menus that do not mirror your ProcessWire Page Tree hierarchy/structure Menus can contain both ProcessWire pages and custom links Create menu hierarchies and nesting via drag and drop Easily add CSS IDs and Classes to each menu item on creating the menu items (both custom and from ProcessWire pages) or post creation. Optionally set custom links to open in a new tab Change menu item titles built from ProcessWire pages (without affecting the original page). E.g. if you have a page titled 'About Us' but you want the menu item title to be 'About' Readily view the structure and settings for each menu item Menus stored as pages (note: just the menu, not the items!) Menu items stored as JSON in a field in the menu pages (empty values not stored) Add menu items from ProcessWire pages using page fields (option to choose between PageAutocomplete and AsmSelect [default]) or a Selector (e.g. template=basic-page, limit=20, sort=title). For page fields, you can specify a selector to return only those specified pages for selection in the page field (i.e. asm and autocomplete) For superusers, optionally allow markup in your menu titles, e.g. <span>About</span> Menu settings for nestedSortable - e.g. maxLevels (limit nesting levels) Advanced features (e.g. add pages via selector, menu settings) currently permissible to superadmins only (may change to be permission-based) Delete single or all menu items without deleting the menu itself Lock down menus for editing Highly configurable MarkupMenuBuilder - e.g. can pass menu id, title, name or array to render(); Passing an array means you can conditionally manipulate it before rendering, e.g. make certain menu branches visible only to certain users [the code is up to you!]  Optionally grab menu items only (as a Menu object WireArray or a normal array) and use your own code to create custom highly complex menus to meet any need. More... In the backend, ProcessMenuBuilder does the menu creation. For the frontend, menus are displayed using MarkupMenuBuilder.

      Credits

      In this module's infancy (way back!), I wanted to know more about ProcessWire modules as well as improve my PHP skills. As they say, what better way to learn than to actually create something? So, I developed this module (instead of writing PW tutorials as promised, tsk, tsk, naughty, naughty!) in my own summer of code . Props to Wanze, Soma, Pete, Antti and Ryan whose modules I studied (read copied ) to help in my module development and to Teppo for his wonderful write-up on the "Anatomy of fields in ProcessWire" that vastly improved my knowledge and understanding of how PW works. Diogo and marcus for idea about using pages (rather than a custom db table), onjegolders for his helpful UI comments, Martijn Geerts, OrganizedFellow, dazzyweb and Mike Anthony for 'pushing me' to complete this module and netcarver for help with the code.
       
      Screens

    • By kongondo
      Introducing Variations, an Input- and Fieldtype for product variations and their attributes.
      Product variations is a topic that has been coming up now and then, especially in the recent past.  This module seeks to fill this gap. Though it's in its early stages of development, it is already functional and can be used as is. I decided to make an early announcement (modules development forum) in order to get early feedback from potential users. 
      The module is an alternative take on how variations can be built for a product. Imagine the ubiquitous T-Shirt. The product could vary by ...Size, Colour, Material, etc...These variations could in turn have internal variations, i.e. attributes....so, Size [Small, Large], Colour [Red, Blue]...etc; you get the drift.
      The usual approaches to building variations have been either to use Multiple pages, Repeaters, Page Table, Table or Matrix (limited to 1x1 variations). In this module, we do it a bit differently.
      First, the variations occur not at the Field level (meaning all product pages would have the same variations and attributes for each template) but at the page level. Secondly, there are no multiple pages for each variation and/or attributes; a product is a single page. The variations and their attributes are defined by site editors at the page level. Once a variations configuration has been defined, it is applied to the page and all possible combinations are generated (i.e. the Red,Small,Cotton; Red,Large,Cotton, etc) in the Inputfield. There is no limit to the number of variations and attributes that can be defined, although you will be amazed at how quickly the combinations grow! Prices are entered for each combination when editing the page. Combinations without prices are not saved to the database. Please note that prices cannot themselves vary at the page-level. Meaning, you cannot have ONE variation configuration that has different price inputs per product in the same FieldtypeVariations field.
      The module ships with an API for outputting variation combinations in the frontend. Search, database and in-memory work as normal in the frontend. In the backend, DataTables provides a nice paginated, filterable table. Prices can be entered on any pages (of the table) without loss of data (meaning you can enter prices on page 1, scroll to page 10, enter more prices, filter or search the products table, enter more prices and finally save; no data will be lost).
      I still have a couple of ideas and plans pending but would love to hear from you, thanks.
      Below is a short video demo of the module in its current state. Things may/will change, both UI and features. Btw, the Fieldtype, although primarily targeted at commerce applications, is by no means limited to this. Other uses requiring combinations of whatever number of variables are very much within the remit of the module.
      Planned/Hoped for features
      Import/Export product variations and attributes (Excel, etc) Full integration with Padloper (I will have to  discuss with @apeisa) SKU fields for each product variation Add/Remove extra subfields, e.g. multi-currency prices (currently there is only 1 input for each product variations' price) Product variation images? Etc... Please not this module is not related to this other planned module (but it may eventually).
      Sneak Peek Demo
       
       
    • By bernhard
      hi everybody,
      this is a preview of a module that i'm working on for quite a long time. I needed it for an intranet office management application that i'm still working on. It makes it very easy to create very customized Datatables using the awesome jquery datatables plugin (www.datatables.net)
       
      EARLY ALPHA release!
      It's very likely that there will lots of changes to this module that may cause breaking your implementations.
       
      Module source
      https://gitlab.com/baumrock/RockDataTables2/tree/master
      Screencast:

       
      Remarks:
      The module is intended to be used on the backend. Loading styles is at the moment only done via adding files to the $config->styles/scripts arrays. Also the communicaton to javascript is done via the $config->js() method that is built into the admin and would have to be implemented manually on frontend use. But it would not be difficult of course
       
      Installation:
      Nothing special here, just download + install
       
      Example setup of the most minimal Table:
      you always need 2 files to create a table:
      php file to define the columns and related data (page selector) js file to control the client-side actions like rendering, sorting, etc PHP
      // init datatables module $dt2 = $modules->get('RockDataTables2'); // setup columns // name $col = new dtCol(); $col->name = 'name'; $col->title = 'Name'; $col->data = function($page) { return $page->title; }; $dt2->cols->add($col); // setup table $dt2->id = 'dt_kundenliste'; // give your table an id $dt2->js('/site/modules/ProcessRockProjects/dt_kundenliste.js'); // tell it where to find the related javascript // ################################## // ajax request -> return data // non-ajax -> render table // ################################## if($config->ajax) { // here you can setup your page selector // this will for sure change in the future to support filtering etc echo $dt2->getJSON($pages->find('template=rockcontact, sort=random, limit=10000')); die(); } else return $dt2->render(); JS
      $(document).ready(function() { // setup variables var opt = ProcessWire.config.dt_kundenliste; // options from backend var colDefs = []; // column definitions // custom column definitions here (see https://datatables.net/reference/option/columnDefs for all options) // load default column definitions colDefs = colDefs.concat(dtGetDefaultDefs(opt)); // initialise table $('#dt_kundenliste').DataTable({ ajax: './kundenliste/', columnDefs: colDefs, }); }); that's it - as easy as that!

       
      Customization example:
      in the screencast you see an example that i'm using in a process module. i put the table inside an InputfieldMarkup just to have the same look&feel all around the admin. you see that you could also use this module to create tables quickly and easily using @kongondo s runtime markup module.
      complete PHP code:
      $this->headline('Kundenliste'); $form = $modules->get('InputfieldForm'); // init datatables module $dt2 = $modules->get('RockDataTables2'); // setup columns // name $col = new dtCol(); $col->name = 'name'; $col->title = 'Name'; $col->data = function($page) { return $page->title; }; $dt2->cols->add($col); // type $col = new dtCol(); $col->name = 'type'; $col->data = function($page) { return $page->rockcontact_type->title; }; $dt2->cols->add($col); // modified $col = new dtCol(); $col->name = 'modified'; $col->data = function($page) { $obj = new stdClass(); $obj->timestamp = $page->modified; $obj->display = date('d.m.Y', $page->modified); return $obj; }; $dt2->cols->add($col); // setup table $dt2->id = 'dt_kundenliste'; $dt2->js('/site/modules/ProcessRockProjects/dt_kundenliste.js'); $f = $modules->get('InputfieldMarkup'); $f->value = $dt2->render(); $form->add($f); // ################################## // ajax request -> return data // non-ajax -> render form + table // ################################## if($config->ajax) { echo $dt2->getJSON($pages->find('template=rockcontact, sort=random, limit=10000')); die(); } else $out .= $form->render(); return $out; what is interesting here is this part:
      // modified $col = new dtCol(); $col->name = 'modified'; $col->data = function($page) { $obj = new stdClass(); $obj->timestamp = $page->modified; $obj->display = date('d.m.Y', $page->modified); return $obj; }; $dt2->cols->add($col); datatables support orthogonal data (https://datatables.net/extensions/buttons/examples/html5/outputFormat-orthogonal.html). a date column is a good example, because you need to DISPLAY a formatted date (like 10.02.2017) but you need to be able to SORT this column by a different value (timestamp). its very easy to accomplish this by providing both values in your json. Btw: You could also just transfer the timestamp and do the formatting on the client-side via javascript. Next Example will show ho this would work. Both cases can be necessary, it's just an example here.
      back to topic: now we have both data available and need to tell the table wich data to use for which action. it's easy, just add the definition to the array:
      // modified date colDefs.push({ targets: opt.colnames.indexOf('modified'), render: { _: 'display', sort: 'timestamp', }, }); this tells the datatable to use the display-value for displaying (and filtering) and the timestamp-value for sorting. see https://datatables.net/reference/option/columns.render
      you can also easily modify a simple non-orthogonal data via a render function:
      // name colDefs.push({ targets: opt.colnames.indexOf('name'), render: function ( data, type, full, meta ) { return '<span class="blurry" title="'+data+'">'+data+'</span>'; }, }); this adds the span with "blurry" class to every cell of type "name". i did this to blur all the client data in my screencast
      the complete javascript:
      $(document).ready(function() { // setup variables var opt = ProcessWire.config.dt_kundenliste; // options from backend var colDefs = []; // column definitions // custom column definitions here // see https://datatables.net/reference/option/columnDefs for all options // name colDefs.push({ targets: opt.colnames.indexOf('name'), render: function ( data, type, full, meta ) { return '<span class="blurry" title="'+data+'">'+data+'</span>'; }, }); // typ colDefs.push({ targets: opt.colnames.indexOf('type'), render: function ( data, type, full, meta ) { return '<a href="#" style="white-space: nowrap;">'+data+'</a>'; }, }); // modified date colDefs.push({ targets: opt.colnames.indexOf('modified'), render: { _: 'display', sort: 'timestamp', }, }); // load default column definitions colDefs = colDefs.concat(dtGetDefaultDefs(opt)); // initialise table $('#dt_kundenliste').DataTable({ ajax: './kundenliste/', columnDefs: colDefs, scrollY: "400px", scrollCollapse: true, scrollX: "100%", pageLength: 10, }); }); you can also have scrollbars just by adding options to your datatable. also fixed columns are possible. just see the docs on datatables.net

      Why i created this module:
      of course i know @Soma s module but i needed a lot more features and the newer datatables version. also i like to define all the columns as objects and have everything on one place. lister & markupadmindatatable: nice for basic tables but lacks of features to modify the appearance of the cell values (like rendering icons, background colors and so on) datatables provides a great frontend API for filtering, showing/hiding columns, getting data, modifying it... it also plays well together with frontend charts like google chart api in this case:
       
      todo / roadmap:
      all kinds of column filters (like seen in the example above that shows an older and bloated version of this module) support for ajax filters and pagination (currently all filtering and sorting is done on the client side. i tried it with up to 50.000 rows and got reasonable results. initial loading took around 10sec. but of course this heavily depends on the complexity of your table and your data.