Convert from DOCX to PDF and then email multiple attachments in Power Automate

I am successfully creating and storing/saving plumsail docs from creation as a docx and then also converting them to pdf. After they come back I need to email them to an individual. So there would be an array of 2 converted plumsail pdf files ... I am using this technique here and sometimes it works and sometimes it doesn't work so when the recipient gets the email zero, one or both files are corrupted.

The workaround I heard is to specifically state the content-type ... in addition to the content as properties under contentBytes.
Add multiple attachments to an approval email with Power Automate

The first inspiration is well documented and is here ...
Send an email with multiple (0 – n) item attachments in Power Automate

So I thought I would try and see what the content-type is for the Plumsail pdf's. Thankfully I believe that is simply...

As far as I can tell there's nothing automated to tell me what the content-type is...application/pdf

So instead of this.. (this sometimes works and sometimes doesn't)

{
"Name": "CA_LetterOfEntry.pdf",
"ContentBytes": @{outputs('ConvertCALetterOfEntryToPDF')?['body/fileContent']}
}

I did this...

{
"Name": "USCA_CrossBorderLetter.pdf",
"content": {
"$content-type": "application/pdf",
"$content": @{outputs('Convert_CA2_DOCX_to_PDF')?['body/fileContent']}
}
}

But then outlook barks at me...I tried it with wrapping the @{outputs('Convert_CA2_DOCX_to_PDF')?['body/fileContent']} in quotes and without quotes...

OpenApiOperationParameterValidationFailed

The 'inputs.parameters' of workflow operation 'SendEmailToRequestorsCA' of type 'OpenApiConnection' is not valid. Error details: The API operation 'SendEmailV2' is missing required property 'emailMessage/Attachments/0/ContentBytes'.

I then tried...

{
"Name": "CA_LetterOfEntry.pdf",
"ContentType": "application/pdf",
"ContentBytes": @{outputs('ConvertCALetterOfEntryToPDF')?['body/fileContent']}
}

One file will open but the other doesn't, which makes me think I'm doing some wrong...I have triple checked my work. My process for creating the pdfs from docx is the same.

It seems the answer is this...I need to wrap the result file in base64ToBinary
base64ToBinary(@{outputs('ConvertCALetterOfEntryToPDF')?['body/fileContent']})

How to avoid corrupt email attachment in Power Automate

As soon as I did that it worked.

Ironically I only did it for one of the files in the array and both are now working.... I'm sharing this because ...
a) is it a bug with Plumsail's pdf file creator
b) I don't understand why that's not necessary on one file and why it is on another.
c) I'll add it to both to be safe as supposedly that ensures it's properly encoded.

Hi @sasrsc,

So, if you just take the PDF dynamic content output of the Plumsail action in Power Automate and use it in the attachment field of the action that sends the email does it work ok?

Or does the issue happen when you combine several PDF files into an array and then send the array as an attachment?

If you think that some of the PDF results are corrupted could you save them as PDF using, for example, SharePoint "Create file" action and then share with us the result files?

Please share the PDF files and screenshots of your flow at support@plumsail.com with a reference to the thread. We'll check it further.

Best regards,
Petr
Plumsail team

Hi @sasrsc,

I'll post my flow here too. It works and sends valid PDFs via Outlook action in Power Automate.

Best regards,
Petr
Plumsail team