Transform multi-page PDFs to image (all instead of only the first page)

Zbulo
Zbulo Member Posts: 2

Hi there, I'm using Cloudinary's "transform a resource"-module on the automation platform Make to process user uploads.

Overall this works fine, but when users upload multipage PDFs, only the first page is processed. I read that one can specifcy a particular page to be converted, but I'm looking at convert all pages, no matter their number. Would I need to add another instruction to do so?

https://res.cloudinary.com/zbulo/image/upload/w_800,q_auto:eco/xxx/xxx.jpg

Thanks for your help!

Answers

  • DannyFromCloudinary
    DannyFromCloudinary Member, Cloudinary Staff Posts: 150

    Hey @Zbulo. Thanks for the question.

    Unfortunately there's not currently a way to concatenate all pages of a PDF into a standard image format with a single transformation

    When you convert a pdf into an image format such as a jpg, we will only provide a single page, and by default it's the first page. It you wanted to request a different page, you would need to add the transformation pg_X, where X is a page number. So for page 5 for instance, it would be https://res.cloudinary.com/cloud_name/image/upload/pg5/yourpdf.jpg

    I hope this helps!

    -Danny

  • Zbulo
    Zbulo Member Posts: 2

    Thanks for the quick reply @DannyFromCloudinary, very helpful!

    Is there a way for Cloudinary to recognize the number of pages of a PDF to help me iterate through them?

    Could you recommend a workaround in case an upload has a large number of pages (hundreds)?

  • DannyFromCloudinary
    DannyFromCloudinary Member, Cloudinary Staff Posts: 150

    We have the resources() method of the Admin API which you can read about here, though I don't think this will be particularly useful to Make. What you would need to do is call this method, specifying {pages: true}, which will return the number of pages in the PDF. Once you have that number, you could use a loop to request pg_1, pg_2, etc until the page count is hit.

    I appreciate this is fairly cumbersome though, and as I say, I don't think it plays well with Make, but it is one option that might be able to help.