Converting a Word document to PDF document is a common need in organizations, however, I found it quite complicated to achieve in CRM/D365CE Online. Luckily, there is a light of hope at the end of the tunnel.
When a record is created, a PDF document is generated automatically with user input data and attached to the record. Additionally, users want to use the Document Template functionality to apply to the PDF content.
First, we’re going to create a workflow to run on creation of a record. Using Document Template to generate a Word document is easily to achieve. I covered the process in another post here. I’ll continue using the sample in the previous post where a student profile Word document is generated in the Notes pane when a student record is created.
Now, we want to a custom workflow to convert the Word document to a PDF document and attach it to the Notes pane. I’ve considered following approaches having their own pros and cons.
Using third-party Word to PDF conversion libraries
We can use a PDF conversion library to convert the document. We’ll use ILMerge to merge the library with our custom workflow library, when we deploy to CRM.
Pros: easily to achieve and straight forward with .Net/C# code.
Cons: can’t be done because:
- Most PDF conversion libraries call a lot of low-level functions which are restricted in isolated CRM Online environment.
- You may have to purchase a license.
- You need to merge the conversion library with your plugin/custom workflow library before deploying to CRM Online. The merged dll may exceed the size limitation in CRM Online.
I’ve tried a few Word-PDF libraries:
And a few Word-HTML-PDF libraries:
- iTextSharp 4.1.6
Using external PDF conversion service
Pros: even easier to achieve, we just need to call an API and get back the result. It’s outside CRM so no CRM limitation.
- When you use third-party service, it usually costs and is risky when you send sensitive document to their servers.
- When you build your own service, you’ll need to worry about hosting, security and stuff. It may become a separated project, not a requirement or change request. So it will cost much.
Microsoft Flow to the rescue
In my case, I found the above options are not good enough. And Flow is the best option I got so far. The idea of using Flow is to create your own conversion web service which receives a Word document, convert it to PDF, and returns the PDF document, but you don’t have to code.
- It’s outside of CRM, and it is supported and integrated right in CRM Online.
- The document is manageable in customer’s Office 365.
- It’s free! (well, somewhat)
- Easy to configure without any coding.
Cons: of course there are limitations you should consider:
- Flow limits: https://docs.microsoft.com/en-us/flow/limits-and-config
- Billing and meters: https://docs.microsoft.com/en-us/flow/billing-questions
- Plans: https://asia.flow.microsoft.com/en-us/pricing/
In the next part, I’ll show you how to configure a Flow and use it in CRM.
Have a nice day!
One thought on “Convert Word to PDF in Dynamics 365 CE Online with Flow (Part 1)”