Wanze

Pages2Pdf

Recommended Posts

On 21.2.2017 at 5:49 PM, zyON said:

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.

Maybe you can set the headerMargin setting to zero in the WirePDF module configuration? Do you print the header?

Share this post


Link to post
Share on other sites

Hi @Wanze, i tried it all:

 

<img src="<?=$mandant->teaserbild->first()->height('100')->url;?>" width="<?=$mandant->teaserbild->first()->height('100')->width;?>" height="100" alt="logo" />

// AND

<img src="<?=$mandant->teaserbild->first()->height('100')->httpUrl;?>" width="<?=$mandant->teaserbild->first()->height('100')->width;?>" height="100" alt="logo" />

// AND ALSO

$imagedata = file_get_contents($mandant->teaserbild->first()->height('100')->filename);
$base64Img = "data:image/png;base64," . base64_encode($imagedata);
<img src="<?=$base64Img;?>" width="<?=$mandant->teaserbild->first()->height('100')->width;?>" height="100" alt="logo" />

 

but nothing works. How do I enable debug mode (showImageErrors) for the pdf module?

 

Thanks,

thomas

 

Share this post


Link to post
Share on other sites

Strange update:

 

$pdf->save();

shows the images, but

$pdf->download();

doesn't. Not sure what's going on here but I can work around that.

Thanks,

thomas

  • Like 1

Share this post


Link to post
Share on other sites

Greeting,

I need help to use a font 'dejavusans'? I have problems with the display Croatian letters š, đ, č, ć, ž.

I use

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

but I can not set the font 'dejavusans'

<?php

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

$mpdf = $pdf->mpdf;

$pdfPath = $config->paths->files . $page->id . "/" . $page->title.'.pdf';
$stylesheet = file_get_contents($config->paths->templates.'/pages2pdf/styles.css');

$wireSendOptions = array('exit' => false, 'forceDownload' => false, 'downloadFilename' => '');

$mpdf->WriteHTML($stylesheet,1);

$html = "";
$html .= "<html lang='hr'><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /></head><body>";
$html .= '<table border=0>';
$html .= 'text example š đ č ć ž';
$html .= "</body></html>";
$mpdf->WriteHTML($html);

$mpdf->Output($pdfPath, 'F');
wireSendFile($pdfPath, $wireSendOptions );
?>

 

Share this post


Link to post
Share on other sites

In administration, inside the WirePdf configuration, when I set Mode: "s"  then I get a an exception:

mPDF Error - cannot find TTF TrueType font file - /.../site/templates/fonts/DejaVuSans.ttf": invalid checksum 26f399eb8 table: FFTM (expected 6f399eb8)

Can i help me why there is a exception?

Share this post


Link to post
Share on other sites
On 08/03/2017 at 1:52 PM, Wanze said:

Maybe you can set the headerMargin setting to zero in the WirePDF module configuration? Do you print the header?

Wanze, yes thanks. I was missing the configuration options on the WirePDF module (was checking only the Pages2PDF module configuration).

Share this post


Link to post
Share on other sites

I'm trying to use this module to create a PDF of a page on my website. I've tried following along with this thread and the tutorials, etc on Github but I'm still having trouble getting it to work correctly. The page in question is vector.houseofdeadleg.co.uk. If you click on the button the pdf downloads but only includes a header and footer, and any text on the page. I can't get the images to be included.

Share this post


Link to post
Share on other sites

I have this installed on PW3 and my supposed pages2pdf link simply loads the page with the get variable specified ={page.id}, not as a PDF. What could be the matter?

Share this post


Link to post
Share on other sites

Does anybody know how to solve with Pages2Pdf second page content top margin?, I attach an image so you can see that the paragraph hasn't got any padding or margin although is set.

Captura de pantalla 2017-07-26 a las 19.31.24.png

Share this post


Link to post
Share on other sites

see the docs and examples on that page: https://mpdf.github.io/reference/mpdf-functions/addpagebyarray.html

$mpdf->AddPageByArray(array(
    'orientation' => 'L',
    'mgl' => '50',
    'mgr' => '50',
    'mgt' => '50',
    'mgb' => '50',
    'mgh' => '10',
    'mgf' => '10',
    ));

mgt = page margin from the top (where regular text starts, in the example it would start 50mm below the top)

mgh = margin for the header (where the header text ends, in the example it would end 10mm from the top)

 

  • Like 2

Share this post


Link to post
Share on other sites
<?php 

	$pdf = $modules->get('WirePDF');
	$pdf->pageFormat = 'A4';
	$pdf->bottomMargin = 10;

	$mpdf = $pdf->mpdf;

	$mpdf->AddPageByArray(array(
	    'orientation' => 'L',
	    'mgl' => '50',
	    'mgr' => '50',
	    'mgt' => '50',
	    'mgb' => '50',
	    'mgh' => '10',
	    'mgf' => '10',
	    ));

 ?>

Still not getting the margin within header and body, not sure if I've defined it the right way

Share this post


Link to post
Share on other sites

looks fine to me. try it with an empty pdf and the most simple headers & texts possible. maybe your header is just too large and it cannot shrink it (because it's not intended).

mpdf is often trial&error ;)

  • Like 3

Share this post


Link to post
Share on other sites
On 6.6.2017 at 2:18 AM, hellomoto said:

I have this installed on PW3 and my supposed pages2pdf link simply loads the page with the get variable specified ={page.id}, not as a PDF. What could be the matter?

The page you try to download the PDF from (the given ID via get parameter) must:

  • Be viewable for the current user
  • Its template must be allowed to create PDFs (see the module config)

Otherwise you should debug around this line:

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

Cheers

Share this post


Link to post
Share on other sites
9 hours ago, Manol said:

<?php 

	$pdf = $modules->get('WirePDF');
	$pdf->pageFormat = 'A4';
	$pdf->bottomMargin = 10;

	$mpdf = $pdf->mpdf;

	$mpdf->AddPageByArray(array(
	    'orientation' => 'L',
	    'mgl' => '50',
	    'mgr' => '50',
	    'mgt' => '50',
	    'mgb' => '50',
	    'mgh' => '10',
	    'mgf' => '10',
	    ));

 ?>

Still not getting the margin within header and body, not sure if I've defined it the right way

Did you check the settings in the WirePDF module? You can define the margin there, which should be the same for all pages. If it is not working on just one page, there might be a problem with the markup. Maybe you can introduce some manual page breaks for testing this, please see the mpdf documentation for this feature. 

  • Like 1

Share this post


Link to post
Share on other sites

Hello there,

I tried to use SVG files in image tags and some of the vector paths are "destroyed" and everything in the SVG is black.

Then in tried inlining the SVG:

if( $img->ext == "svg")
    echo "<div class'card__img'>".file_get_contents($img->filename)."</div>";
else
    echo "<img class='card__img' src='{$img->url}'>";

This outputs a small icon with a red "X" … meaning; "file not found" … I guess.

Before one of the icons there was this line in the PDF:

<?xml version="1.0" encoding="utf-8"?>

So this means the module found the file but did not render the content.

(… and YES, I saw there is a module "ImageRasterizer", but unfortunately it requires Imagemagick and the pecl imagick extension.)

Share this post


Link to post
Share on other sites
1 hour ago, bernhard said:

hi alf and welcome to the forum

did you read the docs of mpdf regarding svg? https://mpdf.github.io/what-else-can-i-do/images.html

maybe there is some helpful information..

@bernhard

No, but I read the PDF (http://www.mpdfonline.com/repos/mpdfmanual.pdf) and as far as I can see it has the same content … how ever … SVGs "should" work.

So the question is if there is a problem with the module or with my installation or who knows? … if nothing works, I will disable SVG files and I will use PNGs instead …

Share this post


Link to post
Share on other sites

Just in case someone else encounters the same problem:

I had to migrate a whole website to PW and during tests I imported around 200 pages. Now I wanted to delete them and start the real import process. To get rid of the test pages I tried to delete them with adrians AdminActions, but got an error message and nothing was deleted:

Error: Call to a member function path() on a non-object (line 261 of /xxx/site/assets/cache/FileCompiler/site/modules/Pages2Pdf/Pages2Pdf.module) 

I had to detach the template in question in Pages2Pdf settings. Then it worked and I was able to delete the pages.

Same error with a ListerPro Action(Delete), so I asume it's a problem with Pages2Pdf...

PW 3.0.62 Pages2Pdf 1.1.7

  • Like 1

Share this post


Link to post
Share on other sites

I've just added this module to a dev site and when trying to call the module for rendering I'm getting an error – Parse Error: syntax error, unexpected ',' (line 8910 of /Applications/MAMP/htdocs/xxx/site/modules/WirePDF/mpdf/mpdf.php)

 

Additional:

Looking at WirePDF module, it was saying I had two versions, one in the Pages2PDF folder and one separate one, I think one might be a Handover from a previous attempt to use teh same module. I deleted the Pages2PDF folder and the WirePDF one and did a fresh install, now I get teh error message  Compile Error: 'break' not in the 'loop' or 'switch' context (line 2416 of /Applications/MAMP/htdocs/xxx/site/modules/Pages2Pdf/mpdf/classes/svg.php)

Share this post


Link to post
Share on other sites
On 23.8.2017 at 5:05 PM, houseofdeadleg said:

I've just added this module to a dev site and when trying to call the module for rendering I'm getting an error – Parse Error: syntax error, unexpected ',' (line 8910 of /Applications/MAMP/htdocs/xxx/site/modules/WirePDF/mpdf/mpdf.php)

 

Additional:

Looking at WirePDF module, it was saying I had two versions, one in the Pages2PDF folder and one separate one, I think one might be a Handover from a previous attempt to use teh same module. I deleted the Pages2PDF folder and the WirePDF one and did a fresh install, now I get teh error message  Compile Error: 'break' not in the 'loop' or 'switch' context (line 2416 of /Applications/MAMP/htdocs/xxx/site/modules/Pages2Pdf/mpdf/classes/svg.php)

What PHP version are you using? These kind of errors make me guess that mpdf is not compatible with your PHP version. Can you try to use the dev branch of the module via GitHub?

Share this post


Link to post
Share on other sites

I have this

$pdf = $modules->get('Pages2Pdf')->render(array(
  'title' => 'PDF',
  'markup' => '<a href=\'{url}\' target=\'_blank\'>{title}</a>',
  'page_id' => '',
));

$content .= <<<EOT
<script type="text/javascript">
  $("h1").append(" <small>[$pdf]</small>");</script>
</script>
EOT;

which outputs to /?pdf={pid} but clicking the link just opens the current page in a new tab, no PDF.

???

Share this post


Link to post
Share on other sites

Also having a problem with images..

On some pages the PDF shows the image, on other pages the image is missing.

<img src="<?= $page->navimg->url ?>" width="220"/>

 

Share this post


Link to post
Share on other sites

try outputting the image url as plaintext

<p><?= $yourimage->url ?></p>

also check the return setting of your images field. it can be set as array or single image. if it is set as array you would have to define wich image to show (eg $yourimages->first()->url )

Share this post


Link to post
Share on other sites

Hi bernhard,

thank you for the hint.  The image field is set as single element.
 

  <td colspan="1" style="padding:15px">
    <img src="<?= $page->navimg->url; ?>" width="220"/>
    <p><?= $page->navimg->url ?></p>
  </td>

something between ..

<?php if ($page->images->count > 0) : ?>
<table>
  <tr>
  <?php
    $gallery = $page->images;
    $gallery = $gallery->slice(0,4);
   foreach ($gallery as $image): ?>
    <td>
      <img src="<?= $image->size(200, 200)->url ?>" width="200" height="200"/>
    </td>
  <?php endforeach; ?>
  </tr>
</table>
<?php endif; ?>

 

template part:

<?php 
$optionspdf = array(
  'title' => 'Datenblatt',
  'markup' => '<a class="uk-button gaming" href="{url}" download>{title}</a>',
  'pageFormat' => 'A4'
);
echo $modules->get('Pages2Pdf')->render($optionspdf);
?>

 

result:

Unbenannt.thumb.PNG.434147903301c5d7a1ddea668fee6fee.PNG

 

Share this post


Link to post
Share on other sites

@maxf5 Can you check if the image is existing on your hard drive by looking at the file in /site/assets/files? Recently I had a problem in ProcessWire that my thumbnails were not getting generated correctly if I was using numbers like 100,200,300,400 for the dimensions. Strangely it worked by using other dimensions like 110, 390 etc.

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 Robin S
      Password Generator
      Adds a password generator to InputfieldPassword.

       
      Usage
      Install the Password Generator module.
      Now any InputfieldPassword has a password generation feature. The settings for the generator are taken automatically from the settings* of the password field.
      *Settings not supported by the generator:
      Complexify: but generated passwords should still satisfy complexify settings in the recommended range. Banned words: but the generated passwords are random strings so actual words are unlikely to occur.  
      https://modules.processwire.com/modules/password-generator/
      https://github.com/Toutouwai/PasswordGenerator
    • By Robin S
      If you've ever needed to insert links to a large number of files within CKEditor you may have found that the standard PW link modal is a somewhat slow way to do it.
      This module provides a quicker way to insert links to files on the page being edited. You can insert a link to an individual file, or insert an unordered list of links to all files on the page with a single click.
      CKEditor Link Files
      Adds a menu to CKEditor to allow the quick insertion of links to files on the page being edited.

      Features
      Hover a menu item to see the "Description" of the corresponding file (if present). Click a menu item to insert a link to the corresponding file at the current cursor position. The filename is used as the link text. If you Alt-click a menu item the file description is used as the link text (with fallback to filename if no description entered). If text is currently selected in the editor then the selected text is used as the link text. Click "* Insert links to all files *" to insert an unordered list of links to all files on the page. Also works with the Alt-click option. Menu is built via AJAX so newly uploaded files are included in the menu without the page needing to be saved. However, descriptions are not available for newly uploaded files until the page is saved. Installation
      Install the CKEditor Link Files module.
      For any CKEditor field where you want the "Insert link to file" dropdown menu to appear in the CKEditor toolbar, visit the field settings and add "LinkFilesMenu" to the "CKEditor Toolbar" settings field.
       
      http://modules.processwire.com/modules/cke-link-files/
      https://github.com/Toutouwai/CkeLinkFiles
    • By matjazp
      A module for managing files and folders. Supports creating, opening (e.g. viewing, playing, editing), renaming, moving, copying, deleting and searching for files. You can also view and change (not supported on Windows) file and directory permissions. 
      https://github.com/matjazpotocnik/ProcessFileManager

      The author of FileManager component is (c) 2006 - 2018 Gerd Tentler, http://www.gerd-tentler.de/tools/filemanager/. I modified it to work with ProcessWire as a module. Please see license files on usage in commercial projects!
    • By Robin S
      An inputfield for displaying markup editable via CKEditor.
      The module is intended for use with the Form Builder module. Allows blocks of static text to be included within a form, which can be edited in the form settings using CKEditor.
      Usage
      Install the Markup CKEditor module.
      In the Form Builder module settings, add "MarkupCKEditor" to "Inputfield types to use with FormBuilder".
      In your form settings, add a new field of type "Markup CKEditor". Enter the text you want to show in this field using "Markup Text" on the "Details" tab.
      Screenshots


       
      http://modules.processwire.com/modules/inputfield-markup-ckeditor/
      https://github.com/Toutouwai/InputfieldMarkupCKEditor
    • By marcus
      Hi y'all! Long time no see. Here's a little module aiming to help you build accessible websites
      ProcessWire Accessibility Tools
      Download: http://modules.processwire.com/modules/pwat/
      Github: https://github.com/marcus-herrmann/PWAT
      A small, but hopefully growing toolkit for creating accessible ProcessWire sites. Right now it consists of the following little helpers:
      tota11y visualization toolkit by Khan Academy A toggle button to see view site in grayscale. The w3c recommends checking your page without colours to see if your design still works (accompanied by a colours contrast check, which is part of tota11y) A link to test your webpage with WAVE, webaim's Web Accessibility eValuation Tool. By the nature of this tool, the website under test must be available online, local hosts won't work.
      Installation
      Once you have downloaded PWAT, go to your module Install page and click "Check for new modules". Find "ProcessWire Accessibility Tools" and click "Install". During installation, PWAT creates a new role 'pwat_user'. To use the Accessibility Tools, you have to grant user this role.
      Following, you can start configuring the module.

      Usage
      PWAT starts with only the tota11y script activated. On the configuration page you can decide
      whether PWAT is visible on admin pages if tota11y is active if the grayscale toggle is active if the link to WAVE will be visible
      Credits
      The amazing tota11y visualization tool by Khan Academy Inspiration: Paul J. Adam's bookmarklets Inspiration: WordPress wa11y Plugin
      Best,
      marcus