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 joshua
      This module is (yet another) way for implementing a cookie management solution.
      Of course there are several other possibilities:
      - https://processwire.com/talk/topic/22920-klaro-cookie-consent-manager/
      - https://github.com/webmanufaktur/CookieManagementBanner
      - https://github.com/johannesdachsel/cookiemonster
      - https://www.oiljs.org/
      - ... and so on ...
      In this module you can configure which kind of cookie categories you want to manage:

      You can also enable the support for respecting the Do-Not-Track (DNT) header to don't annoy users, who already decided for all their browsing experience.
      Currently there are four possible cookie groups:
      - Necessary (always enabled)
      - Statistics
      - Marketing
      - External Media
      All groups can be renamed, so feel free to use other cookie group names. I just haven't found a way to implement a "repeater like" field as configurable module field ...
      When you want to load specific scripts ( like Google Analytics, Google Maps, ...) only after the user's content to this specific category of cookies, just use the following script syntax:
      <script type="text/plain" data-type="text/javascript" data-category="statistics" data-src="/path/to/your/statistic/script.js"></script> <script type="text/plain" data-type="text/javascript" data-category="marketing" data-src="/path/to/your/mareketing/script.js"></script> <script type="text/plain" data-type="text/javascript" data-category="external_media" data-src="/path/to/your/external-media/script.js"></script> <script type="text/plain" data-type="text/javascript" data-category="marketing">console.log("Inline scripts are also working!");</script> The type has to be "optin" to get recognized by PrivacyWire, the data-attributes are giving hints, how the script shall be loaded, if the data-category is within the cookie consents of the user. These scripts are loaded asynchronously after the user made the decision.
      If you want to give the users the possibility to change their consent, you can use the following Textformatter:
      [[privacywire-choose-cookies]] It's planned to add also other Textformatters to opt-out of specific cookie groups or delete the whole consent cookie.
      You can also add a custom link to output the banner again with a link / button with following class:
      <a href="#" class="privacywire-show-options">Show Cookie Options</a> <button class="privacywire-show-options">Show Cookie Options</button> This module is still in development, but we already use it on several production websites.
      You find it here: PrivacyWire Git Repo
      Download as .zip
      I would love to hear your feedback 🙂
      CHANGELOG
      0.1.1 Debugging: fixed error during uninstall 0.1.0 Added new detection of async scripts for W3C Validation 0.0.6 CSS-Debugging for hiding unused buttons, added ProCache support for the JavaScript tag 0.0.5 Multi-language support included completely (also in TextFormatter). Added possibility to async load other assets (e.g. <img type="optin" data-category="marketing" data-src="https://via.placeholder.com/300x300">) 0.0.4 Added possibility to add an imprint link to the banner 0.0.3 Multi-language support for module config (still in development) 0.0.2 First release 0.0.1 Early development
    • By bernhard
      --- Please use RockFinder3 ---
    • By MoritzLost
      Cacheable Placeholders
      This module allows you to have pieces of dynamic content inside cached output. This aims to solve the common problem of having a mostly cacheable site, but with pieces of dynamic output here and there.  Consider this simple example, where you want to output a custom greeting to the current user:
      <h1>Good morning, <?= ucfirst($user->name) ?></h1> This snippet means you can't use the template cache (at least for logged-in users), because each user has a different name. Even if 99% of your output is static, you can only cache the pieces that you know won't include this personal greeting. A more common example would be CSRF tokens for HTML forms - those need to be unique by definition, so you can't cache the form wholesale.
      This module solves this problem by introducing cacheable placeholders - small placeholder tokens that get replaced during every request. The replacement is done inside a Page::render hook so it runs during every request, even if the response is served from the template cache. So you can use something like this:
      <h1>Good morning, {{{greeting}}}</h1> Replacement tokens are defined with a callback function that produces the appropriate output and added to the module through a simple hook:
      // site/ready.php wire()->addHookAfter('CachePlaceholders::getTokens', function (HookEvent $e) { $tokens = $e->return; $tokens['greeting'] = [ 'callback' => function (array $tokenData) { return ucfirst(wire('user')->name); } ]; $e->return = $tokens; }); Tokens can also include parameters that are parsed and passed to the callback function. There are more fully annotated examples and step-by-step instructions in the README on Github!
      Features
      A simple and fast token parser that calls the appropriate callback and runs automatically. Tokens may include multiple named or positional parameters, as well as multi-value parameters. A manual mode that allows you to replace tokens in custom pieces of cached content (useful if you're using the $cache API). Some built-in tokens for common use-cases: CSRF-Tokens, replacing values from superglobals and producing random hexadecimal strings. The token format is completely customizable, all delimiters can be changed to avoid collisions with existing tag parsers or template languages. Links
      Github Repository & documentation Module directory (pending approval) If you are interested in learning more, the README is very extensive, with more usage examples, code samples and usage instructions!
    • By Craig
      I've been using Fathom Analytics for a while now and on a growing number of sites, so thought it was about time there was a PW module for it.
      WayFathomAnalytics
      WayFathomAnalytics is a group of modules which will allow you to view your Fathom Analytics dashboard in the PW admin panel and (optionally) automatically add and configure the tracking code on front-end pages.
      Links
      GitHub Readme & documentation Download Zip Modules directory Module settings screenshot What is Fathom Analytics?
      Fathom Analytics is a simple, privacy-focused website analytics tool for bloggers and businesses.

      Stop scrolling through pages of reports and collecting gobs of personal data about your visitors, both of which you probably don't need. Fathom is a simple and private website analytics platform that lets you focus on what's important: your business.
      Privacy focused Fast-loading dashboards, all data is on a single screen Easy to get what you need, no training required Unlimited email reports Private or public dashboard sharing Cookie notices not required (it doesn't use cookies or collect personal data) Displays: top content, top referrers, top goals and more
    • By daniels
      This is a lightweight alternative to other newsletter & newsletter-subscription modules.
      You can find the Module in the Modules directory and on Github
      It can subscribe, update, unsubscribe & delete a user in a list in Mailchimp with MailChimp API 3.0. It does not provide any forms or validation, so you can feel free to use your own. To protect your users, it does not save any user data in logs or sends them to an admin.
      This module fits your needs if you...
      ...use Mailchimp as your newsletter / email-automation tool ...want to let users subscribe to your newsletter on your website ...want to use your own form, validation and messages (with or without the wire forms) ...don't want any personal user data saved in any way in your ProcessWire environment (cf. EU data regulation terms) ...like to subscribe, update, unsubscribe or delete users to/from different lists ...like the Mailchimp UI for creating / sending / reviewing email campaigns *I have only tested it with PHP 7.x so far, so use on owners risk
      EDIT:
      Since 0.0.4, instructions and changelog can be found in the README only. You can find it here  🙂
      If you have questions or like to contribute, just post a reply or create an issue or pr on github, thanks!
×
×
  • Create New...