Convert Excel to PDF using Nintex Workflow

We recently released the Muhimbi PDF Converter Xtension for Nintex Automation Cloud. You can download it here or learn more about available Muhimbi deployments for Nintex on our product page.

In this guide you'll learn how to convert Microsoft Excel documents to PDF using Nintex Workflows.

In the first part of the guide we use the Muhimbi PDF Converter for SharePoint On-Premises to convert Excel documents to PDF using a Nintex workflow. The Muhimbi PDF Converter for SharePoint On-Premises comes with comprehensive support for all Nintex Workflow versions, currently NW2007 – NW2019.

In the second part of the guide we convert Excel documents using Nintex Workflows (O365) with our REST API. This involves integrating the functionality exposed by the Muhimbi PDF Converter for SharePoint Online directly into a Nintex Workflow by invoking our comprehensive REST API.

Converting Excel files using Nintex with PDF Converter for SharePoint On-Premises

In this example, a Nintex workflow retrieves all the Excel documents modified during the current day and converts them to PDF. In an ideal setup, you will schedule this workflow to run out of office hours to process this as a batch for all new and modified files.

To create a new workflow, you can follow the instructions below or download the complete workflow in NWF format from the following link:

Nintex Workflow to retrieve and convert files to PDF

nintex workflow The finished workflow

Prerequisites

Before we start building the workflow, ensure all prerequisites are in place. It is also assumed that the reader has some knowledge of building Workflows using Nintex Workflow.

  1. Make sure the PDF Converter for SharePoint version 4.1 (or newer) is installed.

  2. Naturally, Nintex Workflow will need to be installed as well.

  3. Make sure the Muhimbi.PDFConverter.Nintex.WebApp SharePoint Feature is activated on the relevant Web Application using SharePoint Central Administration.

  4. You will need to have the appropriate privileges to create workflows.

Creating a new workflow

To get started, create a new workflow and choose the blank template. Make sure the workflow doesn’t start automatically and add the workflow variables listed in the following screenshot.

create new workflow

Ensure that the appropriate data types are assigned. They are listed under the ‘Type’ column beside each variable name. The names are largely self-explanatory, but some additional information is provided below:

  • Source Item ID: By default, the item that triggered the workflow (in our case, the MS Excel file) is converted to PDF format. However, as we are iterating over multiple items, we need to specify the ID of the item to convert in this variable. In SharePoint 2010 and later select Integer as the Type, not List Item ID.
  • Source List ID: The PDF Converter assumes the MS Excel file that is being converted is located in the same list the workflow is attached to. However, if this is not the case, then the list ID (a GUID) will need to be specified as well. In this example, everything is located in the same list, so this variable is not actually used.
  • Source Files: As we are potentially converting multiple MS Excel files we need to define a variable of type Collection to hold the list of files we will be iterating over.
  • Generated PDF Item ID: Once a file has been converted to PDF, you may want to carry out additional actions on this new file. For example, checking it in. Once converted, the ID of the PDF is automatically stored in this variable. In SharePoint 2010 and later select Integer as the Type, not List Item ID.
  • Generated PDF List ID: As the PDF Converter allows files to be written to different document libraries, and even completely different Site Collections, you may want to know the ID of the destination list.

**Adding the workflow actions

You are now ready to add the actions to the workflow. You can start with adding a Query List action, which will allow you to retrieve all files modified today and store the results in the Source Files collection.

add workflow actions

You can fill out the settings for this action as per the screenshot above. You may want to add an additional filter rule to check that Content Type is not equal to Folder or Document Set.

You can continue by adding the For Each action to the workflow. Specify the collection’s name to iterate over and the variable’s name to store the Item’s ID.

specify collection name

The next set of actions you add will need to be added inside the For Each action to ensure they are executed separately for each file in the list.

You need to ensure that the workflow only invokes the PDF Converter for those files that are not already in PDF format. To achieve this, add a condition and check that the file type equals ‘pdf’ as per the following screenshot.
file type equals pdf

After this, you need to add the Convert file to PDF action listed under the Muhimbi PDF section to the No branch of the workflow condition (as we want this workflow to only convert those MS Excel files that are not of type pdf). You can fill this section as per the image below:

convert file to pdf

The PDF Converter integrates with all Nintex Workflow versions.

You may want to leave the Destination Path empty, which will write the PDF File to the exact location as the source file. Hover the mouse over the small information icons for more information about the Destination Path or any other fields.

The workflow is now done. You may want to add some logging information using the Log In the History List action. In our example, we use the following two logging information:

  • Last action in the No branch:
    List ID: {WorkflowVariable:Generated PDF List ID} - List Item ID: {WorkflowVariable:Generated PDF Item ID}
  • Last action in the Yes branch:
    Already in PDF Format: {WorkflowVariable:Source Item ID}

Running the workflow

You can finalize the workflow by saving and publishing it, after which the workflow is ready to be executed.
You can either run the workflow manually or schedule it to run at a specific time of your choice.

For more information and an example of how to use the output of one PDF Workflow Action as the input of the next Action can be found in our blog Combining multiple Muhimbi PDF SharePoint Workflow Activities into a sequence.

Converting MS Excel Files Using Nintex Workflows (O365) using REST API

Note: This tutorial is for the SharePoint Online version of Nintex Workflow.

You can also convert MS Excel files using Nintex Workflows using REST API. This section shows how to integrate the functionality exposed by the Muhimbi PDF Converter for SharePoint Online directly into a Nintex Workflow by invoking our comprehensive REST API.

Although Muhimbi’s comprehensive Web Services (SOAP) interface works well with our on-premise products, the brand-new and much-simplified REST-based interface works very well with cloud-based products.

This new REST-based service is part of the Muhimbi PDF Converter Services Online product. It comes as a separate product and does not have any dependencies on SharePoint and can be used to integrate with services such as Microsoft Flow, Azure Logic Apps, C#, Java, PHP, JavaScript, Python Ruby, and many other services including Nintex Workflow for Office 365. Although available as a stand-alone subscription, this new service is automatically included in each PDF Converter for SharePoint Online subscription at no additional charge.

Prerequisites

Before you begin, please make sure the following prerequisites are in place:

Building the Workflow

This section explains in detail how you can create the workflow to convert MS Excel files to PDF.

This workflow is available for download as well. If you are downloading, you can import it to Nintex Workflow for Office 365, set the API KEY, and publish it. Once the workflow is published, you are ready to go.

If you are creating the workflow step by step, you can navigate to a site collection and document library containing the MS Excel document and choose to create a new Nintex Workflow. In this example, we use the standard Shared Document library available on most site collections.

Create the Following Workflow Variables:

The following Workflow Variables need to be created for the workflow to work correctly:

  • JSON (Text): Contains the JSON, JavaScript Object Notation, the command that will be sent to the conversion service.

  • API_KEY (Text): A unique ID that will be used to look up your Muhimbi subscription details.

  • ResponseText (Text): The status message returned by the Conversion Service.

  • ResponseCode (Integer): The status code returned by the Conversion Service.

    create workflow variables

As a first step, insert a Set Workflow Status action, edit it and set it to Started. This status will let you know that the workflow has actually been triggered (as there is no other way to track this in MS SharePoint Online). This will also give you the option to click on something to inspect the current status of the workflow.

Add a Build String action and set the Output to the JSON workflow variable. In the String field enter the following:

add build string action

When you insert code, pay attention to the following:

  • JSON Notation: You may be familiar with JSON notation, but note that we have replaced the curly braces - { } - with square brackets [ ]. This is due to a bug in Nintex Workflow for Office 365. If you have any concerns about using square brackets (as they are also used for Array types) feel free to replace them with anything else. In a follow-up step we will fix them.
  • Copy & Paste: When pasting this JSON code from the browser window, paste it in Notepad (and copy back) to strip out non-standard characters and formatting.
  • References: The text displayed in red are Nintex Workflow references. After pasting the entire fragment, replace each Nintex reference using the Advanced Lookup facility on the bottom of the text box in the screenshot above.
  • Output file name: In this basic example, we just add '.pdf' to the end of the output path and file name. To keep things simple, we are not including the Nintex Workflow actions to strip off the old extension and add the new one. You can use any valid output path and file name.

As mentioned above, we have used square brackets for JSON above and we need to replace these with curly braces again. You can insert a Replace Substring in String action and configure it as follows:

  • Search String: Enter the opening square bracket [.

  • Replace String: Enter the opening curly brace {.

  • String: Insert a reference to the workflow variable named JSON.

  • Output: Pick the JSON workflow variable to store the results in.

  • Click Save button.

    41

Copy the workflow action (using the actions menu), and paste it as the next action. Configure the newly pasted workflow action and replace the opening bracket with the closing bracket ']'. Do the same for the curly brace, and replace '{' with '}'. Click Save button, and we now have a valid JSON to send to the Conversion Service.

You need to set the API_KEY next. Insert a Set Variable action and configure it to set the API_KEY workflow variable to the API Key you received by email when signing up for the Muhimbi PDF Converter Services Online and click the Save button. E.g.:

decafbad-baad-baad-baad-decafbaaaaad

Note: Do not try to use this particular key, as it will not work. Do not put curly braces around the key.

set api key

Next, you need to insert the Web Request action and configure it as follows:

  • URL: https://api.muhimbi.com/api/v1/operations/convert
  • Method: POST
  • Content type: application/json
  • Add header: Click Add header, specify API_KEY as the Header name and insert a reference to the API_KEY workflow variable for the Header value.
  • Body: Select the Content option, add a reference to the JSON workflow variable in the Data field.
  • Store response content in: ResponseText.
  • Store http status code in: ResponseCode.
  • Click Save button.

insert web request action

Finally, insert another Set Workflow Status action and configure it with the text Completed. This will help us when we run the workflow, as we can now easily see when the workflow has been completed.Your completed workflow should look like the following:

set workflow status

run workflow

oublish workflow

The workflow is complete and can now be published.

Once published, open the document library the workflow is associated with and ensure that a MS Excel file is present. You can manually start the workflow. After a few seconds, the PDF file will show up next to the file the workflow was started on.

Troubleshooting

Although both Nintex Workflow for Office 365 and the Muhimbi PDF Converter work very well together, there are a lot of moving parts in the workflow like custom generated JSON, customer-specific API keys, paths to the document libraries, etc. So, there are chances that you may encounter some issues when deploying the workflow. Some common issues and troubleshooting tips are provided below for your reference:

  • Check prerequisites: Double-check that the prerequisites listed in the beginning of this section are in place.
  • Log to History List: If it is not clear what is going wrong, log critical parts such as the JSON workflow variable (after the replace operation) as well as the ResponseText workflow variable (after the web request) using the Log To History List workflow action. You can see the contents of this list by clicking on the Workflow Status column for the List Item the workflow is running on.
  • Send email: The amount of text that can be logged to the History List is limited (roughly 250 characters). For larger messages, use the Send an Email action instead to send an email with debug content in the body of the email to yourself.
  • Copy & Paste: When copying the JSON fragment into your workflow, paste it into Notepad first to clean it, and then copy it from Notepad and paste it into your workflow. This is because browsers tend to insert hidden characters that are not filtered out by the Nintex Workflow editor.
  • Nintex References: Make sure that actual Nintex Workflow references replace the Nintex Workflow references in the JSON provided. Double-check if the references are active by logging the JSON workflow variable to the History List. You should see the actual paths and not {Current Item:Server Relative URL}.
  • Muhimbi Support: After double checking all the prerequisites and going over all the troubleshooting steps in this section, if you are still stuck, please contact our friendly support desk, who are here to help.

Fine-tuning

The workflow created in the previous section was to give a quick idea of how to use the Converter. However, it would benefit from error handling and a solution for a possible recursion problem where the workflow will be triggered for PDF files it has created.

We have created a version of the workflow that is more production ready. Full details on the same are beyond the scope of this article. You can download the full workflow here and customize this as per your requirements.

After customization, you can import it into Nintex Workflow for Office 365, and set the API KEY, and then publish it for your use.

import nintex workflow

nintex workflow for office 365

set api key

Other Operations

This section demonstrated how to invoke the Convert action on Muhimbi's REST interface to convert an MS Excel file to a PDF. In addition to PDF Conversion, we also expose additional end-points for Merge, Watermark, Secure, Split, OCR, and Copy Metadata operations. Complete examples are beyond the scope of this article, but you can find examples in the SharePoint section of our GitHub repository.

Have a Question?
We’re Always Happy to Help.

© Muhimbi Ltd. 2008 - 2024
This website uses cookies to ensure you get the best experience. Learn more