Merge PDF failing with image files

I have a Microsoft Form that allows attachments. Power Automate is then used to attach the response and attachments and email them. I have had successful tests with docx, xls, pdf attachments, but problems arise when users attach scanned documents that output as jpeg, png etc.

The flow fails with the following error:

**Some of the files are corrupted or encrypted. Please check the following files: **

The file with index 1 is corrupted.
The file with index 2 is corrupted.

These were 2 separate scanned receipts.

Any idea's on how to overcome this?

Many thanks,


The "Merge PDF" action can process only PDF-files so you have to prepare your images for merging. Below, I will show you how to create a DOCX-file with the submitted images and convert it to PDF so it could be merged with other PDF-files or saved as a separate one. The described approach can be integrated in your flow with all modifications you find necessary.

  1. Parse JSON of the attachments field output:

  2. Generate a schema from a sample output of the "Get response details" action:

  3. Create an array variable to store objects with images

  4. Check whether a name of each attachment ends with an image extension (the condition is within "Apply to each" block):

  5. If true, get file content from OneDrive by ID (all submitted attachments are stored there), compose an object with file content and append it to the array variable:

  6. Get a DOCX-template, the token in it should be the same as the property name in the composed object. Use picture formatter to process the image.

  7. Create a document from the template, just pass the array to it as template data, then convert it to PDF.

1 Like

Thank you for your detailed response, Evgeniy!

1 Like