Convert any file to PDF format using the Data View Web Part and a simple hyperlink
Next up in our series about new features in the PDF Converter for SharePoint 4.0, we’ll showcase the new URL interface for converting documents to PDF format.
In addition to generating PDF files manually, via workflows and web service calls, as of version 4.0 it is also possible to convert documents and web pages by simply invoking a URL. This functionality is particularly helpful if you want to place a link to the PDF version of a file anywhere in a web page or Data View Web Part.
The URL is made up of the following elements:
\_layouts/Muhimbi.PDFConverter/Convert.aspx?Action=ConvertAndDownload&ListId= _your_list_id_&ItemId= _your_item_id_& ConversionURL= _url_to_convert_
-
Action: The action to carry out. Currently the only supported value is ConvertAndDownload.
-
ListId: The ID (GUID) of the list that contains the item to convert.
-
ItemId: The ID of the item to convert.
-
ConversionURL: A fully qualified URL of the web page to convert.
Please specify a combination of ListId / ItemId or the ConversionURL. Mixing these parameters is not allowed.
The best way to illustrate how to use this functionality is by example. In this example we want to make sure that users cannot see the original source files as we don’t want them to have access to these documents. Instead they can access each file via a special hyperlink that downloads the document in PDF format.
This can be achieved in many ways, but in this demonstration we use SharePoint’s Data View Web Part to automatically generate a list of documents and link each document to the ConvertAndDownload facility. Some familiarity with SharePoint Designer and the DVWP is assumed. For more information see the following resources:
To implement the solution carry out the steps below:
-
Make sure you have access to a Site Collection, a Document Library named Shared Documents and a web part page to insert the DVWP on (We use the home page named default.aspx).
-
Start SharePoint Designer and open the Site Collection to work in.
-
Open the web page to insert the DVWP on, in our case default.aspx.
-
Select a Web Part Zone to add the DVWP to and choose Insert Data View from the Data View menu.
-
From the newly opened Data Source Library click the Shared Documents Library and select Show Data.
-
In the newly opened Data Source Details tab select Name (and any other fields you may be interested in) and choose Multiple Items View from the Insert Selected Fields as… dropdown menu.
-
Any available documents are automatically listed. Click the name of one of the documents followed by the ‘>’ menu. Change Format as Text to Format as Hyperlink.
-
The previous action opens the Edit Hyperlink screen. Enter the following information in exactly this sequence:
Address: _layouts/Muhimbi.PDFConverter/Convert.aspx?Action=ConvertAndDownload&ListId={$ListID}&ItemId={@ID}
Text to display: {@FileLeafRef}
-
After closing the Edit Hyperlink screen you will most likely see an error about the ListID variable not being recognised. Choose Parameters from the Data View menu to automatically create this ListID parameter. Close the Data View Parameters screen using the OK button.
That is all. Click Save in SharePoint Designer and open / refresh the page in your web browser. Click on a document’s link to convert it to PDF format and open it in your browser.
In summary, the new version of the PDF Converter makes it even easier to add PDF Conversion abilities to your solution. As always, upgrades are completely free. Don’t hesitate to leave a comment below if you have any questions or contact us to discuss anything related to our products.
Clavin is a Microsoft Business Applications MVP who supports 1,000+ high-level enterprise customers with challenges related to PDF conversion in combination with SharePoint on-premises Office 365, Azure, Nintex, K2, and Power Platform mostly no-code solutions.