Secure PDFs using Power Automate

One of the many advantages provided by the PDF file format is the ability to password protect files to make sure they cannot be opened by un-authorized users. Even more useful, in my opinion, is the ability to apply restrictions to PDF files to prevent users from copying its content or even sending it to a printer.

The best way to show how this works is by example.What follows is a walkthrough of how to create a simple Flow to automatically apply security settings to any new or modified PDF file in a Document Library.

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

  • Muhimbi PDF Converter Services Online full, free or trial subscription(Sign up).
  • Appropriate privileges to create Flows.
  • Working knowledge of Microsoft Power Automate and SharePoint Online.

In this example,  we will upload a file in SharePoint Online, our Flow will be triggered when the file is created in the document library and then Secure it.

Note:  Because we are running the workflow when PDF files are created as well as modified, we need to add a new Yes/No column named Secured  the document library using a default value of No. This way we can mark a document as secured and stop Flow  from recursively triggering.

Step 1:

  • Setting up your SharePoint Online Environment.
  • Create a SharePoint Online List and Add with name Secured: Column type – Yes/No (Default value ‘No‘) – This will be used to prevent recursive flows.

Step 2:

  • Open the MS Flow designer, create a flow and find the ‘When a file is created or modified (properties only)’ trigger. Using this trigger will allow you to start the flow when adding or modifying a property of a file into a folder.
  • In the action, specify the path to the SharePoint Online Library to monitor for new items.

Step 3:

  • In this step (Condition) we will manage the recursive event (continuous loop).
  • I am using the AND operator to prevent an endless loop from happening.
    • Secured’ (Output of ‘When an item is created or modified’ trigger) is equal to ‘false’.
    • Expression ‘split(triggerBody()?[‘{FilenameWithExtension}’],’.’)[1]‘(this will return the file extension)  is equal to ‘pdf’.

The ‘Secured’ is a Column of type ‘Yes/No’ and the default value is set to ‘No (false)’. Only if both the values evaluate to true, it will Secure the PDF or else it will just terminate the Flow. We will set the ‘Secured’ field to ‘False (No)’ in the ‘Update File Properties’ action in our Flow later.

As the Flow updates a column and writes back the file in the same item, the Trigger (‘When an item is created or modified’) will always be invoked. However, now that we have set the ‘Secured’ field to ‘True (Yes)’, the Flow will be terminated when it is triggered a second time.

Confused? Just follow the instructions below and everything should be clear by the end.

Step 4 :

  • If both conditions evaluate to ‘true (Yes)’, OCR the document else ‘false (No)’, terminate the Flow.

Step 5:

  • Add the ‘Get file content’ SharePoint action and pass the ‘Identifier’ value into the File field (Output of ‘When an item is created or modified’ trigger).

Step 6:

  • Add the Muhimbi ‘Secure PDF’ action.
    • Source Filename – Add the ‘File Content’ the output of the ‘Get file content’ SharePoint Action.
    • Open Password: An optional password that the user must enter in order to open the document. Please note that any password entered here is displayed in clear text to allow Power Automate action field references to be added.
    • Owner Password: An optional password that the user must enter in order to change the PDF restrictions. When specifying any PDF Restrictions then this password must be set. Please note that any password entered here is displayed in clear text to allow Power Automate action references to be added.
    • One or more restrictions to apply to the PDF file, separated by a pipe ‘|’ character . By default it applies all restrictions(Print|HighResolutionPrint|ContentCopy|Annotations|FormFields|ContentAccessibility|DocumentAssembly), but any combination is allowed. Enter the word Nothing to not apply any restrictions. In order to activate these settings you must supply an owner password.

Step 7:

  • Add the SharePoint Online ‘Update file properties’ action.
    • Site Address: Update the site-collection address.
    • Library Name: Specify the Source Library Name.
    • Id – ‘ID’ the output of the ‘When a file is created or modified (properties only)’ action.
    • Title – ‘Title’  the output of the ‘When a file is created or modified (properties only)’ action.
    • Secured – Set it to ‘Yes’.

Step 8:

  • Use the ‘Create file’ SharePoint action to write the generated PDF document to the output document library.
    • File name: ‘File Name with extension’  output of the ‘When a file is created or modified (properties only)’ action.
    • File Content: Processed file content is the output variable of the ‘Secure’ action.

All Done! Upload a PDF to the source library. After a few seconds your file will be secure in the source library.



Important!

  • The SharePoint Online List item is updated.
  • The ‘Secured” field is set to ‘Yes’.

As the SharePoint Library column is updated, the Flow will be triggered again. However, this time it will not Secure the document it will just Terminate the Flow.

Thanks for reading!

Subscribe to this blog for the latest updates about SharePoint Online, Power Automate (Microsoft Flow), Power Apps and document conversion and manipulation using The PDF Converter.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s