Jump to content

Pages2Pdf


Wanze

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?

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

 

Link to comment
Share on other sites

  • 4 weeks later...

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

 

Link to comment
Share on other sites

  • 2 weeks later...

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?

Link to comment
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).

Link to comment
Share on other sites

  • 3 weeks later...

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.

Link to comment
Share on other sites

  • 4 weeks later...
  • 1 month later...

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

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

Link to comment
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
Link to comment
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.)

Link to comment
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 …

Link to comment
Share on other sites

  • 3 weeks later...

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
Link to comment
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)

Link to comment
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?

Link to comment
Share on other sites

  • 2 weeks later...

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.

???

Link to comment
Share on other sites

  • 2 weeks later...

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 )

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

 

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

Link to comment
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
×
×
  • Create New...