When developing a product such as the PDF Converter for SharePoint you start with a fair idea of how customers want to use it and what they may want to use it for. It is not until a product has been selling for a while before you grasp what the market really wants.
One of the first changes we made to the product was making it workflow enabled to allow it to be used from products such as SharePoint Designer and the ever popular Nintex Workflow. This basically cut the number of helpdesk tickets by 75%. Recently, however, we have been getting an increasing number of requests from people who want to use the product from their own source code. Although we never imagined anyone ever wanting to do this, we have decided to document (part of) the public interface to our product.
This post describes the public interface of the PDF Converter and provides a simple code sample illustrating how it can be invoked from your own custom .net code. Please consider reading the following related blog postings as well as they provide an alternative approach for using the PDF Converter from your own code:
- Configure PDF Security from a SharePoint Workflow
- Converting Office files to PDF Format using a Web Services based interface
The external interface is defined in the following class: Muhimbi.SharePoint.DocumentConverter.PDF.DocumentConverter.
The two main methods for converting documents are:
- DataTable ConvertToPdf(SPFile sourceFile, SPFolder destinationFolder, string destinationFileName, bool copyMetadata)
- DataTable ConvertToPdf(SPFolder sourceFolder, SPFolder destinationFolder, bool includeSubFolders, bool copyMetadata)
The interface largely describes itself. The first method can be used for converting a single file whereas the second method is used to convert entire folders.
Each method returns its results in a DataTable with a single row for each converted file. Each row’s fields can be accessed by name as defined in the following public constants on the DocumentConverter class.
- COLUMN_FILENAME = "Filename";
- COLUMN_FILEPATH = "Path";
- COLUMN_RESULT = "Result";
- COLUMN_MESSAGE = "Message";
- COLUMN_CONVERTEDITEMID = "ConvertedItemID";
As always, the best way to show how it all works is by example. The code at the end of this article generates the following screen
In order to use the code sample below, follow these steps:
Download and install the Muhimbi PDF Converter for SharePoint.
Copy the code below into a file named sample.aspx or download it here.
Place the file in 12\TEMPLATE\LAYOUTS\Muhimbi.PDFConverter (or anywhere else you want).
Access it at http://YOUR_SERVER/SOME_SITE/_layouts/Muhimbi.PDFConverter/sample.aspx.
Enter valid values in the text boxes and click ‘Convert’.
<%@ Assembly Name="Microsoft.SharePoint, Version=18.104.22.168, Culture=neutral, PublicKeyToken=71e9bce111e9429c"%>
Labels: Articles, PDF Converter