Jump to content
August

generating PDF-Documents with images

Recommended Posts

Hi again, after trying pages2PDF, RockPDF and mpdf I'm not sure which of them I should use. Of course, there is also wirePDF.

I merged mpdf with rockPDF, add a footer and a page in Landscape and that works, like in the code-snippet below but be am I on the right way?

After that I tried a couple of times rendering an image. Nothing happend, the same with Pages2PDF too. I also copied an Image-URL within processwire and tried further getting an Image within the PDF-Document, but it still display only the red marked placeholder.

I simply would like create an PDF on click from some Pages including the Images.

Are there special requirements on Debian 10 with Apache and php 7.3 using Processwire 3.0.123.?
Is there a guide that I didn't found?
Is somebody out there who has a similar issue solved and would you be so kind to explain?

 

        $pdf = $modules->get('RockPdf');
        $mpdf = $pdf->mpdf;
#        $mpdf->showImageErrors = true;
        $pdf->set('SetHeader', 'header text');
        $mpdf->AddPage('L');
#        $mpdf->Image(urlencode('site/assets/files/1845/image-2.275x200.jpg'), 0, 0, 210, 297, 'jpg', '', true, false);
        $pdf->set('SetFooter', '
<table width="100%">
    <tr>
        <td width="33%">{DATE j.m.Y}</td>
        <td width="33%" align="center">{PAGENO}/{nbpg}</td>
        <td width="33%" style="text-align: right;">whatever</td>
    </tr>
</table>');
        $pdf->show(); // generate pdf

 

Share this post


Link to post
Share on other sites
$img = $pages->get(1)->images->first(); // adjust to your setup
$pdf = $modules->get('RockPdf');
$mpdf = $pdf->mpdf;
$mpdf->WriteHTML('Hello World ' . date('H:i:s'));
$mpdf->WriteHTML('<div>Showing image ' . $img->url . '</div>');
$mpdf->WriteHTML('<img src="' . $img->url . '">');
$pdf->save();

Does this work?

  • Like 1

Share this post


Link to post
Share on other sites

image.png.bbf7541df3ab82cfd0efb4d1414639e1.png

Hi bernhard,

unfortunately, no. Thank you.
The reason for this could be the URL path, the image is only accessible via the complete path (localhost).
This adress in the browser does not work:
"file:///www/home/in..."

 

 

Share this post


Link to post
Share on other sites
13 hours ago, August said:

After that I tried a couple of times rendering an image. Nothing happend, the same with Pages2PDF too. I also copied an Image-URL within processwire and tried further getting an Image within the PDF-Document, but it still display only the red marked placeholder.

I think you need to pass the full (absolute) filename to the mpdf->image() method, not a relative one and not(!) a URL.

$filename = "/absolute/filepath/to/the/image.jpg";

// or when using PWs pageimage
$filename = $image->filename;

// do a test in your script for debugging:
if(!is_readable($filename)) die('Missing file');

$mpdf->AddPage('L');
$mpdf->Image($filename, 0, 0, 210, 297, 'jpg', ...

 

  • Like 2

Share this post


Link to post
Share on other sites
4 hours ago, Jens Martsch - dotnetic said:

You need to use the disk path instead of the URL

I'm using ->url in several spots in my projects and it works. Maybe he messed up something else or maybe our setups are just different. The screenshot looks like he is already using a full disc path /var/www/... and not an url site/assets/...

@August Make sure the file exists on your server and then just try different paths/urls and see which one works for you. Start doing it manually without using pw variables and once you have one working example expand on that one.

  • Like 1

Share this post


Link to post
Share on other sites

Well, yeah, I am using path because of different reasons. Because my images are not available via URL (or only if logged in) as I use pagefileSecure in my config. So the process mPDF has no access to the images, and therefore I use the path.

  • Like 1

Share this post


Link to post
Share on other sites

Hey, lets pull it down to this:

serving the full filesystempath should work everytime, if the file is_readable(),

URL „may“ work most of the time, as the pdf-lib will expand it to the full filesystempath. 

In both scenarios finally the full filesystempath is needed to read, parse, import the imagefile into the pdf object. 

😉

  • Like 1

Share this post


Link to post
Share on other sites
2 hours ago, Jens Martsch - dotnetic said:

Well, yeah, I am using path because of different reasons. Because my images are not available via URL (or only if logged in) as I use pagefileSecure in my config. So the process mPDF has no access to the images, and therefore I use the path.

Nice to know, thx. I haven't been working with pdf for some time but I remember I've always had issues with the correct file paths... I think paths did somehow not work, but not sure. I think they didn't work in older versions of mpdf. There you had to define relative paths (not public urls) to a root path that was set in the module's config. Maybe things have changed to the good 🙂 

  • Like 1

Share this post


Link to post
Share on other sites

Hey Guys, thanks a lot for your replies. Back after work, I have just checked your answers and I'm closely suprised. It is the indication of the absolute path that the image outputs immediately. Bernhards snippet - an excerpt, I took again. Then I only changed one line as in the code-snippet below, that solved the problem. .

$mpdf->WriteHTML('<div>Showing image ' . $img->filename . '</div>');

image.png.916905d03e02045363fab265de0f4fbe.png As in the Screenshot beside, the seond Path(last line) is the right one.

Thank you bernhard, horst and jens - your all commitment is just great!

  • Like 4

Share this post


Link to post
Share on other sites

Hey Guys, I have one more question, in the hope of solving PDF creation problems.

How would you create a download/store -link for a PDF-File from Page using RockPDF/mpdf library on action (may like pages2pdf) ?

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By gebeer
      I am happy to present my new fieldtype FieldtypeImageFromPage. It is made up of 2 modules:
      Fieldtype Image Reference From Another Page is a Fieldtype that stores a reference to a single image from another page. The image can be selected with the associated Inputfield.
      Inputfield Select Image From Page is an Inputfield to select a single image from images on a predefined page and it's children.
      And there also is a helper module that takes care of cleanup tasks.
      This module evolved out of a discussion about my other Module FieldtypeImagePicker.  It caters for use cases where a set of images is being reused multiple times across a site. With this fieldtype these images can be administered through a chosen page. All images uploaded to that page will be available in the inputfield.
      When to use ?
      Let editors choose an image from a set of images that is being used site-wide. Ideal for images that are being re-used across the site.
      Suited for images that are used on multiple pages throughout the site (e.g. icons).
      Other than the native ProcessWire images field, the images here are not stored per page. Only references to images on another page are stored. This has several advantages:
      one central place to organize images when images change, you only have to update them in one place. All references will be updated, too. (Provided the name of the image that has changed stays the same) Features
      Images can be manipulated like native ProcessWire images (resizing, cropping etc.) Image names are fully searchable through the API Accidental image deletion is prevented. When you want to delete an image from one of the pages that hold your site-wide images, the module searches all pages that use that image. If any page contains a reference to the image you are trying to delete, deletion will be prevented. You will get an error message to help you edit those pages and remove references there before you can finally delete the image. How to install and setup
      Download and install this module like any other modules in ProcessWire Create a page in the page tree that will hold your images. This page's template must have an images field Upload some images to the page you created in step 2 Create a new field. As type choose 'Image Reference From Another Page'. Save the field. In 'Details' Tab of the field choose the page you created in step 2 Click Save button Choose the images field name for the field that holds your images (on page template from step 2) Click Save button again Choose whether you want to include child pages of page from step 2 to supply images Add the field to any template You are now ready to use the field View of the inputfield on the page edit screen:

      View of the field settings

      The module can be installed from this github repo. Some more info in the README there, too.
      In my tests it was fairly stable. After receiving your valued feedback, I will eventually add it to the modules directory.
      My ideas for further improvement:
      - add ajax loading of thumbnails
      Happy to hear your feedback!
       
    • By Fanni
      Hi all, 
      I am having some issues uploading a PDF to our website (a problem we’ve had before).
      I have tried reducing the size of the PDF but the problem seems to be with generating the thumbnail image because the upload works under the Fallback mode but the thumbnail is terrible (see attached). 
      Does anybody have any advice about this? Please note that I'm not a developer. 
      Thanks!
       


    • By aComAdi
      Hi,
      Have been working with ProcessWire for a few months now, successfully implementing several sites. I am compiling data management into modules for our clients. Several sites are using those modules now. The modules are using RockMigrations to install fileds, templates and pages.
      Today, I installed a new site. And now I am tripping over an issue that I cannot explain. Content on pages is organized in 'rows'. The users can add row by using RepeaterMatrix...then completing the fields to add data to the row. One particular content row has image fields. When I upload the images to the fields, all works as expected. The images appear in the RepeaterMatrix and I do find the images in assets/files/xxxx. But the images are not displayed in the front-end (see attachment). As you can see in the attachment, the various text and textarea fields in the RepeaterMatrix item are displayed correctly.
      I have done the following:
      Compare field settings to the existing implementations: they are identical Compare the RepeateMatrix settings and permissions to existing implementations: they are identical Change field name. No change. Delete field and created manually (including once with different name). No change. If I dump the element with Tracey, I get the following output:
      If Max Number = 1 null If Max Number = 0 count => 0
      page => "/processwire/repeaters/for-field-136/for-page-1/1574873590-62-1/" (60)
      field => "wk_inhalt_start_links_bild" (26)
      url => "/serverpath/site/assets/files/1046/" (30)
      path => "/serverpath/serverpath/serverpath/serverpath/site/assets/files/1046/" (56)
      items => array () I would venture that there is an issue regarding images on the shared server...but another content element on the site works just fine with images.
      Bit stumped right now. Especially considering that I made the same installation earlier today on a different server successfully. I would appreciate any ideas on where to investigate this issue.

    • By August
      Has anyone already successfully integrated mpdf QrCode Library? I am currently testing bernahrds solution RockPDF including mpdf. I think it would be optimal, but I have problems with some basic things. In this context, what does a proper implementation look like?

      Many thanks in advance
    • By Martin Wuehr
      Hello everybody,
      I'm hosting a Processwire Installation for a client. It runs on Processwire 2.5.3. Over the years everything was fine but now there is an issue with one Image-Field in one Template. Trying to upload an Image the Error "Not enough Memory to load/resize" occure. Other Image-Fields in all other Templates working without any issue. The Images I Tried to upload are very small (600px * 420px). The Images blongs to a News feed, and worked before.
      I read about the problem in the forum but I can't get this solved. I have no access to the php.ini to modify the memory_limit.
      I tried to update the Processwire Verion but failed. (Tried 2.7 /2.8 / 3.2) Got Always Internal Server Error and in the error Log: 
      Compile Error:     Cannot redeclare PageEditFieldPermissionConfig()….
      Has anybody any idea how I can get this solved?
      Thank you so much
      Martin
       
×
×
  • Create New...