Search code examples
pythonplonedexterity

Display first page of child file pdf in plone


I have a parent file type that is folderish, and I would like to include a thumbnail of the first page of a child pdf in the template. Can someone roughly outline the tools and process you can imagine would achieve this, so that I can investigate further?


Solution

  • Getting out the first page of pdf can be achieved by using ghostscript. This is an example script which forms an gostscript command and stores the images. I took this from collective.pdfpeek. Which by the way could solve your problem right away :-)

    Until few days ago I would have recommended you not to use it, since it was a little bit buggy, but they recently shipped a new version, so give it a try! I'm not sure whether they now support DX or not.

    So the workflow for you should be.

    1. Uploading a PDF
    2. Subscribe modified/creation events.
    3. create image of first page using ghostscript (check my command, or collective.pdfpeek)
    4. store it as blob (NamedBlobImage) on your uploaded pdf.
    5. Also implement some queueing like collective.pdfpeek to not block all your threads with ghostscript commands.

    OR

    Give collective.pdfpeek a shot!

    BTW: imho on a large scale the preview generation for pdfs needs to be implemented as a service, which stores/manages the images for you.