Subscribe to News feed

Combining multiple PDF files using a SharePoint Designer Workflow

Posted at: 11:23 PM on 26 May 2010 by Nycklander

workflow Hi, I’m Nicolas and today I will show how to merge multiple PDF files using a SharePoint Designer workflow using the PDF Converter for SharePoint and the Workflow Power Pack.

Update: Please note that as of version 5.0 of the PDF Converter it is also possible to merge PDF Files using the SharePoint User Interface as well as via direct Web Service calls.

A quick introduction for those not familiar with the product: The Muhimbi Workflow Power Pack for SharePoint allows custom C# or VB.NET code to be embedded in SharePoint Designer Workflows without the need to resort to complex Visual Studio based workflows, the development of bespoke Workflow Activities or long development cycles.

The solution presented below shows how to create a SharePoint Designer workflow and attach it to a document library. This workflow is triggered when adding or modifying an item in the library, for example after converting a document using the PDF Converter. This example is particularly useful when you want to automatically add a cover page or Appendix to each and every PDF file in the system.

The workflow checks if the file extension for the current item is “pdf”. If this is the case then it uses the Workflow Power Pack to execute some C# code that carries out the actual appending of PDF files. The solution provided in this post works in SharePoint 2007 as well as 2010.

Append PDF content from one file to another

Create the workflow as follows:

  1. Download and install the Muhimbi Workflow Power Pack for SharePoint
     
  2. Download and install the Muhimbi PDF Converter for SharePoint 
     
  3. We need to be able to access functionality in the Muhimbi.SharePoint.DocumentConverter.PDF assembly. Add this reference to the relevant Web Application using the Workflow Power Pack Central Administration screens as described in the Administration Guide.
      
  4. Make sure you have the appropriate privileges to create workflows on a site collection.
     
  5. Create a new workflow using SharePoint Designer.
     
  6. On the Workflow definition screen associate the workflow with the Shared Documents library, tick the boxes next to both “Automatically start….” options and proceed to the next screen.
     
  7. We only want to act on files of type PDF. Although we could have put this validation in the code, in this example we use a workflow condition for it so add a Compare Any Data Source condition and:
     
    a. Click on the first value followed by the display data binding (fx) button.
    b. Select Current Item as the Source and select File Type in the Field. Click the OK button to continue.
    c. Click on the second value and enter pdf. (Use lower case as the compare option is case sensitive).
     
  8. Click the Actions button and insert the Execute Custom Code action.
     
  9. Click parameter 1 and enter a relative or absolute path to the PDF file you want to append to the current workflow item. For example /sites/PDFConversion/Shared%20Documents/appendix.pdf  or Shared%20Documents/appendix.pdf
     
  10. Optionally, click parameter 2 to specify a second PDF file to append.
     
  11. Insert the C# based code listed below by clicking this code in the workflow designer.  Note that copying this code using Internet Explorer may remove line breaks. Preferably use Chrome or Firefox to copy the code or alternatively paste it from Internet Explorer into Windows Wordpad and then copy it from there into SharePoint Designer.
     
    /*********************************************************************************************
                         Muhimbi PDF Converter - Combining Multiple PDF Files
     
                  Copyright 2010, Muhimbi Ltd - www.muhimbi.com - All rights reserved
     
    The following code shows a simple way to merge PDF content from one or more files.
     
    Error and permission checking as well as other minor features have been omitted for the sake
    of brevity and clarity.
     
    This code requires Muhimbi’s PDF Converter and Workflow Power Pack to be installed.
    **********************************************************************************************/
     
    using Syncfusion.Pdf.Parsing;
    using System.IO;
     
    // ** Some variables we're going to use
    SPFile spDocument1ToAppend = null;
    SPFile spDocument2ToAppend = null;
    PdfLoadedDocument document1ToAppend = null;
    PdfLoadedDocument document2ToAppend = null;
     
    // ** Get and load current pdf document (the one which triggered the workflow)
    SPFile spSourceDocument = MyWorkflow.Item.File;
    PdfLoadedDocument sourcePdfDocument = new PdfLoadedDocument(spSourceDocument.OpenBinary());
     
    // ** If supplied, get and load 1st pdf document to append to
    string document1ToAppendPath = MyWorkflow.Parameter1 as string;
    if (!string.IsNullOrEmpty(document1ToAppendPath))
    {
        spDocument1ToAppend = MyWorkflow.Web.GetFile(document1ToAppendPath);
        document1ToAppend = new PdfLoadedDocument(spDocument1ToAppend.OpenBinary());
    }
     
    // ** If supplied, get and load 2nd pdf document to append to
    string document2ToAppendPath = MyWorkflow.Parameter2 as string;
    if (!string.IsNullOrEmpty(document2ToAppendPath))
    {
        spDocument2ToAppend = MyWorkflow.Web.GetFile(document2ToAppendPath);
        document2ToAppend = new PdfLoadedDocument(spDocument2ToAppend.OpenBinary());
    }
     
    // ** Get destination file and folder
    string destinationFolderUrl = spSourceDocument.ParentFolder.Url;
    SPFolder spDestinationFolder = MyWorkflow.Web.GetFolder(destinationFolderUrl);
    string destinationFileName = spSourceDocument.Name;
    string destinationFilePath = string.Format("{0}/{1}", destinationFolderUrl,
                                 destinationFileName);
    SPWeb spDestinationWeb = spDestinationFolder.ParentWeb;
    SPFile spDestinationFile = spDestinationWeb.GetFile(destinationFilePath);
     
    // ** If a document library requires manual checkout and the file is not checked out,
    // ** then check the file out before uploading
    if (spDestinationFile.Exists && spDestinationFile.Item.ParentList.ForceCheckout &&
        spDestinationFile.CheckOutStatus == SPFile.SPCheckOutStatus.None)
    {
        spDestinationFile.CheckOut();
    }
     
    // ** Add the file to the site including the meta data
    using (MemoryStream mergedDocument = new MemoryStream())
    {
        // ** Append files to destination document
        if (document1ToAppend != null)
            sourcePdfDocument.Append(document1ToAppend);
     
        if (document2ToAppend != null)
            sourcePdfDocument.Append(document2ToAppend);
     
        // ** Save merged file and overwrite in document library
        sourcePdfDocument.Save(mergedDocument);
        spDestinationFile = spDestinationWeb.Files.Add(destinationFilePath, mergedDocument,
                            spSourceDocument.Item.Properties, true);
    }
     
    // ** Check the file back in if this script was responsible for checking it out
    if (spDestinationFile.Item.ParentList.ForceCheckout)
        spDestinationFile.CheckIn("Auto check-in after PDF document appending.");
             
  12. Click the Actions button, select Log to History List, click this message and enter PDF content appended to current item.
     
  13. Close the Workflow Designer.
     
  14. Update an existing PDF or add a new PDF file to your document library to trigger the workflow and append contents from the files defined in parameter 1 and parameter 2.
     
    Files to append   
     
  15. The workflow should look something like this.

    Workflow 


Of course this is just a sample, feel free to play around with the code, change which parameters are passed into the workflow, use different document libraries as source and destination of PDF documents, change the sequence in which documents are appended, etc.

Please leave a comment if you’re trying to do anything specific or if you want to share your experience with this approach.

As always, feel free to contact us using Twitter, our Blog, regular email or subscribe to our newsletter.

.





Labels: , , , , , ,

Workflow Power Pack 1.2 - Embed C#/VB in SharePoint 2007 / 2010 Designer Workflows

Posted at: 11:57 AM on 24 May 2010 by Muhimbi

WPPBoxIf you are a loyal follower of this blog then you may have noticed that we are adding SharePoint 2010 compatibility to our entire Product Line. We started with our best-selling PDF Converter for SharePoint and, with the experience gained during that project, moved on to the Workflow Power Pack.

A quick introduction for those not familiar with the product: The Muhimbi Workflow Power Pack for SharePoint allows custom C# or VB.NET code to be embedded in SharePoint Designer Workflows without the need to resort to complex Visual Studio based workflows, the development of bespoke Workflow Activities or long development cycles.

In addition to SharePoint 2010 support we have also made it possible to localise the Workflow Power Pack for the non-English market. Support for the Dutch language has already been added and more languages will follow shortly. If you would like to see support for your language then please drop us a line.
 

SP2010-WPP
Look at the fancy support for the Shiny new SharePoint Designer 2010 Workflow Editor

 
The main changes in version 1.2 are as follows:

859 Added support for SharePoint 2010.
723 Made it possible to create localised versions.
862 Added support for the Dutch language.
856 Added support for Server and Enterprise license models.
858 Improved support for deploying resource files in Farm environments.

 
For more information check out the following resources:

 
As always, feel free to contact us using Twitter, our Blog, regular email or subscribe to our newsletter.

 

Download your free trial here (1.5MB).


.






Labels: , , , ,

New release of MuSH – Workflow Enabled ‘TinyURL’ for SharePoint v2

Posted at: 3:43 PM on 07 May 2010 by Muhimbi

Today we are releasing a small and incremental upgrade to the Muhimbi URL Shortener for SharePoint. No major new features, just bug fixes, deployment improvements and changes to the License Manager to manage our new type of Server and Enterprise licenses. Oh the excitement….

For those not familiar with the product, the Muhimbi URL Shortener for SharePoint, aka MuSH, can be used to shorten URLs for typical web applications and SharePoint in particular. It integrates tightly with both WSS and MOSS and allows short URLs to be created directly from a list item’s context menu, workflows and web services. For details see the original announcement.

The main changes and improvements are as follows:

848 Error when first ever shortened URL is given a manual short name.
If you deployed a previous version and experienced problems then please contact use before downloading this new version as some manual steps are involved. This only affects a small number of users.
852 Added support for new licensing model.
854 Added new resource deployment libraries.

  Workflow-690

For more information check out the:

As always, feel free to contact us using Twitter, our Blog or regular email or subscribe to our newsletter.

Download your free trial here (1MB).

.






Labels: , , ,

PDF Converter for SharePoint 3.4 – SharePoint 2010 & Office 2010 RTM Compatible

Posted at: 3:58 PM on 06 May 2010 by Muhimbi

PDFBox

Although it has only been 2 weeks since the RTM version of SharePoint 2010 was released, our team has been working flat out to make the popular Muhimbi PDF Converter for SharePoint compatible with both SharePoint 2007 and SharePoint 2010.

As we were going through a full QA cycle anyway we also validated the software with the RTM version of Office 2010 to make sure our customers can make use of the latest and greatest innovations such as Excel Spark lines when generating PDF files.

For those not familiar with the product, the PDF Converter for SharePoint is a lightweight solution that allows end-users to convert common document types to PDF format from within SharePoint using a friendly user interface, workflows or a web service call without the need to install any client side software or Adobe Acrobat. It integrates at a deep level with SharePoint and leverages facilities such as the Audit log, localisation, security and tracing. It runs on WSS 3, MOSS as well as SharePoint 2010 and is available in English, German, Dutch, French, Traditional Chinese and Japanese. For detailed information check out the product page.

 

 PDF-Converter-Doclib

New support for the Ribbon in SharePoint 2010

The main changes in version 3.4 are as follows:

792 New - Added support for SharePoint 2010 RTM
845 New - Added Taiwanese translations (Traditional Chinese)
827 Fix - MS-Word Paragraph borders are not rendered correctly when saved as PDF
782 Fix - Excel 2010 has problems converting ODS files
483 Fix - Resources not deployed on farms where 'Timer Account' is not local administrator
524 Fix - STSADM and Timerjob are fighting over access to layouts.sitemap
787 Fix - Resources don't deploy when SharePoint 2010 Timer service account is not local Admin
797 New - Make license manager SP2010 compatible
840 Fix - Convert to PDF is not present on Folder Context Menu in SP2010 & SP2007
841 Fix - PDF Converter loads slowly on very big (100K+ items) Document Libraries
833 Fix - Too much logging during anonymous requests
808 New - Added support for Server and Enterprise Licenses
821 New - Added Sample Java code to Setup Project
822 New - Added Sample .net code to Setup Project
825 New - Added test harness executable to setup and Start Menu

 

For more information check out the following resources:

 

As always, feel free to contact us using Twitter, our Blog, regular email or subscribe to our newsletter.

Download your free trial here (6MB). .

.





Labels: , , , ,

Need support from experts?

Access our Forum

Download Free Trials