Subscribe to News feed

Converting SharePoint Online Pages / Items to PDF

Posted at: 15:21 on 12 October 2017 by Muhimbi

HTML5 logo and wordmarkA couple of months ago we released a new version of our core document conversion platform, with the main change being a completely overhauled HTML converter. It supports the latest HTML, JavaScript, Print and Screen CSS media types and does a great job overall when it comes to converting HTML content to PDF.

In addition to supporting the latest HTML standards, it also comes with the ability to convert SharePoint Online web pages and URLs, a unique facility exclusive to Muhimbi's range of products. This new facility is particularly useful when it comes to archiving Lists and List Items to PDF Format, or sharing the content of SharePoint pages and Wikis with 3rd parties.

Although it is also possible to convert SharePoint Online URLs using our on-premise products, this new functionality is primarily aimed at our Online customers. In this article we will show how to carry out these kinds of conversions using the SharePoint Online User Interface, SharePoint Designer Workflows, Microsoft Flow and Logic Apps, as well as a REST based API.

 

User Interface

Although automating conversions is very powerful, sometimes all you need is a quick PDF of the current web page, generated by clicking a link in SharePoint's user interface. Please follow the steps below to set this up:

  1. Elevate the Muhimbi App to allow links to be added to the SharePoint User Interface. This requires Site Collection Administrator privileges.
  2. Enable the Muhimbi PDF Converter - Convert Web Page App Feature as described at the end of this Knowledge Base Article.
  3. Specify the default user credentials for converting SharePoint Online pages.
     

SP Online UI Conversion The original list (left), Convert via Personal Actions (middle), resulting PDF (right)

 
With everything configured, navigate to a Classic View SharePoint Online page (At the time of writing this functionality is only available in Classic view due to limitations in SharePoint Online's Modern View). From the Personal Actions menu (the menu that is opened when clicking on your name at the top-right corner of the screen), select Convert Page to PDF.

The resulting PDF is automatically optimised for print purposes. The left-hand navigation menu is removed as are (most of) the other user interface elements. If you prefer the PDF to look exactly like what is displayed in the web browser, including user interface elements, then switch to the Screen media type in the HTML Conversion configuration screen (the same screen used for specifying the default credentials).

 

SharePoint Designer Workflows

Converting via the SharePoint User Interface is nice and well, but more often than not conversion is part of an automated process. For example, every time a List Item is updated, or whenever a List Item's status changes to Approved, a PDF rendition will need to be created and archived / emailed or whatever other business process is important to your organisation.

The easiest way to automate this is by creating a SharePoint Designer Workflow. Please follow the steps below to set this up:

  1. Install and activate the Muhimbi Workflow Actions. Make sure to use version 9.10 or later.
  2. Although there is no need to Elevate the Muhimbi App, and enabling the Muhimbi PDF Converter - Convert Web Page App Feature, it may come in handy if you do not wish to store HTML Conversion credentials inside the workflow itself. You can specify the default credentials, as well as a number of optional aliases, using Muhimbi's User Credentials facility.
  3. Create a new SharePoint Designer workflow. In our case we navigate to the List and use SharePoint's List ribbon to create a workflow in SharePoint Designer. A full tutorial for creating SharePoint Designer Workflows is beyond the scope of this article, have a look at this video for a basic introduction.
  4. Give the workflow a name, set its Start Options (we use manual in this example) and design the workflow.
  5. Insert the Convert HTML to PDF workflow action and fill in the blanks.
     
    HTMLConversion-SPD - Online
    • this url / html: The fully qualified URL to convert. In this example we would like to convert the List Item so navigate to the View Item URL for the list item, and copy the URL up to and including '?ID=''. This will result in something like https://acme.sharepoint.com/sites/somesite/Lists/some_list/DispForm.aspx?ID=. Select this url, click the ... button and paste the address. Place the cursor at the end of the URL and click the Add or Change Lookup button. From the Field from source option, select ID to automatically insert the ID of the item that is being converted.
    • this file: Specify the location to write the PDF file to, e.g. Shared Documents/item.pdf. Naturally you can make the file name unique by inserting the ID in the same way as described in the previous step. For details about specifying output paths, see this blog post.
    • Orientation: Page orientation of the converted file. Use Portrait or Landscape.
    • Credentials: In order to convert SharePoint Online web pages - not files, this applies to URLs only - the HTML Converter needs to authenticate during conversion. Specify credentials, or leave them empty to use the default credentials configured centrally. If one or more aliases have been configured then they can be used by specifying the alias name between curly braces in the user name field (e.g. {SomeAliasName}). The password field can be left empty in this case.
    • Authentication: Accept the default value for URLs located in SharePoint Online. For external - non-SharePoint - URLs, specify Web (for normal web based authentication) or anonymous for sites that require no authentication.
    • Viewport: Optionally specify a virtual screen resolution to allow responsive web content to output the appropriate version (e.g. mobile or desktop version).
    • Media Type: Control if output should be optimised for Print layout (using the Print CSS Media type) or rendered exactly as displayed on screen.
    • Conversion delay: Control the delay between initially loading the page, including JavaScript rendering, and starting the PDF Conversion process. Do not set this value too low as SharePoint Online pages contain very rich content.
  6. Finish the workflow, publish it, and start it on a list item of your choice. After a few seconds you will find a PDF rendition in the output folder.

  
 

Microsoft Flow & Logic Apps

Microsoft Flow, and its big brother Logic Apps, are rapidly increasing in popularity. It is easy to see why, not only does it provide a great browser-based workflow editor for SharePoint Online, it can also be used in combination with non-SharePoint environments such as OneDrive, Dropbox, Google Drive, SalesForce and hundreds of other systems. Muhimbi's PDF Converter is available out of the (Flow) box, and makes it easy to convert, merge, watermark, secure, split and OCR files, just have a look at these tutorials.

As of mid-October 2017 our Flow actions also support the conversion of SharePoint Online pages. The SharePoint Designer workflow created in the previous section can easily be recreated in Flow. From a high level perspective, the steps are as follows:

  1. Create a new Flow and use the SharePoint Online trigger When an item is created or modified. Fill out the URL for the site collection and select the relevant SharePoint list from the dropdown menu.
  2. Insert Muhimbi's Convert HTML to PDF action and fill it out as per the screenshot displayed below. Naturally you will need to substitute the source URL, User name and password. Make sure that for SharePoint Online conversions you select Print as the Media type.
  3. Insert a Create File action to write the converted file back to SharePoint Online (or Dropbox, OneDrive, Google Drive, or send the PDF via email).
  4. Publish the workflow and create / update a list item in the specified list. After a few seconds the Flow will trigger and a PDF file will be generated.     
     

HTML Conversion - Flow

 

REST API

All functionality exposed by the Muhimbi PDF Converter is also available via an online REST based API. Sample code is beyond the scope of this blog post, you can find details for languages such as C#, Java and PHP on GitHub.

 

Troubleshooting / Caveats

Please keep in mind that HTML is not the best format for print or PDF Conversion purposes. Although our new HTML Converter is excellent, it is not magic. Depending on your exact needs and source material, you may need to experiment with the various settings. Our support desk staff is very experienced, so contact us if you have any questions or require assistance.

Some points to take into account:

  1. Modern Views: In SharePoint Online it is possible to display Lists and Libraries in Modern or Classic mode. Modern View is undergoing constant change (by Microsoft), as a result we currently only support the conversion of pages displayed in Classic View. Some Modern View pages will convert fine while others don't.
  2. Multi Factor Authentication (MFA):  An increasing number of SharePoint Online / Office 365 environments are secured using MFA. Although this is a positive development, it gets in the way of automated systems such as our HTML converter. If your environment uses MFA then please create an App password for HTML conversions, or disable MFA on your HTML Conversion account.
  3. HTML Conversion link not displayed: The option to convert the current page to PDF is only available in Classic SharePoint pages. Modern pages currently do not provide a facility for extending the personal actions menu. We will make sure it is added as soon as Microsoft makes this functionality available.
  4. The generated PDF looks different from what is displayed on screen. By default the page being converted is optimised for print / PDF output. If you prefer the PDF to look exactly like what is displayed on screen, including user interface elements, then set the Media Type to Screen in the HTML Conversion configuration screen.
  5. User modified content is not converted: Please keep in mind that the converter has no knowledge about the information currently displayed in the user's browser (e.g. size of the browser window, or custom data entered but not yet submit to the server). The converter always requests a fresh copy of the URL and converts that information to PDF.
  6. User specific information is missing: HTML Conversion is carried out in the context of the configured user account, the system is not aware of the user carrying out the HTML conversion. Be careful, don't specify accounts that display more information than the users should have access to.

.

Labels: , , , , , , ,

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

Links to this post:

Create a Link

Need support from experts?

Access our Forum

Download Free Trials