Convert HTML to PDF in SharePoint

In this guide you’ll learn how to convert HTML / website content to PDF in SharePoint. This guide is commonly used to convert SharePoint pages such as Wikis, publishing pages, Nintex Forms, and the ‘properties page’ for Lists and Document Library items to PDF. This guide can be used in SharePoint Online or On-premises deployments.

Note: If you are using our PDF Converter before release 8.3, you may find that particularly HTML5 pages (e.g. SP2013 and later) are rendered as bitmaps and ‘overflow CSS’ elements are cut-off. For optimum results please use release 8.3 or higher.

The key HTML to PDF converter features include:

  1. Brand new conversion engine with support for JavaScript, CSS and HTML5.

  2. Support for Print and Screen CSS media types to optimize output for Print / PDF Conversion.

  3. Available to all client technology including Nintex Workflow, Nintex Forms, SharePoint Designer, Flow, Logic Apps, REST & Web Services API as well as the SharePoint User interface.

  4. Enabled by default, with the option to switch back to the legacy HTML Converter using our API or config file.

  5. The MSG and EML Converter uses the new engine by default for HTML based emails.

  6. Support for converting SharePoint Online URLs.

  7. Improved error reporting, including authentication related issues.

  8. Control conversion delay between initially loading the page, including JavaScript rendering, and starting the actual PDF Conversion process.

  9. Modify the ‘View Port’ size to allow responsive web content to output the appropriate version (e.g. mobile or desktop version).

Some Caveats

Please keep in mind that HTML is not the best format for print or PDF Conversion purposes. Although our new HTML Converter is much improved, there can still be certain situations where the output is not very well optimized . Depending on your exact needs or system settings you may need to experiment with the various settings.

We recommend you to take into account the following:

  1. When converting MS SharePoint content, it is recommended to disabled the ‘Minimal Download Strategy’ SharePoint Feature as it interrupts the conversion process. Please refer to this article for details. If this is not an option, then set the conversion delay to 1000 (milliseconds).

  2. The Conversion Services will need to authenticate against the page you are looking to convert. The HTML Converter fits in with Windows’ standard security model, so you may need to tweak the server’s internet settings as per this Knowledge Base article. Naturally you have to make sure that the account the Conversion Service runs under has the appropriate privileges to read the page that is being converted.

  3. Modern web based content is very complex and it is no longer a couple of HTML elements that make up the design of a page. External JavaScript is loaded, as is third party content in iframes, part of the page is rendered by JavaScript, CSS modifies the look and feel of the page depending on the media type. So, this means that there is no clear point in time for our Converter to start the conversion process. Our software tries to make the most of it though, and in many cases succeeds using the default settings. For those situations where HTML content is converted too early (e.g. a ‘please wait, loading’ or similar message is displayed in the converted file) it is possible to tweak the Conversion Delay setting.

  4. The converter has no knowledge of the current user’s browser session. If the user has modified the page (e.g. collapsed / opened certain sections) or has made changes to the page without saving, then the converter will not reflect those changes. When converting HTML to PDF, the Converter requests the specified URL from scratch using the credentials of the account the Conversion Service runs under.

If you have any questions or comments, please feel free to contact our friendly support desk.

Setup Automatic PDF Conversion Using SharePoint Designer Workflow

In this example, you will generate a PDF file whenever the Tasks list is modified. The generated PDF file is stored in the Shared Documents library. You can create the workflow as follows:

  1. Make sure you have the appropriate privileges to create workflows on a site collection.

  2. Create a new workflow using SharePoint Designer.

  3. On the Workflow definition screen, associate the workflow with the Tasks list, tick the boxes next to both ‘Automatically start’ options, and proceed to the next screen.

  4. Add ‘Convert HTML to PDF’ action and click ‘this url’ and enter the URL to the page that was created in the previous step.
    e.g. http://gbsavdws106/sites/Demo2019/SitePages/SalesTaskList.aspx

  5. Click ‘this file’ and enter the path and file name where the PDF file will be generated, e.g. Shared Documents/Tasks.pdf.

  6. Optionally, change the generated page’s orientation from Portrait to Landscape.

  7. The username and password are optional. By default, the credentials that the Muhimbi Conversion Service runs under will be used to open the web page. You can leave it empty.

  8. Click the Publish button to deploy and activate the workflow.

activate workflow

You can enter one or more tasks to test. You will observe that every time a task is added or updated a PDF file is written to the Shared Documents/Tasks.pdf location. You can open the PDF file to check the results.

shared documents

In summary, this HTML conversion capability (available in newer versions) opens up many possibilities. As always, upgrades are completely free, so please upgrade and use all the available features.

Convert List Item Including All Attachments to PDF

The PDF Converter for MS SharePoint provides first-class support for converting (and/or merging) files stored in Document or Form Libraries. However, if you want to convert a list item, including all attachments, into a single PDF, then you have to do a little work.

The key to combining the list item and attachments in PDF Converter is the Merge Workflow Activity, which accepts a mix of URLs (to convert the HTML of the List Item View to PDF) and paths to attachments. For example, the following two lines convert the list item and an attachment.

http://SomeWebApp/sites/SomeSiteCollection/Lists/SomeList/DispForm.aspx?ID=3

/sites/SomeSiteCollection/Lists/SomeList/Attachments/3/somefile.xxx

It is pretty simple to generate the fully qualified URL to the List Item, which is just a matter of requesting the current item’s ID and concatenating it to the URL of the list's DispForm.aspx. However, retrieving the URLs to the attachments is a different matter as they all go into a generic 'attachments bin' for which file names cannot be queried from a SharePoint Designer workflow.

You have several options to overcome this challenge of querying the list attachments. Some of these are given below for your reference:

  1. Use JavaScript

  2. Use Nintex Workflow to extract the attachment paths. Our software ships with Nintex Workflow compatible workflow activities. For more information, refer to How can I use the PDF Converter in combination with Nintex workflow?. For more information on how to retrieve list of attachments, refer to Practical Nintex Forms to PDF Conversion using the PDF Converter for SharePoint (muhimbi.com)

    Note: You need version 7.2.1 of the PDF Converter, or newer, to merge List Item attachments.

If none of the above options suit your particular scenario, you can always use our API from your own custom code. For details about merging files from your own code refer to How can I merge files from my own source code? – Muhimbi

Converting HTML pages in MS SharePoint to PDF

When the Muhimbi.PDFConverter.ConvertWebPage.Site feature is enabled on a site collection then an option to convert the current web page to PDF format is automatically added to the Personal Actions menu.

convert html to pdf

Select this option to convert the current page and download it as a PDF file. This is perfect for quickly saving a list or web page as a PDF file.

The default page size, orientation, margin, scale mode and many other settings can be tweaked in the service’s config file. For details see HTML Specific switches in the Administration Guide, subsection Tuning the Document Conversion Settings.

Additional Resources

Troubleshooting

Blog Articles

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