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

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 Mike Rockett
      Jumplinks for ProcessWire
      Release: 1.5.56
      Composer: rockett/jumplinks
      Jumplinks is an enhanced version of the original ProcessRedirects by Antti Peisa.
      The Process module manages your permanent and temporary redirects (we'll call these "jumplinks" from now on, unless in reference to redirects from another module), useful for when you're migrating over to ProcessWire from another system/platform. Each jumplink supports wildcards, shortening the time needed to create them.
      Unlike similar modules for other platforms, wildcards in Jumplinks are much easier to work with, as Regular Expressions are not fully exposed. Instead, parameters wrapped in curly braces are used - these are described in the documentation.
      Under Development: 2.0, to be powered by FastRoute
      As of version 1.5.0, Jumplinks requires at least ProcessWire 2.6.1 to run.
      View on GitLab
      Download via the Modules Directory
      Read the docs
      Features
      The most prominent features include:
      Basic jumplinks (from one fixed route to another) Parameter-based wildcards with "Smart" equivalents Mapping Collections (for converting ID-based routes to their named-equivalents without the need to create multiple jumplinks) Destination Selectors (for finding and redirecting to pages containing legacy location information) Timed Activation (activate and/or deactivate jumplinks at specific times) 404-Monitor (for creating jumplinks based on 404 hits) Additionally, the following features may come in handy:
      Stale jumplink management Legacy domain support for slow migrations An importer (from CSV or ProcessRedirects) Feedback & Feature Requests
      I’d love to know what you think of this module. Please provide some feedback on the module as a whole, or even regarding smaller things that make it whole. Also, please feel free to submit feature requests and their use-cases.
      Note: Features requested so far have been added to the to-do list, and will be added to 2.0, and not the current dev/master branches.
      Open Source

      Jumplinks is an open-source project, and is free to use. In fact, Jumplinks will always be open-source, and will always remain free to use. Forever. If you would like to support the development of Jumplinks, please consider making a small donation via PayPal.
      Enjoy! :)
    • By BitPoet
      As threatened in Ryan's announcement for 3.0.139, I built a little module for sliding toggles as a replacement for checkboxes. Styling of the input is CSS3 only (with all the usual caveats about older browsers), no JS necessary, and may still be a bit "rough around the edges", so to speak, since I didn't have much time for testing on different devices or brushing things up enough so I'd feel comfortable pushing it to the module directory. But here's the link to the GitHub repo for now:
      InputfieldSlideToggle
      Fieldtype and Inputfield that implements smartphone-style toggles as replacement for checkbox inputs. The visualization is CSS-only, no additional JS necessary.
      Status
      Still very alpha, use with caution!
      Features / Field Settings
      Size
      You can render the toggles in four different sizes: small, medium, large and extra large.
      Off Color
      Currently, "unchecked" toggles can be displayed either in grey (default) or red.
      On Color
      "Checked" toggles can be rendered in one of these colors: blue (default), black, green, grey, orange or red.
      Screenshots

      Some examples with checkbox label


      View all Size and Color Combinations
      Small toggles Medium toggles Big toggles Extra big toggles  









    • By Orkun
      Hi Guys
      I needed to add extended functionalities for the InputfieldDatetime Module (module is from processwire version 2.7.3) because of a Request of Customer.
      So I duplicated the module and placed it under /site/modules/.
      I have added 3 new Settings to the InputfieldDatetime Module.
      1. Day Restriction - Restrict different days based on weekdays selection (e.g. saturday, sunday) - WORKING

       
      2. Time Slots - Define Time slots based on custom Integer Value (max is 60 for 1 hour) - WORKING

       
      3. Time Range Rules per Weekday - Define a minTime and MaxTime per Weekday (e.g. Opening Hours of a Restaurant) - NOT WORKING PROPERLY

       
      The Problem
      Time Slots and Day Restriction working fine so far. But the Time Range Rules per Weekday doesn't work right.
      What should happen is, that when you click on a date, it should update the minTime and maxTime of the Time Select.
      But the change on the select only happens if you select a date 2 times or when you select a date 1 time and then close the datepicker and reopen it again.
      The time select doesn't get change when you select a date 1 time and don't close the picker.
      Here is the whole extended InputfieldDatetime Module.
      The Files that I have changed:
      InputfieldDatetime.module InputfieldDatetime.js jquery-ui-timepicker-addon.js (https://trentrichardson.com/examples/timepicker/) - updated it to the newest version, because minTime and maxTime Option was only available in the new version  
      Thats the Part of the JS that is not working correctly:
      if(datetimerules && datetimerules.length){ options.onSelect = function(date, inst) { var day = $(this).datetimepicker("getDate").getDay(); day = day.toString(); var mintime = $(this).attr('data-weekday'+day+'-mintime'); var maxtime = $(this).attr('data-weekday'+day+'-maxtime'); console.log("weekday: "+day); console.log("minTime: "+mintime); console.log("maxTime: "+maxtime); var optionsAll = $(this).datetimepicker( "option", "all" ); optionsAll.minTime = mintime; optionsAll.maxTime = maxtime; $(this).datetimepicker('destroy'); $(this).datetimepicker(optionsAll); $(this).datetimepicker('refresh'); //$.datepicker._selectDate($(this).attr("id"),date); //$.datepicker._base_getDateDatepicker(); // var inst = $.datepicker._getInst($(this)); // $.datepicker._updateDatepicker(inst); /*$(this).datetimepicker('destroy'); InputfieldDatetimeDatepicker($(this), mintime, maxtime); $(this).datetimepicker('refresh'); */ // $(this).datetimepicker('option', {minTime: mintime, maxTime: maxtime}); } } Can you have a look and find out what the Problem is?
      InputfieldDatetime.zip
       
      Kind Regards
      Orkun
    • By teppo
      This module tracks changes, additions, removals etc. of public (as in "not under admin") pages of your site. Like it's name says, it doesn't attempt to be a version control system or anything like that - just a log of what's happened.
      At the moment it's still a work in progress and will most likely be a victim of many ruthless this-won't-work-let's-try-that-instead cycles, but I believe I've nailed basic functionality well enough to post it here.. so, once again, I'll be happy to hear any comments you folks can provide
      https://modules.processwire.com/modules/process-changelog/
      https://github.com/teppokoivula/ProcessChangelog
      How does it work?
      Exactly like it's (sort of) predecessor, Process Changelog actually consists of two modules: Process Changelog and Process Changelog Hooks. Hooks module exists only to serve main module by hooking into various functions within Pages class, collecting data of performed operations, refining it and keeping up a log of events in it's own custom database table (process_changelog.) Visible part is managed by Process Changelog, which provides users a (relatively) pretty view of the contents of said log table.
      How do you use it?
      When installed this module adds new page called Changelog under Admin > Setup which provides you with a table view of collected data and basic filtering tools See attached screenshots to get a general idea about what that page should look like after a while.
      For detailed installation instructions etc. see README.md.
       


    • By Gadgetto
      Status update links (inside this thread) for SnipWire development will be always posted here:
      2019-08-08
      2019-06-15
      2019-06-02
      2019-05-25
      If you are interested, you can test the current state of development:
      https://github.com/gadgetto/SnipWire
      Please note that the software is not yet intended for use in a production system (alpha version).
      If you like, you can also submit feature requests and suggestions for improvement. I also accept pull requests.
      ---- INITIAL POST FROM 2019-05-25 ----
      I wanted to let you know that I am currently working on a new ProcessWire module that fully integrates the Snipcart Shopping Cart System into ProcessWire. (this is a customer project, so I had to postpone the development of my other module GroupMailer).
      The new module SnipWire offers full integration of the Snipcart Shopping Cart System into ProcessWire.
      Here are some highlights:
      simple setup with (optional) pre-installed templates, product fields, sample products (quasi a complete shop system to get started immediately) store dashboard with all data from the snipcart system (no change to the snipcart dashboard itself required) Integrated REST API for controlling and querying snipcart data webhooks to trigger events from Snipcart (new order, new customer, etc.) multi currency support self-defined/configurable tax rates etc. Development is already well advanced and I plan to release the module in the next 2-3 months.
      I'm not sure yet if this will be a "Pro" module or if it will be made available for free.
      I would be grateful for suggestions and hints!
      (please have a look at the screenshots to get an idea what I'm talking about)
       




×
×
  • Create New...