Enhancing PDF Generation in Power Automate with Plumsail Documents

Tech
June 25, 2024

Data processes typically break down into three key components: inputs, processes, and outputs. A streamlined, automated process to manage these inputs and produce accurate outputs is crucial for efficient workflow. Since these outputs often include creating Word and PDF files, –  Plumsail Documents comes in very handy for document generation within Microsoft Power Automate. Plumsail offers a user-friendly and efficient alternative to more traditional methods, simplifying the complexities often associated with PDF creation. 

While Power Automate does provide several options for generating PDFs, these can be cumbersome and costly. Historically, creating complex HTML pages and using OneDrive’s file conversion tool (currently in Preview) or the “Word Online (Business)” connector, which requires a premium license, was the norm. Although Microsoft’s “Print()” function in PowerApps is a recent addition, it is limited to single-screen layouts and doesn’t quite meet the needs for more comprehensive document generation.  

Three Power Automate Actions currently available for Generating “PDF” Outputs

Microsoft currently offers three options for PDF outputs:


Option 1 – OneDrive for Business, which is currently in Preview.

Option 1 – OneDrive for Business, which is currently in Preview.

Option  2 – Word Online (Business), a Premium feature.

Option  2 – Word Online (Business), a Premium feature.

Option 3 – PowerApps Print() Screen which offers limited formatting capabilities.

Option 3 – PowerApps Print() Screen which offers limited formatting capabilities.

Plumsail Documents, on the other hand, streamlines this process, making it more accessible and less resource-intensive. In this blog we explore how Plumsail Documents can transform your document generation within Microsoft Power Automate, providing a more streamlined and user-friendly solution.

Introducing Plumsail Documents

For those seeking a simpler, low-code solution, Plumsail Documents presents an attractive option. While there is a cost associated with this connector (based on usage volumes), its ease of implementation and support for various document formats can significantly expedite development. Plumsail Documents not only facilitates PDF creation but also supports Word, Excel, and PowerPoint file generation.

You can explore this further with a 14-day free trial, allowing you to create a developer API key for integration into your Power Automate solutions. Please be aware that trial documents will be watermarked, and this watermark can be removed by subscribing to a paid plan.

Below are the Plumsail Documents actions that are available for use with a subscription, including the ability to work with a variety of document types. Here are the Plumsail Documents actions available for use with a subscription, offering versatile capabilities to handle various document types effectively.

Plumsail Documents actions that are available for use with a subscription

Why Choose Plumsail Documents Over Power Automate’s Native Connector?

Plumsail Documents offers several distinct advantages over Power Automate’s “Convert Word Document to PDF” connector, including:

  1. Custom Templates and Document Generation: Plumsail allows the creation of complex templates for diverse document types, enhancing flexibility and functionality.
  2. Complex Data Integration: Integrate structured data like JSON to populate documents with nested sections, data-driven tables, and more.
  3. Multiple File Format Support: Generate PDFs, DOCX, XLSX, PPTX, and other formats, catering to various document-related workflows.
  4. Advanced Document Operations: Merge, split PDFs, and extract text for more intricate document processes.
  5. Seamless Integration: Designed for easy integration with Power Apps and Power Automate, ensuring smooth document workflows.
  6. Cloud Storage Integration: Compatible with SharePoint, OneDrive, and Google Drive, facilitating direct document saving.
  7. Customization and Scalability: Scalable infrastructure supports growing document generation needs, making it ideal for businesses with expanding requirements.

Building a Power Automate Flow with Plumsail Documents

Incorporating Plumsail into your workflow typically involves several steps, starting with the creation of your Power App (if necessary for the front end) and then integrating it with Plumsail Documents actions. Here’s an example illustrating how to develop a Power App for generating a PDF document using Plumsail Documents based on user inputs.

In this scenario, we’ve developed a basic mobile Power App designed to collect a “Service Request” from users, generate a PDF document, save it to a SharePoint document library, and send it as an email attachment.

This application was created using a SharePoint list as the data source. For more detailed instructions on creating a canvas app from a list, please refer to this article: Create a canvas app with data from Microsoft Lists (includes video) – Power Apps | Microsoft Learn.

The SharePoint List Schema

The basic Power App features a standard gallery view of all records and a “View / Edit” screen for basic CRUD (Create, Read, Update, and Delete) operations.

When a record is submitted to the Service Request list, the Power Automate flow is automatically triggered. The flow proceeds to generate a PDF, store it, and email the output.

The SharePoint List Schema

Power App – Data Entry Form

Power App – Data Entry Form

Power App – Requests Browse Gallery

Power App – Requests Browse Gallery

The Power Automate Flow

Broadly speaking, the Power Automate flow appears as follows.

The Power Automate Flow

Here’s a breakdown of each section:

First, we’ve initialized a variable named ‘strTemplateJSON’ to accumulate and structure all variable data in JSON format, which will be forwarded to the Plumsail action. Additionally, ‘strCompanyInfo’ stores JSON representing our fictional company, and ‘strFilename’ designates the name for the generated document.

It’s important to note that this approach accommodates passing text, numeric data, and even graphical images such as signatures captured via pen input controls.

In this instance, we’re retrieving a sample company logo stored in an image library directly by referencing and formatting the JSON. The image data itself is sourced from the SharePoint internal property ‘Thumbnail Large’.

Power Automate Flow – Get Company Logo / Data

Power Automate Flow – Get Company Logo / Data

Next, we compile our JSON into a single variable named ‘strTemplateJSON’ like this.

Here’s a bonus developer tip: JSONLint offers a fantastic free tool for validating your JSON code format.

Power Automate Flow – Compile all JSON into a Single Element

Power Automate Flow – Compile all JSON into a Single Element

After assembling the JSON data, the next step involves acquiring a handler to the DOCX template intended for the population. Before this, the template file contents must be converted to Base64 format. Subsequently, both the ‘Template File’ contents and ‘Template Data’ are passed to the ‘Create document from DOCX template’ function, with the output specified as ‘PDF’.

Power Automate Flow – Populate Template

Power Automate Flow – Populate Template

The Microsoft Word Document Template

We have saved our DOCX template in a SharePoint library named “Documents Template.” The document is displayed below with variable placeholders. As indicated in the previously compiled JSON, the corresponding data will replace these placeholders. Specific formatting is applied to image data, allowing you to specify the exact size of the image for rendering, as demonstrated below.

Microsoft Word – DOCX Template with Variable Placeholders

Microsoft Word – DOCX Template with Variable Placeholders

To fetch the template, we use the SharePoint ‘Get file content’ action.

‘Get file content’

The next step is to create an action to convert the file content to Base64 using the following expression: base64(outputs(‘Get_file_content’)?[‘body’]).

Base64

Finally, this is where the true magic unfolds in the Plumsail connector. We pass the converted template file through ‘Outputs’ along with the template data sourced from the assembled JSON string variable.

In this scenario, Plumsail will send the converted file through the ‘Body’ value, which contains the populated data. Therefore, our next logical step is to execute a SharePoint ‘Create file’ action. Here, we’re saving it to the Shared Documents library on SharePoint, though it could alternatively be stored in OneDrive or any other compatible and accessible cloud storage location.

Create file

If we didn’t need to email this as an attachment, we would be finished now. However, to send this as an attachment, we’ll need to include a SharePoint “Get file content” action to retrieve the document we just created.

Get file content

To attach this PDF to a list item, we will employ the SharePoint ‘Add attachment’ action, using the ID that originally triggered our flow. In this scenario, the ‘Body’ contains the data retrieved from the preceding SharePoint ‘Get file content’ action.

Power Automate Flow – How to Add as SharePoint List Item Attachment

Power Automate Flow – How to Add as SharePoint List Item Attachment

To send the document as an attachment in an email, we will configure the ‘Send an email (V2)’ action.

Power Automate Flow – Send Email with Attachment

Power Automate Flow – Send Email with Attachment

The final result will be delivered to your inbox along with the attachment. Opening the attachment will display our finalized PDF output, complete with all populated data, including the image logo.

The PDF Document Template

Here is the final PDF displaying all our outputs.

Power Automate Flow – Send Email with Attachment

Power Automate Flow – Send Email with Attachment

Repeating JSON data can also be used, for example in a classic invoice or purchase order header or footer. Table rows can also be auto-populated based on the data.

Want to Know More?

You can read more about the Plumsail Documents and Power Automate here:

As a Plumsail partner, Elantis offers discounts of up to 10% on subscriptions. For more information or a demonstration, contact our team of automation experts, or discover how Elantis can enhance your Power Platform solutions by exploring our services here.  Embrace the power of Plumsail Documents to streamline your document generation workflows and enhance productivity!



SUBSCRIBE TO OUR BLOG

Skyrocket your business with Elantis!

Elantis is your trusted partner in revolutionizing your business operations and taking them to the stratosphere. Our modern solutions support content and collaboration, automation and productivity, governance and compliance, organizational change management, and data analytics—ensuring that your organization stays light-years ahead of the competition.

Ready for lift off? Let’s get started.

RELATED ARTICLES

Discover a Better Way to Manage Records: How Switching from OpenText to Microsoft Purview Enhances Compliance and Efficiency

Discover a Better Way to Manage Records: How Switching from OpenText to Microsoft Purview Enhances Compliance and Efficiency

In the daily operations of municipalities and other public sector organizations, maintaining productivity and delivering top-tier services to constituents hinges crucially on effective records management. Yet, many government entities struggle with outdated, unresponsive, and insecure systems that hinder their ability to manage records effectively. In this blog, discover the substantial advantages of transitioning from traditional records management solutions like OpenText to Microsoft Purview.

read more
Tackling Content Sprawl in Microsoft Teams and SharePoint: A Quick Guide

Tackling Content Sprawl in Microsoft Teams and SharePoint: A Quick Guide

Content sprawl is a growing concern for organizations leveraging Microsoft Teams and SharePoint for collaboration and document management. As teams create and share files, the risk of unmanaged content accumulation can lead to inefficiencies, security risks, and compliance issues. In this blog, we will delve into the challenges of content sprawl, identify signs of it, outline a governance plan to manage it, and provide best practices and tips to control it effectively.

read more
Mastering Document and Record Lifecycle Management with Microsoft Purview

Mastering Document and Record Lifecycle Management with Microsoft Purview

In today’s digital landscape, effective document and record management is essential. Microsoft Purview helps meet legal obligations, ensures compliance, and boosts efficiency by regularly disposing of unnecessary items. This blog explores leveraging Microsoft Purview for streamlined management, the cost of lacking a system, and tips for maximizing its benefits.

read more