Converting Modern SharePoint Online Pages (ASPX pages) to PDF

One of the most common questions asked by customers of The Muhimbi PDF Converter Services Online regards using The PDF Converter to convert Modern Experience SharePoint Online pages to PDF in conjunction with Microsoft Flow, Logic Apps, and PowerApps.  The short answer is yes, The PDF Converter can certainly do this, the longer answer (how to do it) is the topic of this blog post.

For those not familiar with the product, The Muhimbi PDF Converter Online is one of a line of subscription services that converts, merges, watermarks, secures, and OCRs files from Microsoft Flow, Logic Apps, and PowerApps.  Not to mention your own code using C#, Java, Python, JavaScript, PHP, Ruby and most other modern platforms.

In his post, we’ll show you how to create a Power Automate (Flow) solution to select a  Modern SharePoint Online page from the Site pages App and convert it to PDF.

Prerequisites

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

Now, on to the details of how to create a Power Automate (Flow) solution to select a  Modern SharePoint Online page from Site pages App and convert it to PDF.

First, let’s review how the basic structure of our Power Automate (Flow) looks:

Flow

Step 1 – Trigger (For a Selected File)

  • We use the SharePoint trigger ‘For a selected file’.
  • For the ‘Site Address’ in the image below, choose the correct site address from the drop down menu.
  • The Modern Pages or ASPX pages are stored in a special App called Site Pages which is not an App of type Library.  So, our Site Pages app won’t appear in the drop down menu.  Instead, what you will get as choices in the drop down menu are Library names.

NoteWe can basically go ahead and convert any ASPX page sitting in any of the libraries across SharePoint Online. For the sake of this blog post, I am targeting the Site pages (ASPX pages) that are present inside the Site Pages Library.

  • So what we can do is enter the GUID value of the Site Pages App to get all items (in other words Pages) present in the Site Pages.
  • For obtaining the GUID value, navigate to the Library settings and  copy the Encoded GUID value from the URL as shown in the image below-

GUID

  • This is the however not the correct GUID that we want since this is Encoded. We need the GUID in its pure Decoded form.
  • Navigate to this site and enter the copied GUID and click on Decode as shown in the image below.

Decoded

  • Remember we get the Decoded GUID in curly brackets, however while adding this GUID in the ‘Library Name’ option as a custom value you need to enter just the GUID without the curly brackets as shown below.

Capture

Step 2 – Get File Properties

  • For the ‘Site Address’ in the image below, choose the correct site address from the drop down menu.
  • For the ‘Library Name‘, enter the same GUID value as in the previous step.
  • For the ‘Id‘ as shown in the image below, navigate to ‘Add Dynamic Content‘ line and choose ‘ID‘ from the ‘For Selected File‘ action.

Capture1

Step 3 – Convert HTML to PDF

  • In the ‘Source URL or HTML’ section shown in the image below, navigate to ‘Add Dynamic Content‘ line and choose ‘Link to item‘ from the ‘Get file properties‘ action.
  • In the ‘Page orientation’ field, select the appropriate option. Depending on the content and layout of the page ‘Portrait’ may work out best.
  • In the ‘Media type’ field, select the ‘Print’ option from the drop down menu. (This automatically strips out most of the SharePoint User interface).
  • Select ‘SharePoint Online’ as the ‘Authentication type’ from the drop down menu.
  • You will need to enter the correct ‘User name’ and ‘Password’ to get authenticated with the SharePoint Online authentication that you selected in the authentication field above.
  • If you are not comfortable with passing credentials directly in the Power Automate action and in plain text, you can create a Secret in Azure and pass this secret.
  • For more details, check out my blog post on ‘Using Azure Key vault to avoid passing Credentials in Power Automate‘.
  • In the ‘Conversion Delay’ field, enter a delay of 10000 (in milliseconds, so 10 seconds).  This delay will give the page time to load before it is converted.

HTML

Step 4 – Create File

  • For the ‘Site Address’ in the image below, choose the correct site address from the drop down menu.
  • Select the correct ‘Folder Path’ where the converted PDF should be created.
  • Give a meaningful ‘File Name’ to the created PDF, but make sure you remember to add the extension ‘.pdf’ after the ‘File Name’ and to make the file name unique, or multiple runs of the flow will overwrite the same file.  I recommend basing it on the source file name. You can get this by navigating to the Add dynamic content line and choose ‘Name’ inside the ‘Get File properties‘ action.
  • Select the ‘Processed file content’ option, shown in the image below, to populate the ‘File Content’ field.

Name

That’s it, navigate to the Site pages app, select a Site page and run the Power Automate for the selected Page as shown below-

HowToConvert

To see the fruits of our labor, please see below what the Wiki page looks like when viewed in a browser and how it looks as a PDF.

Source Wiki Page –

Original Page

Converted PDF –

Untitled

Microsoft is constantly making changes in the Modern Experience part so we cannot ignore edge cases. The Modern View implementation is updated so often, it is next to impossible to provide a single solution that works for every case.

For more details visit this User voice forum – https://sharepoint.uservoice.com/forums/329214-sites-and-collaboration/suggestions/32229454-printing-modern-pages

Keep checking this blog for exciting new articles about Power Automate, SharePoint Online, Power Apps, as well as document conversion and manipulation using The Muhimbi PDF Converter.

Author: Yash kamdar

Yash Kamdar is a Cloud Engineer based out of India. He is an Author, Trainer, Speaker and also run his own Youtube channel- Power Podium.

2 thoughts on “Converting Modern SharePoint Online Pages (ASPX pages) to PDF”

  1. Hi Yash,
    great article, I have been through the whole tutorial and it worked just fine. However, it seems that the pdf export does not handle webpart from a page ? Such as list or images… Any chance you have experienced it yoursled ? Am I doing something wrong or its not yet supported by the muhimbi add-in ?

    Thanks for your help any way, I have learned a lot with your posts so far.

    Like

    1. Hello Florent, thank you so much for your comments. You are correct, a couple of webparts are currently not being rendered correctly and that is purely because Microsoft keeps changing the behaviour of SharePoint Online Modern pages. We are working hard to generate a PDF that looks exactly similar to the original page. This is planned as a part of future releases.

      Like

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 )

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

%d bloggers like this: