Jump to content

Recommended Posts

PDF Fieldtype/Inputfield
 
Module for ProcessWire allowing you to easily generate thumbnails of the PDF files embedded to the site.
 
Current version: 1.1.2 (Changelog)

Module page: http://modules.processwire.com/modules/fieldtype-pdf
Github: https://github.com/uiii/ProcessWire-FieldtypePDF

For detailed instructions see: https://github.com/uiii/ProcessWire-FieldtypePDF/blob/master/README.md

  • Like 22

Share this post


Link to post
Share on other sites

Looks great!

A few suggestions if I may :)

I think you should note somewhere is the requirement for imagemagick, ghostscript, and the imagick extension. Also, do a class_exists check on imagick and fail with a nice error if it isn't available.

Also, you may want to add these lines to your code:

$imagick->setOption("pdf:use-cropbox","true");
$imagick->setColorspace(Imagick::COLORSPACE_RGB);

Also, if you find that the colors in the image are not matching those in the PDF, this gives instructions on the changes that need to be made to your imagemagick delegates file: http://www.lassosoft.com/CMYK-Colour-Matching-with-ImageMagick

Share this post


Link to post
Share on other sites

Great first post! ;)

Just quickly looking and reading. I think instead of creating new class with extending Pagefile you could add a method via hook to Pagefile

$this->addHook("Pagefile::thumbnail", $this, "thumbnail");

public function thumbnail($width, $height) {}

Not sure if that's better at all. Looks all ok, and may better extend with new Class... but just wanted to mention.

  • Like 1

Share this post


Link to post
Share on other sites

Hi, thanks for the replies. :-)
 

I think you should note somewhere is the requirement for imagemagick, ghostscript, and the imagick extension ...

 
 Yes, that's right. When and how is the proper way to print this error?
 

$imagick->setOption("pdf:use-cropbox","true");
$imagick->setColorspace(Imagick::COLORSPACE_RGB);
Also, if you find that the colors in the image are not matching those in the PDF, this gives instructions on the changes that need to be made to your imagemagick delegates file: http://www.lassosoft.com/CMYK-Colour-Matching-with-ImageMagick

 
I haven't much experience with ImageMagick. I've just found somewhere the code snippet of "pdf to image" conversion and use it. What consequences will have these two options? 
 
The "delegate" thing - I think it's not related to the module itself.
 

$this->addHook("Pagefile::thumbnail", $this, "thumbnail");

public function thumbnail($width, $height) {}

Hey, I didn't know that it's so simple :-). If it's better or not I don't know, maybe the class is more suitable for future module's extensions.

  • Like 1

Share this post


Link to post
Share on other sites

You can provide the error like this:

if(!class_exists('Imagick')) {
    $this->error(__("This module requires the php imagick extension, but it is not installed"));
}

You could use this in the install routine of the module.

I am not sure how to check for ghostscript. A hacky way would be to include a tiny PDF with your module and run the thumbnail generator on it. If the thumbnail is created, then it must be available. If not, return another error.

The cropbox setting is important because PDFs can have a crop applied to them and if you don't set this, the thumbnail you generate will show the entire contents of the page, not just what is visible in the PDF.

The colorspace_rgb is just to convert colors to RGB. The IM delegates settings I linked to are not something you can do with the module, but I think they are worth noting in your readme. Without those changes, some colors can turn out pretty fluorescent. Of course many thumbnails will look just fine depending on the colors used.

Just an FYI - I created a similar module a long time ago that I haven't ever got around to finalizing for release:

https://github.com/adrianbj/ProcessPDFImageCreator

The main difference with this one is that it creates large preview images for every page of the PDF and then relies on PW to create the thumbnails as requested from these large images. It's not beautifully coded, but you might find something of interest in there. The reasons I never released were because it can be slow to count the number of pages in a PDF (which I wanted to store) depending on what other libraries are available on the server, and also the generation of images for a document of a couple of hundred pages can take a long time and I never got around to setting up something so that this is done in the background after page save.

  • Like 2

Share this post


Link to post
Share on other sites

Fine, thanks. I'll update the module soon.
 

Just an FYI - I created a similar module a long time ago that I haven't ever got around to finalizing for release:
https://github.com/adrianbj/ProcessPDFImageCreator


Yes, I've found it and got a little inspiration. Originally I wanted to use it, but I don't like it requires exact, properly named fields to work. And conversion of the whole PDF isn't my need, just the first page thumbnail. But based on this a got an idea to add optional parameter to the thumbnail method specifing the page number to convert.

Share this post


Link to post
Share on other sites

Yes, I've found it and got a little inspiration. Originally I wanted to use it, but I don't like it requires exact, properly named fields to work. 

Yeah, I didn't know about how to make a configurable module back then :)

  • Like 1

Share this post


Link to post
Share on other sites

Hi and thanks for this nice module  :)

I'm having a bit of a problem with the thumbnail component of the module.  Sometimes when I create a thumbnail the resize creates extra noise in the image. Sometimes deleting the pdf from the page and re-uploading it removes the noise, so it doesn't seem to be an issue with the file itself. For now I'm working around it by commenting out the line in the module that resizes the image ($imagick->scaleImage($width, $height); from PagePDF.php) and using Image's size function. 

0wA5Ygs.jpg

Any help would be appreciated. 

Thanks

Share this post


Link to post
Share on other sites

Hi, thanks for your report. Sorry, but I don't have enough time now to solve the issue. If you can wait until mid-August I will look at that and try to replace the scale function with the ProcessWire's one.

Share this post


Link to post
Share on other sites

Richard are you still there? Haven't seen any activity on this as I filed couple issues on github some time ago. Thanks :D

Share this post


Link to post
Share on other sites

Hi, I'm still there, but I don't have much time to fix the issues. Sorry. If you find the solution you can create a pull request or make your version of the module. If I find some time a will try to look at that. Once again, sorry.

Share this post


Link to post
Share on other sites

I'm having huge problems with ImageMagick on my local setup.

I get the following error in the backend:

NoDecodeDelegateForThisImageFormat `C:/usr/local/domain.local/public_html/site/assets/files/1037/testfile.pdf' @ error/constitute.c/ReadImage/555

As I understand it, this has something to do with image formats. Doing a var_dump(Imagick::queryFormats()) yields an empty array.

I have the php_imagick.dll extension installed, along with the necessary binaries, all in my System PATH.

The only version that works with my PHP 5.5.11 (installed with XAMPP 1.8.3) is ImageMagick 6.8.8-4 Q16 x86. The Windows installer is the same version. Every other version causes PHP to skip loading the extension.

No errors in php_error_log.

Any ideas?

Update - If I run convert -list configure, I see that there is no pdf delegate listed. How do I install that? And why isn't it included with IM?

Update - seems this has more to do with GhostScript... I've always had it installed, so I don't know where the problem is.

Note - Have also asked on SO here: http://stackoverflow.com/questions/27382843

Share this post


Link to post
Share on other sites

Has anyone a hint how to get this awesome module to work if there is no imagick extension on the server but ImageMagick is available as executable? Could it be possible to write a wrapper for the excution of ImageMagick or am I missing something which is only available by the PHP Modul?


By the way ... I want to use it on a managed server from DomainFactory.

Share this post


Link to post
Share on other sites

You could definitely do this so long as you have exec available for PHP and also have imagemagick compiled with ghostscript. 

If these requirements are met, then something like this should work:

exec('convert -density 600 document.pdf[0] -colorspace RGB -resample 300 output.png');

inside the thumbnails function: https://github.com/uiii/ProcessWire-FieldtypePDF/blob/master/PagePDF.php#L7

Share this post


Link to post
Share on other sites

My shared hosting provider has asked me what the minimum version of GhostScript is for this to work. They also need to know if it should be a PHP module or the standalone binaries (added to PATH, I would assume).

Safe to say latest version and binaries?

Share this post


Link to post
Share on other sites

Hi Mike,

I'm not sure if there is some minimal version of ghostscript needed. I have installed ghostscript 9.15 with imagemagick 6.9.0 and according to phpinfo the php's imagick module is of version 3.1.2. In this configuration everything works fine.

No binaries are executed directly from php, the php's imagick module is used (imagick.so in php.ini), but you must have installed ghostscript and imagemagick as a system package.

Hope this helps you.


BTW: If you are going to use this module on PW 2.5, you will probably get some errors. I'm working on that and hope to finish it this week. PW 2.4 should be ok. 

Share this post


Link to post
Share on other sites

Hi Richard,

Seems right to me. Going to let them know now.

The module worked just fine on my 2.5 install - no problems. What errors have you been getting?

Share this post


Link to post
Share on other sites

Really, so you are lucky :-). There are some issues https://github.com/uiii/ProcessWire-FieldtypePDF/issues. Not all issues are fatal, but needs to fix. I have already fixed all of them but not published yet. I have also changed the API (still backward compatible). The new version isn't ready yet, I need to update the documentation and want to add some tests.

Share this post


Link to post
Share on other sites

Hehe, guess so. I originally used it in a development-site on 2.5.13, and have kept up to date since, now on 2.5.23 (current). The only problems I had (only on production server) were specifically about Imagick and GhostScript.

Will give the update a test when you release it. :-)

Share this post


Link to post
Share on other sites

Hi Richard

So GhostScript was installed on my shared server, but I'm getting this now:

 - PDFDelegateFailed `[ghostscript library 8.70] -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pngalpha" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r300x300" -dUseCropBox -dFirstPage=1 -dLastPage=1 "-sOutputFile=/tmp/magick-11484_KMMlcXf5Ras%d" "-f/tmp/magick-11484_ZdfVOglomq7" "-f/tmp/magick-11484jAuPBFSKDl5M"':    **** Warning:  An error occurred while reading an XREF table.
   **** The file has been damaged.  This may have been caused
   **** by a problem while converting or transfering the file.
   **** Ghostscript will attempt to recover the data.
   **** Page has no /MediaBox attribute. Using the current page size.
Error: /stackunderflow in --run--
Operand stack:
   --dict:4/4(L)--   612.0   792.0   3
Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push   1862   1   3   %oparray_pop   1861   1   3   %oparray_pop   1845   1   3   %oparray_pop   --nostringval--   --nostringval--   2   1   1   --nostringval--   %for_pos_int_continue   --nostringval--   --nostringval--
Dictionary stack:
   --dict:1157/1684(ro)(G)--   --dict:1/20(G)--   --dict:75/200(L)--   --dict:75/200(L)--   --dict:106/127(ro)(G)--   --dict:286/300(ro)(G)--   --dict:23/25(L)--   --dict:2/6(L)--
Current allocation mode is local
GPL Ghostscript 8.70: Unrecoverable error, exit code 1
 @ error/pdf.c/InvokePDFDelegate/271

Have you seen this before?

Update: Seems that the error is only appearing for one PDF file. I'll need to convert it or something to get it to work. Anyways, I also got an error saying "Field "certificate_pdf" is not yet ready to use and needs to be configured." I don't quite understand what needs to be configured...

Update: Just saw this - need to upgrade GS.

Share this post


Link to post
Share on other sites

Hi Mike,

I haven't seen this GS error before. I'm not an expert in Ghostscript nor ImageMagick, I have just go through many internet discussions and found working php code for pdf to image conversion. But as you say, it looks like a GS bug.

I also got an error saying "Field "certificate_pdf" is not yet ready to use and needs to be configured." I don't quite understand what needs to be configured...

This is one of the issues in PW 2.5 as I mentioned earlier. See https://github.com/uiii/ProcessWire-FieldtypePDF/issues/6. If you want, you can temporarily use  somatonic's fork or wait for my upgrade. 

Share this post


Link to post
Share on other sites

Hi Richard

I've asked support to upgrade GS to 9.x.

Would rather wait for your upgrade to come out. The site in questions is in need of some layout changes, so getting this working isn't an urgent matter.

:-)

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 d'Hinnisdaël
      Format Datetime fields as Carbon instances.
      You can find the latest release and the complete readme on Github.
      Installation
      composer require daun/datetime-carbon-format Usage
      All Datetime fields will now be formatted as Carbon instances instead of strings. Some examples:
      // $page->date is a Datetime field // Output format: j/n/Y echo $page->date; // 20/10/2020 echo $page->date->add('7 days'); // 27/10/2020 echo $page->date->format('l, F j'); // Monday, October 20 echo $page->date->year; // 2020 echo $page->date->diffForHumans(); // 28 minutes ago Frontend only
      The ProcessWire admin seems to expect datetime fields to be strings. This module will only return Carbon instances on frontend page views.
      Date output format
      When casting a Carbon instance to a string (usually when outputting the field in a template), the field's date output format will be respected.
      Links
      GitHub • Readme • Carbon docs
       
       
      PS. I remember reading about a Carbon module in a recent newsletter, but couldn't find it anywhere. Was that you, @bernhard?
    • By jploch
      Hey folks,
      Iam working on a module that extends InputfieldPageTable. I use PageTableExtended as a starting point and all went well so far, except I can't access my config values outside of the module file. The config values allways return the defaults, and not the values in the pw field settings. 

      Here is the code that sets the defaults inside my inputfield module file:
      public function init() { parent::init(); // defaults $this->set('gridMaxWidth', '1600'); $this->set('gridColumns', '12'); } Here is how I add the config field:
      public function ___getConfigInputfields() { $inputfields = parent::___getConfigInputfields(); $fieldsetGrid = $this->modules->get('InputfieldFieldset'); $fieldsetGrid->label = $this->_('Default Grid Settings'); $f = $this->wire('modules')->get('InputfieldText'); $f->attr('name', 'gridMaxWidth'); $f->attr('value', $this->gridMaxWidth); $f->label = $this->_('Container max width'); $f->description = $this->_('Grid container max width in px'); // page name format description $f->notes = $this->_('default is 1600'); // page name format notes $fieldsetGrid->append($f); $inputfields->append($fieldsetGrid); return $inputfields; } Accessing the values outside my module files like this (this gives me the default: 1600, even if I insert another value in the backend field settings):
      $default = $this->wire('modules')->get('InputfieldPageGrid'); $default->gridMaxWidth; Any Ideas?
    • By xportde
      How does one enable executables to be uploaded to the File field? Just adding the file extension to the accepted extensions does not seem to work.

      screenshot attached (ignore the label 'video')

    • By MoritzLost
      TrelloWire
      This is a module that allows you to automatically create Trello cards for ProcessWire pages and update them when the pages are updated. This allows you to setup connected workflows. Card properties and change handling behaviour can be customized through the extensive module configuration. Every action the module performs is hookable, so you can modify when and how cards are created as much as you need to. The module also contains an API-component that makes it easy to make requests to the Trello API and build your own connected ProcessWire-Trello workflows.
      Warning: This module requires ProcessWire 3.0.167 which is above the current stable master release at the moment.
      Features
      All the things the module can do for you without any custom code: Create a new card on Trello whenever a page is added or published (you can select applicable templates). Configure the target board, target list, name and description for new cards. Add default labels and checklists to the card. Update the card whenever the page is updated (optional). When the status of the card changes (published / unpublished, hidden / unhidden, trashed / restored or deleted), move the card to a different list or archive or delete it (configurable). You can extend this through hooks in many ways: Modifiy when and how cards are created. Modify the card properties (Target board & list, title, description, et c.) before they are sent to Trello. Create your own workflows by utilizing an API helper class with many convenient utility methods to access the Trello API directly. Feedback & Future Plans
      Let me know what you think! In particular:
      If you find any bugs report them here or on Github, I'll try to fix them. This module was born out of a use-case for a client project where we manage new form submissions through Trello. I'm not sure how many use-cases there are for this module. If you do use it, tell me about it! The Trello API is pretty extensive, I'll try to add some more helper methods to the TrelloWireApi class (let me know if you need anything in particular). I'll think about how the module can support different workflows that include Twig – talk to me if you have a use-case! Next steps could be a dashboard to manage pages that are connected to a Trello card, or a new section in the settings tab to manage the Trello connection. But it depends on whether there is any interest in this 🙂 Links
      Repository on Github Complete module documentation (getting started, configuration & API documentation) TrelloWire in the modules directory Module configuration

    • By David Karich
      ProcessWire InputfieldRepeaterMatrixDuplicate
      Thanks to the great ProModule "RepeaterMatrix" I have the possibility to create complex repeater items. With it I have created a quite powerful page builder. Many different content modules, with many more possible design options. The RepeaterMatrix module supports the cloning of items, but only within the same page. Now I often have the case that very design-intensive pages and items are created. If you want to use a content module on a different page (e.g. in the same design), you have to rebuild each item manually every time.
      This module extends the commercial ProModule "RepeaterMatrix" by the function to duplicate repeater items from one page to another page. The condition is that the target field is the same matrix field from which the item is duplicated. This module is currently understood as proof of concept. There are a few limitations that need to be considered. The intention of the module is that this functionality is integrated into the core of RepeaterMatrix and does not require an extra module.
      Check out the screencast
      What the module can do
      Duplicate multible repeater items from one page to another No matter how complex the item is Full support for file and image fields Multilingual support Support of Min and Max settings Live synchronization of clipboard between multiple browser tabs. Copy an item and simply switch the browser tab to the target page and you will immediately see the past button Support of multiple RepeaterMatrix fields on one page Configurable which roles and fields are excluded Configurable dialogs for copy and paste Duplicated items are automatically pasted to the end of the target field and set to hidden status so that changes are not directly published Automatic clipboard update when other items are picked Automatically removes old clipboard data if it is not pasted within 6 hours Delete clipboard itself by clicking the selected item again Benefit: unbelievably fast workflow and content replication What the module can't do
      Before an item can be duplicated in its current version, the source page must be saved. This means that if you make changes to an item and copy this, the old saved state will be duplicated Dynamic loading is currently not possible. Means no AJAX. When pasting, the target page is saved completely No support for nested repeater items. Currently only first level items can be duplicated. Means a repeater field in a repeater field cannot be duplicated. Workaround: simply duplicate the parent item Dynamic reloading and adding of repeater items cannot be registered. Several interfaces and events from the core are missing. The initialization occurs only once after the page load event Attention, please note!
      Nested repeaters cannot be supported technically. Therefore a check is made to prevent this. However, a nested repeater can only be detected if the field name ends for example with "_repeater1234". For example, if your MatrixRepeater field is named like this: "content_repeater" or "content_repeater123", this field is identified as nested and the module does not load. In version 2.0.1 the identification has been changed so that a field ending with the name repeater is only detected as nested if at least a two-digit number sequence follows. But to avoid this problem completely, make sure that your repeater matrix field does NOT end with the name "repeater".
      Changelog
       
      2.0.1
      Bug fix: Thanks to @ngrmm I could discover a bug which causes that the module cannot be loaded if the MatrixRepeater field ends with the name "repeater". The code was adjusted and information about the problem was provided 2.0.0
      Feature: Copy multiple items at once! The fundament for copying multiple items was created by @Autofahrn - THX! Feature: Optionally you can disable the copy and/or paste dialog Bug fix: A fix suggestion when additional and normal repeater fields are present was contributed by @joshua - THX! 1.0.4
      Bug fix: Various bug fixes and improvements in live synchronization Bug fix: Items are no longer inserted when the normal save button is clicked. Only when the past button is explicitly clicked Feature: Support of multiple repeater fields in one page Feature: Support of repeater Min/Max settings Feature: Configurable roles and fields Enhancement: Improved clipboard management Enhancement: Documentation improvement Enhancement: Corrected few typos #1 1.0.3
      Feature: Live synchronization Enhancement: Load the module only in the backend Enhancement: Documentation improvement 1.0.2
      Bug fix: Various bug fixes and improvements in JS functions Enhancement: Documentation improvement Enhancement: Corrected few typos 1.0.1
      Bug fix: Various bug fixes and improvements in the duplication process 1.0.0
      Initial release Support this module
      If this module is useful for you, I am very thankful for your small donation: Donate 5,- Euro (via PayPal – or an amount of your choice. Thank you!)
      Download this module (Version 2.0.1)
      > Github: https://github.com/FlipZoomMedia/InputfieldRepeaterMatrixDuplicate
      > PW module directory: https://modules.processwire.com/modules/inputfield-repeater-matrix-duplicate/
      > Old stable version (1.0.4): https://github.com/FlipZoomMedia/InputfieldRepeaterMatrixDuplicate/releases/tag/1.0.4
×
×
  • Create New...