Jump to content
Wanze

Pages2Pdf

Recommended Posts

Glad it works! I'll check if this is an issue with my module or mPDF in general.

Am I write that the file call's the module needs to be included before any other files? I am assuming this has to do wit the header that has to be sent.

The order of the includes doesn't matter, but you need to be careful not sending any output (headers) to the browser before downloading the PDF. For example echo out something, though in the context of ProcessWire all echos in your template are catched by PHPs output buffer, so you should be fine. You'd get warnings if that happens, something like "Headers already sent" :)

Cheers

  • Like 2

Share this post


Link to post
Share on other sites

Thanks Wanze, the output headers was one of my issues indeed.

I am back at it again with some issues getting custom fonts to load. In this case I have read a few topics in the forum as well as the manual here. I am attempting to include an Open Sans font. The steps I have taken are so.

Added ttf file to modules/Pages2Pdf/mdf/ttfonts

modified config_fonts.php 

$this->fontdata = array(
  "dejavusanscondensed" => array(
     'R' => "DejaVuSansCondensed.ttf",
     'B' => "DejaVuSansCondensed-Bold.ttf",
     'I' => "DejaVuSansCondensed-Oblique.ttf",
     'BI' => "DejaVuSansCondensed-BoldOblique.ttf",
  ),
  "opensans" => array(
     'R' => "OpenSans.ttf",
     'B' => "OpenSansB-Bold.ttf",
     'I' => "OpenSansI-Italic.ttf",
  ),

Changed Mode in the module settings to "s"

Updated the Default Font in the Module Settings to "OpenSans"

Anything stand out that I am missing?

Share this post


Link to post
Share on other sites

Hi,

All Chinese characters in the output pdf file become ???. How to config to use CJK fonts??

Thanks.

Gideon

Share this post


Link to post
Share on other sites

Hi,

All Chinese characters in the output pdf file become ???. How to config to use CJK fonts??

Thanks.

Gideon

Work it out myself. Maybe someone need the answer. Here it is.

1. Download mpdf 6.0 from http://www.mpdf1.com/mpdf/index.php

2. copy the Sun-ExtA.ttf file to /path/to/your/web/site/modules/Pages2Pdf/mpdf/ttfonts

3. add the following lines to /path/to/your/web/site/modules/Pages2Pdf/mpdf/config_fonts.php

       "sun-exta" => array (

                'R' => "Sun-ExtA.ttf",

                'sip-ext' => 'sun-extb',

                ),

4. change the mode to R in WirePdf module config page

5. Chang fonts to sun-exta in WirePdf module config page

Done.

Gideon

  • Like 2

Share this post


Link to post
Share on other sites

Hello and thanks for the great module!!

Everything seems to work but I have a doubt.

I should create a pdf of a list of events that are setup by the user via a form.
I would then pass a variable with the exact list to the template that I use to create PDF, but I can not.
Some idea?
 
Thanks so much
Andrea

Share this post


Link to post
Share on other sites

Hi a.masca

Can you share your current code? Do you store the events inside ProcessWire or are they only available after submitting the form?

Cheers

Share this post


Link to post
Share on other sites

Hi a.masca

Can you share your current code? Do you store the events inside ProcessWire or are they only available after submitting the form?

Cheers

Thanks Wanze for the answer.

In the page where I want to put my download pdf button,

I have a list of reservations (every reservation is a page) that the user can filter with a form.

example: $prenotazioni = $pages->find("template=prenotazione, giorno=xxx");

So my goal is to pass to the pages2pdf this variable $prenotazioni,

so the user can download the pdf of the list that he filtered.

Thanks a lot

Andrea

Share this post


Link to post
Share on other sites

Hi all,

This is a brilliant module, but I have noticed something unexpected, that I hope someone can help with.

I have a text string which contains a degree symbol ( ˚ ) but for some reason the produced PDF replaces that symbol with a question mark - indicating it doesn't understand it (the same string appears fine on the html page itself).

I have made sure the string is UTF-8 encoded and I'm using the Times font when outputting the PDF.

Does anyone have any ideas why this is happening and any possible way of fixing it?

All the best,
Tony.

Share this post


Link to post
Share on other sites

Hi all,

How do you go about adding a page break to your generated PDF?

I've tried adding

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

into the template file, but although it doesn't give an error when rendering the PDF, neither does it add a new page!

All help gratefully received.

Tony.

Share this post


Link to post
Share on other sites
34 minutes ago, bernhard said:

hi tony,

did you read the manual? http://www.mpdf1.com/mpdf/index.php;)

Thanks for the link Bernhard. 

I had read other online documentation, but it didn't make it clear that all you had to do was include the HTML tag <pagebreak />.
I did that and voila, a page break :)

Thanks again,

Tony.

 

  • Like 2

Share this post


Link to post
Share on other sites
On 9.7.2016 at 11:23 PM, Tony Carnell said:

I have a text string which contains a degree symbol ( ˚ ) but for some reason the produced PDF replaces that symbol with a question mark - indicating it doesn't understand it (the same string appears fine on the html page itself).

I have made sure the string is UTF-8 encoded and I'm using the Times font when outputting the PDF.

Does anyone have any ideas why this is happening and any possible way of fixing it?

Hi Tony,

Could you already solve this problem? It looks like this character is not included in the chosen font, maybe try another one? How did you output the degree symbol, hardcoded or with an entity, e.g. &deg; ?

Cheers

Share this post


Link to post
Share on other sites

Hello,

big thanks for this wonderful modul. I have here a interesting problem. If I save 2 pages with individual templates, the second page always gets the first template. I want to create an invoice and a list of items. Is there something to keep an eye on when doing such stuff? This is my code:

$rechnung = new Page();
$rechnung->template = "rechnung";
$rechnung->parent = wire('pages')->get("/rechnungen/");
$rechnung->title = "HG-".$order->id;
$rechnung->orderid = $order->id;
$rechnung->save();
$rechnung->of(false);
$mail->attachment(wire('modules')->get('Pages2Pdf')->getPDFFilePath($rechnung));
$stueckliste = new Page();
$stueckliste->template="stueckliste";
$stueckliste->parent = wire("pages")->get("/stuecklisten/");
$stueckliste->title = "HGSL-".$order->id;
$stueckliste->orderid = $order->id;
$stueckliste->save();
$stueckliste->of(false);
$mail->attachment(wire('modules')->get('Pages2Pdf')->getPDFFilePath($stueckliste));

Both templates are configured for pages2pdf and I have for both of them an template-file underneath pages2pdf. The first one use the template rechnung and the second page also uses the page rechnung. I use the newest version of pages2pdf and processwire 2.7.2 in combination with the actual release of padloper.

Has anyone here in the forum an idea howto solve this?

Thanks Henning

Share this post


Link to post
Share on other sites

Hi Henning,

Interesting approach on how to use the module :) Looks like a caching problem to me, could you try to add $this->pdf = null after this line:

https://github.com/wanze/Pages2Pdf/blob/master/Pages2Pdf.module#L218

The code should then look like the following snippet:

[...]
  } else {
    $this->create($page, true);
    $name = $this->getPDFFilename($page);
    $this->wire('session')->message(sprintf($this->_("Pages2Pdf: Created PDF file(s) '%s'"), $name));
  }
  // Add me!
  $this->pdf = null;
}

Cheers

  • Like 4

Share this post


Link to post
Share on other sites

Hi Wanze,

thank you very much for the lightning fast response. It works with this addition.

BR

Henning

Share this post


Link to post
Share on other sites

Hey thanks a million for this modul :) 

Unfortunately, I have some troubles. I've installed the modul, add the current template in the settings and tried it out. In the template file (htdocs/site/templates)  I've add this code, like in the instructions:

echo $modules->get('Pages2Pdf')->render();

But I receive always the same error. Something like "Error loading PDF-File". What's wrong? Did I forgot something? I use Processwire 3.0.29.

Thanks for your help.

PS: Sorry for my "English"

printscreen.png

Share this post


Link to post
Share on other sites

@cappuccino You're welcome, I never saw this error before. What is the content of your ProcessWire PDF template (site/templates/pages2pdf/..) that is rendered by the module? Does it work if you you just put a "Hello World" in it? If so, you'd need to simplify your markup and debug what is causing the error.

 

Cheers

Share this post


Link to post
Share on other sites

Hi!
Thanks for this great module!

This is probably easy, but I cant get it to work (Iam a PHP noob). 
I want to generate two PDfs (with different templates) from the same page.

I have two files in the pages2pdf folder under templates (expose_preisliste.php, expose_wohnung.php).
If I understand correctly I would set it up like this:

$preisliste = $modules->get('WirePDF');
$preisliste->markupMain = $config->paths->templates . 'expose_preisliste.php';
$preisliste->save('preisliste.pdf');

$wohnung = $modules->get('WirePDF');
$wohnung->markupMain = $config->paths->templates . 'expose_wohnung.php';
$wohnung->save('wohnung.pdf');

Now I want two links on the frontend to download the files.
How do I call the variable for the Link?
I want the PDFs to be generated when clicking the link.

Thx for your help!

I managed to get this working. 
 

Share this post


Link to post
Share on other sites

Now I have a new Problem.
I have several pages I just use for data storage (no template file associated).
The pages are all children of a page called "wohnen". 
The data of those pages is used on the page home.

Now I want to create a PDF from all these pages (of parent "wohnen").
To let the module know wich PDFs to generate I used a session.
In my template for generating the PDFs I have something like this:

session_start();
$wohnungsnr = $_SESSION['wohnungsnr'];
   <?php    
    $targetPage = "/$wohnungsnr/";
    $wohnung = wire('pages')->get($targetPage);
	$out = " <h1>{$targetPage}</h1> ";
   
    
        $out .="
         <div id='{$wohnungsnr}-content' class='fbox-content'>
             <div class='grid'>
                <h1 class='size1of1'>{$wohnung->headline}</h1>
        ";
		 foreach ($wohnung->grundrisse as $grundriss) {
 $out .=  "<img class='size1of3' src='{$grundriss->url}'>";
};
        $out .= 
            "
            <div class='size1of3 wohnung-content'>
            <table>
            <tr>
                            <th>Wohnungstyp</th>
                            <th>Etage</th>
                        </tr>
                        <tr>
                            <td>{$wohnung->options_zimmer->title} Zimmer</td>
                            <td>{$wohnung->options_etage->title}</td>
                        </tr>
                        <tr>
                            <th>Grösse</th>
                            <th>Kaufpreis</th>
                        </tr>
                        <tr>
                            <td>{$wohnung->size}</td>
                            <td>{$wohnung->preis}</td>
                        </tr>
                        <tr>
                        <th colspan='2'>Ausstattung</th>
                        </tr>
                        <tr>
                            <td colspan='2'>
                                <ul>
            ";
        foreach ($wohnung->ausstattung_repeater as $item) {
            
            $out .= " 
                                    <li>– {$item->headline}</li>
                                ";
        }
        $out .= "</ul>
                            </td>
                        </tr>
            </table>
            
            </div>
             </div>
            </div> ";
	echo "{$out}";
    ?>


<?php include("_footer.php"); ?>

On the page home I have a function that shows all the data from the children of  the"wohnen" page with a download button for every page. My Idea was to change the session variable on click of the download buttton to let the pdf template know wich page to render.
Any Ideas how this works?


You can delete this post I figured it out.
I send the variable with the URL like this:

<a href='$page->url?pages2pdf=1&wohnungsnr={$wohnung->title}' class='button' id='{$wohnung->title}'><img src='http://projekte.janploch.de/fabricius/site/templates/img/icon-download.svg' class='button-icon'>Download Exposé</a>


 

Share this post


Link to post
Share on other sites

Hello,

I'm struggling with this : a 504 Gateway Timeout when generating my PDF.

I used to be able to generate a particular PDF listing 52 places with a photo  (small), a little text and a few pieces of information for each in a table. It worked and I had a PDF of about 350Ko.

Now, I'm trying to generate a PDF of about 250Kos and I get the 504 error. I've tried to re-generate my places catalogue and again, I have the 504 error.

All my templates work fine (although it takes a little while) to generate smaller PDF files.

The page I'm trying to generate is : http://planetalert.tuxfamily.org/players/4e/amandine

If someone have advice on how I could find my way out of this, I'd greatly appreciate ;)

Thanks !

Share this post


Link to post
Share on other sites

I want to let it work with PHP7. I get this error message:

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; mPDF has a deprecated constructor in /site/modules/Pages2Pdf/mpdf/mpdf.php on line 66 Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; grad has a deprecated constructor

/site/modules/Pages2Pdf/mpdf/classes/grad.php on line 3 Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; form has a deprecated constructor in /site/modules/Pages2Pdf/mpdf/classes/form.php on line 3 Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; cssmgr has a deprecated constructor in /site/modules/Pages2Pdf/mpdf/classes/cssmgr.php on line 3 %PDF-1.4 % 3 0 obj <> /Contents 4 0 R>> endobj 4 0 obj <> stream xOO0\IhN=bZW$~wi+(\ `'l4cm=@Κ|҃7X(c)qe8嶴~wuxj=ϭ; Gۗ}q؃E k4FX"%7_Y`Id-#US,qڪQ!)$5|LJO(qiuYvr]ǿbnsP\\ Ґb,ߞymAM*{Hv6EÞy{(ŵjV/M x98F&P{y=+^mKi߀&mKU^0}Y֊';#lKO)]Iҍ,<_216=q0 endstream endobj 1 0 obj <> endobj 5 0 obj <> endobj 6 0 obj <> endobj 7 0 obj <> endobj 8 0 obj <> endobj 9 0 obj <> endobj 2 0 obj <> /ExtGState << /GS1 5 0 R >> >> endobj 10 0 obj << /Producer (mPDF 5.7.4) /CreationDate (20160904200643+02'00') /ModDate (20160904200643+02'00') >> endobj 11 0 obj << /Type /Catalog /Pages 1 0 R /OpenAction [3 0 R /XYZ null null 1] /PageLayout /OneColumn >> endobj xref 0 12 0000000000 65535 f 0000000713 00000 n 0000001255 00000 n 0000000015 00000 n 0000000223 00000 n 0000000802 00000 n 0000000863 00000 n 0000000959 00000 n 0000001060 00000 n 0000001158 00000 n 0000001401 00000 n 0000001529 00000 n trailer << /Size 12 /Root 11 0 R /Info 10 0 R /ID [<3df5fdeb256069fc900acdab6c3ab3f0> <3df5fdeb256069fc900acdab6c3ab3f0>] >> startxref 1639 %%EOF

Any hints?

Thanks!

Share this post


Link to post
Share on other sites

@hheyne @Wanze

I'm hitting the same problem with this module. PW3.0.36 and PHP7. Even though they are only notices, this seems to stop the PDF file from being correctly generated (at least, for me.)

Is the mPdf project still being maintained? I wonder if a patch is in the works for this?

Share this post


Link to post
Share on other sites

The latest version of mPDF (7.0.0) already supports PHP 7, so it should be just a matter of pulling the latest sources into the module (unless there were breaking changes since 5.7).

  • Like 1

Share this post


Link to post
Share on other sites

Hi everyone,

I've just installed this module and it works lovely. However I am unsure as to a few things. I would like to call my original css files "main.css" in my templates folder to use on the pdf. As of now it doesn't seem to load any CSS. I added some inline-styles to the files in the "pages2pdf" folder and they did not seem to load.

Reading the module files I see the below. Though I am unsure what the difference between the two CSS option are. Also I'm unsure as to what I put in them. Where do I start the path? etc. I apologize for my ignorance of PHP and PW.

protected static $config = array(
        'markupMain' => '',
        'markupHeader' => '',
        'markupFooter' => '',
        'mode' => 'c',
        'pageOrientation' => 'P',
        'pageFormat' => 'A4',
        'topMargin' => 30,
        'rightMargin' => 15,
        'bottomMargin' => 20,
        'leftMargin' => 15,
        'headerMargin' => 5,
        'footerMargin' => 10,
        'font' => 'Helvetica',
        'fontSize' => 12,
        'author' => '',
        'headerFirstPage' => 1,
        'cssFile' => '', //this one 
        'css' => '', //and this one
    );

Also is there a way to remove the auto generated header and footer that the pdf seems to generate. The ones that says "default header..." "...created with processwire and pages2pdf..." as well as the header and footer for the website (the one I made). I get seem to get both some times and sometimes not.

Finally some of my images don't appear to load. I've read that there are issues with background-images, but this is just a regular image element. 

Note: I have deactivated the header and footer settings in the back-end module settings but I still get the default head/foot, infact everything I change does not appear to have anything effect, even changing from portrait to landscape; it will still come out portrait.

Any help is much appreciated.

Thanks,

Matt

Share this post


Link to post
Share on other sites

@Matt_P

It sounds like you always get a cached PDF. Try enabling the debug mode or change the cache time to "0" in the Pages2Pdf, then you should actually see your settings taking place. As for the image, can you share your code? Be aware that CSS support is limited when rendering the PDF, that's why you should load a separate CSS file containing the styles just for the PDF's.

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
      PrevNextTabs Module
      Github: https://github.com/outflux3/PrevNextTabs
      Processwire helper modules for adding page navigation within the editor.
      Overview
      This is a very simple module that adds Previous and Next links inline with the tabs on the page editor. Hovering over the tab shows the title of the previous or next page (using the admin's built in jqueryUI tooltips.)
      Usage
      This module is typically used during development where you or your editors need to traverse through pages for the purpose of proofing, flagging and/or commenting. Rather than returning to the page tree or lister, they can navigate with these links.
      Warnings
      If you are using PW version 2.6.1 or later, the system will prevent you from leaving the page if you have unsaved edits.
      For earlier versions, to avoid accidentally losing changes made to a page that might occur if a user accidentally clicks on one of these, make sure to have the Form Save Reminder module installed.
      http://modules.processwire.com/modules/prev-next-tabs/
    • By Gadgetto
      SnipWire - Snipcart integration for ProcessWire
      Snipcart is a powerful 3rd party, developer-first HTML/JavaScript shopping cart platform. SnipWire is the missing link between Snipcart and the content management framework ProcessWire.
      With SnipWire, you can quickly turn any ProcessWire site into a Snipcart online shop. The SnipWire plugin helps you to get your store up and running in no time. Detailed knowledge of the Snipcart system is not required.
      SnipWire is free and open source licensed under Mozilla Public License 2.0! A lot of work and effort has gone into development. It would be nice if you could donate an amount to support further development:

      Status update links (inside this thread) for SnipWire development
      2020-03-21 -- SnipWire 0.8.5 (beta) released! Improves SnipWires webhooks interface and provides some other fixes and additions 2020-03-03 -- SnipWire 0.8.4 (beta) released! Improves compatibility for Windows based Systems. 2020-03-01 -- SnipWire 0.8.3 (beta) released! The installation and uninstallation process has been heavily revised. 2020-02-08 -- SnipWire 0.8.2 (beta) released! Added a feature to change the cart and catalogue currency by GET, POST or SESSION param 2020-02-03 -- SnipWire 0.8.1 (beta) released! All custom classes moved into their own namespaces. 2020-02-01 -- SnipWire is now available via ProcessWire's module directory! 2020-01-30 -- SnipWire 0.8.0 (beta) first public release! (module just submitted to the PW modules directory) 2020-01-28 -- added Custom Order Fields feature (first SnipWire release version is near!) 2020-01-21 -- Snipcart v3 - when will the new cart system be implemented? 2020-01-19 -- integrated taxes provider finished (+ very flexible shipping taxes handling) 2020-01-14 -- new date range picker, discount editor, order notifiactions, order statuses, and more ... 2019-11-15 -- orders filter, order details, download + resend invoices, refunds 2019-10-18 -- list filters, REST API improvements, new docs platform, and more ... 2019-08-08 -- dashboard interface, currency selector, managing Orders, Customers and Products, Added a WireTabs, refinded caching behavior 2019-06-15 -- taxes provider, shop templates update, multiCURL implementation, and more ... 2019-06-02 -- FieldtypeSnipWireTaxSelector 2019-05-25 -- SnipWire will be free and open source Plugin Key Features
      Fast and simple store setup Full integration of the Snipcart dashboard into the ProcessWire backend (no need to leave the ProcessWire admin area) Browse and manage orders, customers, discounts, abandoned carts, and more Multi currency support Custom order and cart fields Process refunds and send customer notifications from within the ProcessWire backend Process Abandoned Carts + sending messages to customers from within the ProcessWire backend Complete Snipcart webhooks integration (all events are hookable via ProcessWire hooks) Integrated taxes provider (which is more flexible then Snipcart own provider) Useful Links
      SnipWire in PW modules directory SnipWire Docs (please note that the documentation is a work in progress) SnipWire @GitHub (feature requests and suggestions for improvement are welcome - I also accept pull requests) Snipcart Website  
      ---- INITIAL POST FROM 2019-05-25 ----
       
    • By horst
      Croppable Image 3
      for PW 3.0.20+
      Module Version 1.2.0
      Sponsored by http://dreikon.de/, many thanks Timo & Niko!
      You can get it in the modules directory!
      Please refer to the readme on github for instructions.
       
      - + - + - + - + - + - + - + - + - + - NEWS - 2020/03/19 - + - + - + - + - + - + - + - + - + - 
      There is a new Version in the pipe, that supports WebP too: 
       
      - + - + - + - + - + - + - + - + - + - NEWS - 2020/03/19 - + - + - + - + - + - + - + - + - + - 
       
       
      -------------------------------------------------------------------------
       
      Updating from prior versions:
       
      Updating from Croppable Image 3 with versions prior to 1.1.7, please do this as a one time step:
      In the PW Admin, go to side -> modules -> new, use "install via ClassName" and use CroppableImage3 for the Module Class Name. This will update your existing CroppableImage3 module sub directory, even if it is called a new install. After that, the module will be recogniced by the PW updater module, what makes it a lot easier on further updates.
      -------------------------------------------------------------------------
       
      For updating from the legacy Thumbnail / CropImage to CroppableImage3 read on here.
       
      -------------------------------------------------------------------------
       
    • By Robin S
      Inspired by a recent question.
      Image Crop Ratios
      Allows preset aspect ratios to be defined per image field for the ProcessWire image crop tool.
      The module adds a select dropdown to the crop tool. Choose an aspect ratio and the crop area will be fixed to that ratio.
      Screencast

      Installation
      Install the Image Crop Ratios module.
      Configuration
      Default aspect ratios for all image fields can be defined in the module config. Aspect ratios for specific image fields can be defined on the Input tab of the field settings. You can override the ratio settings in template context if needed. Insert a hyphen as the first item in the ratio settings unless you want to force a ratio to be applied to the crop tool. The hyphen represents a blank option that allows a free crop area to be drawn. Usage
      Click the "Crop" link on the details view of an image thumbnail. Click the "Crop" icon at the top of the editor window. Choose an option from the "Ratio" select dropdown.  
      https://github.com/Toutouwai/ImageCropRatios
      https://modules.processwire.com/modules/image-crop-ratios/
×
×
  • Create New...