Subscribe to News feed

Using Muhimbi’s PDF Converter with Office 2010

Posted at: 3:53 PM on 24 February 2010 by Muhimbi

Office2010Earlier today we released a new version of our popular PDF Converter for SharePoint. One of the key changes in this version is that it fully supports Office 2010 file formats, including all new formatting features such as Excel 2010 Sparklines.

Full installation details are provided in Appendix – Office 2010 Installation of the Administration Guide, however one detail is so essential that we feel we have to repeat it in this blog post. After all, who reads boring documentation anyway?

Update: As of version 5.2 64 bit versions of Office are supported as well. The following is for those customers who run older versions of the software.

The single most important thing to take away from this post is that no matter what CPU architecture you deploy the PDF Converter on, if you plan to use Office 2010 to carry out the conversions then you should always install the 32 bit version of Office 2010.

Even though the Muhimbi PDF Converter for SharePoint is a hybrid 32 / 64 bit application, the 64 bit version of Office will not work in combination with our software. Even if it did, it would provide little to no benefit.

For more details about the differences between the 32 and 64 bit versions of Office, including Microsoft’s recommendation to run the 32-bit version of Office 2010 on 64 bit hardware, read this article on Microsoft’s Office 2010 blog.

.

Labels: , , ,

Use SharePoint Workflows to inject JavaScript into PDFs and print the ‘open date’

Posted at: 2:29 PM on by Muhimbi

Calendar Ah, those pesky customers of ours, always looking for some niche functionality that is impossible to include in a generic product. However, using the Workflow Power Pack for SharePoint we can achieve almost anything we can think of…..almost.

Previously I described how to configure PDF Security settings from a SharePoint workflow and how to automatically watermark PDF files from a workflow.  This time I’ll show how to add JavaScript to any PDF file to automatically print the current date (the date the PDF was opened) on every page. In essence this adds a print date without modifying the PDF file every day to include the current date.

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 executes a workflow whenever a PDF file is added or updated. It iterates over all pages and inserts a form field on each page. Some client side JavaScript is then added to the PDF file that iterates over all newly added fields to insert the current date every time the PDF file is opened.

As the code is well documented it is easy to make further changes and customisations, e.g. change the formatting of the date or position of the label. Note that this has only been tested with a recent version of Adobe Acrobat reader. If you use a different PDF viewer your mileage may vary.

 
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.
    Note that you need version 3.2.0.20 or newer, older versions do not allow JavaScript to be inserted.
     
  3. Download this article’s source code.
     
  4. We need to be able to access functionality in the Muhimbi.SharePoint.DocumentConverter.PDF and System.Drawing assemblies. Add these references to the relevant Web Application using the Workflow Power Pack Central Administration screens as described in the Administration Guide. Make sure to place each reference on a new line.
      
  5. Make sure you have the appropriate privileges to create workflows on a site collection.
     
  6. Create a new workflow using SharePoint Designer.
     
  7. 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.
     
  8. 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.
    d.  Click on the second value and enter pdf. (Use lower case as the compare option is case sensitive).
     
  9. Click the Actions button and insert the Execute Custom Code action.
     
  10. Optionally click parameter 1 and enter a relative or absolute destination path. Leave the parameter empty to save the modified file on top of the existing PDF file. For details about how paths are handled, see this post and search for the words ‘this url’.
     
  11. Insert the C# based code embedded in step #3’s download (also listed below) by clicking this code.
     
    /*********************************************************************************************
                            Muhimbi PDF Converter - JavaScript Watermarking
     
                  Copyright 2010, Muhimbi Ltd - www.muhimbi.com - All rights reserved
     
     The following code shows a simple way of adding JavaScript to existing PDF Files. It adds 
     the current date to each page in the document in order to simulate a 'print date' that is
     always up to date without the need to modify the PDF file. The code is automatically executed 
     when the document is opened in the Adobe Acrobat Viewer.
     
     Error and permission checking as well as other minor features have been omitted for the sake 
     of brevity and clarity.
     
     Ideally PDF Conversion, applying security and watermarking is executed in the same step, see 
     http://www.muhimbi.com/blog/2010/01/configure-pdf-security-from-sharepoint.html
     
     This code requires Muhimbi’s PDF Converter and Workflow Power Pack to be installed.
    *********************************************************************************************/
     
    using System.Drawing;
    using System.IO;
    using Syncfusion.Pdf;
    using Syncfusion.Pdf.Parsing;
    using Syncfusion.Pdf.Graphics;
    using Syncfusion.Pdf.Interactive;
    using Muhimbi.SharePoint.DocumentConverter.PDF;
     
    SPFile spSourceDocument = MyWorkflow.Item.File;
     
    string destinationFileName = spSourceDocument.Name;
    string destinationFolderName = MyWorkflow.Parameter1 as string;
     
    // ** Load the document
    PdfLoadedDocument sourceDocument = new PdfLoadedDocument(spSourceDocument.OpenBinary());
    PdfDocument destinationDocument = new PdfDocument();
     
    // ** Copy all pages from the source document into the destination document 
    // ** so we can add JavaScript actions.
    destinationDocument.ImportPageRange(sourceDocument, 0, sourceDocument.Pages.Count - 1);
    sourceDocument.Dispose();
     
    // ** Iterate over all pages and add a form element
    for (int i = 0; i < destinationDocument.Pages.Count; i++)
    {
        PdfPage destinationPage = destinationDocument.Pages[i];
     
        // ** Create a new field using a unique name
        PdfTextBoxField field = new PdfTextBoxField(destinationPage, "_M_PrintDateField_" + i);
        // ** Center the field
        const int BOX_WIDTH = 200;
        int boxLeft = (int)((destinationPage.Size.Width - BOX_WIDTH) / 2);
        field.Bounds = new RectangleF(boxLeft, 20, BOX_WIDTH, 20);
        // ** Format the field
        PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12f);
        field.Font = font;
        field.BorderColor = new PdfColor(Color.White);
        field.BackColor = new PdfColor(Color.White);
        field.ReadOnly = true;
        field.TextAlignment = PdfTextAlignment.Center;
     
        destinationDocument.Form.Fields.Add(field);
    }
     
    // ** Create a client side script that iterates over all fields and populates the date
    string jscript = @"
            var pages = " + destinationDocument.Pages.Count + @";
            var today = util.printd('dd-mm-yyyy', new Date());
            for(var i=0; i<pages; i++)
            {
                var field = this.getField('_M_PrintDateField_' + i);
                field.value = 'Today is: ' + today;
            }
            ";
     
    // ** Attach the script to the Document Open event.
    PdfJavaScriptAction jsAction = new PdfJavaScriptAction(jscript);
    destinationDocument.Actions.AfterOpen = jsAction;
     
    // ** Construct the path and file to write the watermarked PDF file to.
    if (string.IsNullOrEmpty(destinationFolderName) == true)
        destinationFolderName = spSourceDocument.ParentFolder.Url;
    SPFolder destinationFolder = Utility.GetSPFolder(destinationFolderName, MyWorkflow.Web);
    string destinationFilePath = string.Format("{0}/{1}", destinationFolder.Url,
                                               destinationFileName);
    SPWeb destinationWeb = destinationFolder.ParentWeb;
    SPFile spDestinationFile = destinationWeb.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 watermarkedFile = new MemoryStream())
    {
        destinationDocument.Save(watermarkedFile);
        spDestinationFile = destinationWeb.Files.Add(destinationFilePath, watermarkedFile,
                                                     spSourceDocument.Item.Properties, true);
    }
     
    // ** Check the file back in if this script was responsible for checking it out.
    if (spDestinationFile.Item.ParentList.ForceCheckout == true)
    {
        spDestinationFile.CheckIn("Auto check-in after PDF watermarking.");
    }
        
  12. Click the Actions button, select Log to History List, click this message and enter File watermarked.
     
  13. Close the Workflow Designer.
     
  14. Update an existing PDF or add a new PDF file to your library to trigger the workflow and apply the JavaScript.

 WaterMarkScript 
Naturally this is just a simple example. Feel free to play around with the code, change which parameters are passed into the workflow, or add different JavaScript. Note that you may want to add a check to the code to check if the JavaScript / fields have previously been added, otherwise duplicate form fields may be added every time the PDF is updated.

This example uses the destinationDocument.Actions.AfterOpen event to execute the JavaScript when the document is opened. If you want to only display this content when printing the PDF then use the destinationDocument.Actions.
BeforePrint
event.

Adobe’s JavaScript for Acrobat reference can be found here.

 

.





Labels: , , , ,

PDF Converter for SharePoint 3.2 – With new support for Office 2010

Posted at: 11:02 AM on by Muhimbi

PDFConverterBoxWe are very excited to announce the new version of the Muhimbi PDF Converter for SharePoint. The main change in this version is support for Office 2010 based converters and file formats.

We are quite surprised by the number of customers asking for Office 2010 support, especially considering that at the time of writing it is still in beta. On the other hand, it appears to be very stable and particularly the improvements in converting InfoPath forms to PDF format make it worth considering.

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 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 both WSS 3 as well as MOSS and is available in English, German, Dutch, French and Japanese. For detailed information check out the product page.

workflow2

Convert files using the User Interface or an automated Workflow

The main changes in version 3.2 are as follows:

778 New: Support for Office 2010 has been added.
768 New: For InfoPath conversions, disabling of external data sources and embedded code has been made optional.

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 (4MB). .





Labels: , , ,

SharePoint 2010 Beta – No longer possible to keep indexes on-line while rebuilding them

Posted at: 11:50 AM on 22 February 2010 by Muhimbi

Just a quick note to make sure that anyone typing this error message into a search engine will find this post.

Due to a change in the SharePoint 2010 AllDocVersions table it is no longer possible to rebuild indexes as part of a SQL 2008 maintenance plan and keep the indexes on-line at the same time.

The reason behind this is that the MetaInfo field is no longer of type Image. It is now of type tCompressedBinary:varbinary(MAX).

If you get the error listed below then make sure you open the Rebuild Index Task in your SQL Maintenance plan and disable the ‘Keep index online while reindexing’ option.

 

Rebuild-Indexes

 

If you don’t then you’ll get the following error:

Executing the query "ALTER INDEX [AllDocVersions_PK] ON [dbo].[AllDocVe..." failed with the following error: "An online operation cannot be performed for index 'AllDocVersions_PK' because the index contains column 'MetaInfo' of data type text, ntext, image, varchar(max), nvarchar(max), varbinary(max), xml, or large CLR type. For a non-clustered index, the column could be an include column of the index. For a clustered index, the column could be any column of the table. If DROP_EXISTING is used, the column could be part of a new or old index. The operation must be performed offline.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.

If you use one of the default maintenance plans then this error happens before the Backup step. As a result your databases will not be backed up.

.

Labels: , ,

Create Shortened (‘TinyURL’) links from your SharePoint Workflow – Part 2

Posted at: 1:22 PM on 18 February 2010 by Muhimbi

workflow Not too long ago we wrote about how to create a Short URL from a SharePoint workflow using the Muhimbi URL Shortener (MuSH) in combination with our Workflow Power Pack. The response from our customers has been so positive that we decided to ship a Workflow Action with the new version of MuSH.

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

Creating short URLs from a workflow can be very useful. For example creating a short URL named after data in an InfoPath form or create a short URL for a deeply nested folder. In the example below we create a short URL that always points to the latest entry in the announcement list. Not sure if this is useful, but it illustrates the power of this facility.

Create the workflow as follows:

  1. Download and install the Muhimbi URL Shortener for SharePoint.
        
  2. Make sure you have the appropriate privileges to create workflows on a site collection.
     
  3. Create a new workflow using SharePoint Designer.
     
  4. On the Workflow Definition screen associate the workflow with the Announcements list, tick the box next to ‘Automatically start this workflow when a new item is created’ and proceed to the next screen.
     
  5. From the Actions Menu select Create Short URL, you may need to click More Actions first.
     
  6. The following Workflow Sentence is inserted:

    image10  
  7. To auto generate the short URL, leave the optional short name empty, but in our case we always want to give it the same name, so enter Announce.
     
  8. Click this ID / address, click the Workflow Lookup button and select Current Item as the Source and ID as the field.
     
  9. Click Document / Display Form and select Document (when used in a Document Library) or Display Form showing the item’s properties. As we are not dealing with a Document Library, it doesn’t matter what is selected.
     
  10. Click Overwrite / Return null and select the Overwrite as we always want to write the latest announcement using the same short name. (Return Null will return null in the output variable, which can then be tested for and action can be taken accordingly.)
     
  11. Click Variable: this variable and specify the variable the Short URL will be stored in. In this example name it shortURL.
     
  12. Add a Log To History List Action and specify the name of the workflow variable the Short URL has been stored in using the Workflow Lookup dialog box.

Close the workflow and create a new Announcement. When the workflow has finished, click the completed link to see the output. Click the generated URL to link to the latest announcement.

Create another Announcement, the Short URL should now link to the latest announcement.

.

Labels: , , , ,

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

Posted at: 2:30 PM on 16 February 2010 by Muhimbi

MushBoxLive never stops at Muhimbi. It has only been 7 days since we announced a new version of the Workflow Power Pack and here we are again with the brand new ‘2.0’ version of our URL Shortener for SharePoint. This version adds support for generating short URLs from workflows, manually specifying short URL names, new languages as well as some other new features and fixes. For full details see the table below.

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:

562 New: Allow users to specify their own Short URL.
556 New: Allow users to specify if they want the short URL to point to the Document rather than the Display Form.
760 New: Allow the URL Shortener to be called from any page using SharePoint’s Personal Action’s menu.
561 New: Allow the URL Shortener to be invoked from a SharePoint Designer Workflow.
735 Fixed: Make sure that the same Short URL is returned if a long URL has been shortened before.
655 New: Add Support for Simplified Chinese in the user interface.


 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: , , ,

SharePoint Workflow Power Pack User Guide – Creating custom methods

Posted at: 2:17 PM on 09 February 2010 by Muhimbi

User-Guide In part 4 of our series of User Guide related blog postings for the Muhimbi Workflow Power Pack for SharePoint we show how to create your own methods in a WPP script in order to keep the code organised and easy to maintain.

A quick introduction In case you are 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 following Blog postings are part of this User Guide series:

  1. Language Features: Discusses the script like syntax, the generic workflow action and condition, passing parameters, returning values from a workflow and using the MyWorkflow property.
     
  2. Embedding .net code in a Workflow Condition: Provides a number of examples of how to use the Evaluate Custom Code condition to carry out basic as well as complex conditional tasks.
     
  3. Embedding .net code in a Workflow Action: Contains a number of examples of how to use the Execute Custom Code  to basically carry out any action you can think of in a SharePoint Designer Workflow.
     
  4. Creating Custom Methods (this article): Shows how to create your own methods in your scripts in order to keep the code organised and easy to maintain.


 



Due to its scripting like approach, the Workflow Power Pack does not allow regular .NET methods to be created. However, by cleverly using delegates you can create your own reusable pieces of code.

To facilitate this, the following delegates can be used in addition to the normal delegates available in the .net framework. Note that this only works for C# as VB.net does not allow anonymous methods to be created.
 

delegate void WorkflowMethod(params object[] parameters);

delegate object WorkflowFunction(params object[] parameters);

delegate void WorkflowMethod<ParameterType>(params ParameterType[] parameters);

delegate ReturnType WorkflowFunction<ParameterType, ReturnType>(params ParameterType[] parameters);

 
There is no need to add these delegates to your WPP Code, they are added automatically.

 

Delegate name

Description

WorkflowMethod

Method with a void return type. Accepts any number of Object based parameters that can be accessed from the delegate body using the parameters array.

Parameters may need to be cast to the correct type before they can be used.

WorkflowFunction

Method using a return type of Object. Accepts any number of Object based parameters that can be accessed from the delegate body using the parameters array.

Parameters may need to be cast to the correct type before they can be used.

WorkflowMethod (Using generics)

Generics based version that allows strongly typed parameters to be passed.

WorkflowFunction (Using generics)

Generics based version that allows strongly typed parameters to be passed and returned

 

The example provided below creates a generic Debug method to concatenate information to a string. This string is then returned as the workflow’s ReturnValue, from where it can be written to the Workflow History.
 

string debugString = String.Empty;
 
WorkflowMethod<string> Debug = delegate(string[] parameters)
{
    debugString += parameters[0] + "\r\n";
};
 
WorkflowFunction Calculate = delegate(object[] parameters)
{
    return (int)parameters[0] + (int)parameters[1];
};
 
WorkflowFunction<int, string> Calculate2 = delegate(int[] parameters)
{
    return (parameters[0] + parameters[1]).ToString();
};
 
Debug("Hello");
Debug("World");
Debug(Calculate(1, 2).ToString());
Debug(Calculate2(3, 4));
 
MyWorkflow.ReturnValue = debugString;

 






Labels: , , , ,

Workflow Power Pack 1.1 - Embed C#/VB code in SharePoint Designer Workflows

Posted at: 11:25 AM on by Muhimbi

WPPBox I can’t believe it has only been 6 weeks since we launched the Workflow Power Pack for SharePoint. We are getting great feedback from our customers, who seem to universally love the product. The support call from one frustrated SharePoint Designer workflow developer who was almost in tears stood out particularly.

The version released today adds support for the number one user request, which is the ability to add your own custom methods to the code to allow some degree of usability and reduce the size of scripts.  Read this post for more details about how to use this new functionality.

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.

We have been working very hard to write as many blog posts as possible to provide examples of what can be achieved using the product as well as how to integrate the WPP with our other products such as the PDF Converter and URL Shortener. Have a look at the following posts:

Embed C# code directly into a SharePoint Designer workflow

  The main changes in version 1.1 are as follows:

743 Add Support for Custom methods using Delegates (See details in User Guide)
763 Trial version causes an error when used after a Pause For Duration activity.

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

.

Labels: , , ,

Tuning SharePoint’s workflow engine

Posted at: 11:36 AM on 04 February 2010 by Muhimbi

workflow As most of our products can be used from a SharePoint workflow, it is perhaps useful to know how to tweak SharePoint’s workflow engine for high-load or other specific scenarios.

This article explains in detail what can be tuned and how it can be tuned. If you are in a rush then you can skip over the first 20%.

In summary:

  • Workflow Throttle: Controls how many workflows can be processing at any one time on the entire server farm. This setting does not control how many workflows can be "In Progress" concurrently, but rather how many can be actively using the processor. When this number is exceeded, workflow instances that are started and events that wake up dehydrated workflows are queued for later processing. The default value is 15. This setting is per farm, so the number of front-end Web servers is irrelevant

    stsadm -o setproperty -pn workflow-eventdelivery-throttle -pv "25"
     
     
  • Workflow Batch Size: Workflows, by their very nature, do not execute in a nonstop, linear fashion. Instead, they run for a little while, pause, run some more, and then pause again, continuing in this manner until the process is complete. Although an outside observer or a developer might disagree, workflows are a collection of batches and the workflow engine is simply a glorified batch controller.

    stsadm -o setproperty -pn workitem-eventdelivery-batchsize -pv "125"
     
     
  • Workflow Timeout: The timeout setting specifies the amount of time (in minutes) in which a workflow timer job must complete before it is considered to have stopped responding and is forced to stop processing. Jobs that time out are returned to the queue to be reprocessed later. The default timeout period is five minutes

    stsadm -o setproperty -pn workflow-eventdelivery-timeout -pv "10"
     
     
  • Workflow Timer Interval: The workflow timer interval specifies how often the workflow SPTimer job fires to process pending workflow tasks. This interval also represents the granularity of delay timers within your workflow. If a timer is set to delay for one minute, but the interval timer fires only every five minutes, the workflow delays for five minutes, not one minute

    stsadm -o setproperty -pn job-workflow -pv value -url http://myWssServer
     

For our products you may need to tweak Workflow Timeout for very long running PDF Conversions. Changing the Timer Interval can be useful during development when using Pause Until or Pause For workflow Activities.

.

Labels: , , , ,

Need support from experts?

Access our Forum

Download Free Trials