<a href="https://msdn.microsoft.com/en-us/library/office/ff181518(v=office.14).aspx"></a>
using System; using System.Security.Permissions; using Microsoft.SharePoint; using Microsoft.SharePoint.Utilities; using Microsoft.SharePoint.Workflow; using Microsoft.Office.Word.Server.Conversions; namespace WordTopdf.ConversionLibrary.PDF_EventReceiver1 { /// <summary> /// List Item Events /// </summary> public class PDF_EventReceiver1 : SPItemEventReceiver { /// <summary> /// An item was added. /// </summary> public override void ItemAdded(SPItemEventProperties properties) { base.ItemAdded(properties); // Verify the document added is a Word document // before starting the conversion. if (properties.ListItem.Name.Contains(".docx")) { //Variables used by the sample code. ConversionJobSettings jobSettings; ConversionJob pdfConversion; string wordFile; string pdfFile; string wordAutomation = "WAS"; // Initialize the conversion settings. jobSettings = new ConversionJobSettings(); jobSettings.OutputFormat = SaveFormat.PDF; // Create the conversion job using the settings. pdfConversion = new ConversionJob(wordAutomation, jobSettings);//[i am getting an error in here] // Set the credentials to use when running the conversion job. pdfConversion.UserToken = properties.Web.CurrentUser.UserToken; // Set the file names to use for the source Word document // and the destination PDF document. wordFile = properties.WebUrl + "/" + properties.ListItem.Url; if (properties.ListItem.Name.Contains(".docx")) { pdfFile = wordFile.Replace(".docx", ".pdf"); } else { pdfFile = wordFile.Replace(".docx", ".pdf"); } // Add the file conversion to the conversion job. pdfConversion.AddFile(wordFile, pdfFile); // Add the conversion job to the Word Automation Services // conversion job queue. The conversion does not occur // immediately but is processed during the next run of // the document conversion job. pdfConversion.Start(); } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)