/******************************************************************************************** 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