Convert any file to PDF format using the Data View Web Part and a simple hyperlink

Related Products

PDF Converter

PDF Converter

Share

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:

  1. 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).

  2. Start SharePoint Designer and open the Site Collection to work in.

  3. Open the web page to insert the DVWP on, in our case default.aspx.

  4. Select a Web Part Zone to add the DVWP to and choose Insert Data View from the Data View menu.

  5. From the newly opened Data Source Library click the Shared Documents Library and select Show Data.

  6. 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.

    SPDesigner

  7. 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.

  8. 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}

  9. 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.

DVWP Result

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.

Labels: Articles, pdf, PDF Converter

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