180 likes | 341 Views
SharePoint Word automation SERVICES. Typical word Conversion scenario. Typical Scenario User request: Please convert 10,000 word documents to PDF by the end of the week. Developer: Time for Ole automation to open the Word document and save the word document as a PDF. Developer
E N D
Typical word Conversion scenario • Typical Scenario • User request: • Please convert 10,000 word documents to PDF by the end of the week. • Developer: • Time for Ole automation to open the Word document and save the word document as a PDF. • Developer • After running for 1 Day only 400 document were converted because we ran out of memory! • Time for plan B, Adobe distiller or third party. Problem solved! • User request • I have more documents and I would like users to pick and choose which files they should convert • Developer • NOOOOOOOOOOOOOOOO!
Word automation services to the recuse • What is Word Automation Services? • Word Services is functionality in SharePoint 2010 that allows developers to transform Word documents into other document types like PDF, XPS, and other formats • Also file operation can be executed on the file without having to open it in a client application • Regular Word document types can be converted into different document types • OpenXML can be utilized to perform insert, append, update, and delete operations on content within the documents
Right on time! • The service runs as a timer job so this allows for the service to take full advantage of the environment • Reliability • Timer job can run of different machine so if one machine is down another one can take it place • Scalability • One a farm with adequate size the service can execute jobs on multiple servers distributing the work load • Speed • In most Production environments the hardware is sized to run thousands or millions of instructions and processes • License • SharePoint Server 2010 is for standard and enterprise CAL
What’s needed? • Nothing BUT SHAREPOINT 2010 and a little code • Now solutions can be given to the user without deploying code to their desktop! • Word Services • OpenXML SDK 2.0
User’s problem/Our solution • Problem: User’s want to selectively pick word documents and convert them to different formats like PDF or XPS. • Solution: • Within a document library allow users to select which documents they want to convert. Utilize the ribbon, it’s a great pluggable interface that can be easily be extended. On the ribbon we will give the user a drop down of document types and two buttons quick and batch convert. Also for our power users sanity provide a third button called Check Status. • Use a document library’s ribbon • Put controls in ribbon using a custom action • Provide a status page
File formats the service can… • Read: • Office Open XML (DOCX, DOCM, DOTX, DOTM) • Word 97-2003 Document (DOC) and Word 97-2003 Template (DOT) • We also support older versions of Word as far back as Word 2.0 for Windows (!) • Rich Text Format (RTF) • Single File Web Page (MHTML) • HTML • Word 2003 XML • Word 2007/2010 XML • Write: • PDF • XPS • Office Open XML (DOCX, DOCM) • Word 97-2003 Document (DOC) • Rich Text Format (RTF) • Single File Web Page (MHTML) • Word 2007/2010 XML
Word services architecture Object Model The object model resides on a SharePoint Server 2010 Web front-end server; it enables developers to create asynchronous file conversion requests and to monitor file conversions in progress. Document Queue The document queue manager resides on a back-end application server; it moves incoming requests into the document queue database and sends requests to the Word Automation Services engine for processing. A timer job controls the frequency of conversions and the number of files that are actively being converted Word Automation Services Engine The Word Automation Services engine provides an optimized, server-based rendering engine that can use server features, such as the availability of multiple processors. In multiple-server configurations, the Word Automation Services engine balances the load to ensure that no single application server is overloaded by conversion requests. Resource from http://msdn.microsoft.com/en-us/library/ee556832.aspx
environment • Virtual Machine (4 GB RAM) • Windows 7 x64 • Visual Studio 2010 x32 ( no x64 yet) • SharePoint 2010 • Software Solution • Empty SharePoint Project • Add an element file - Ribbon • Add Application pages – Pages to submit the jobs • Add a JavaScript external file – Client side JS to talk to the
solution - Ribbon Ribbon <CustomAction Id ="CushWake.WordConversion.Ribbon.Scripts" Location="ScriptLink" ScriptSrc="/_layouts/CushWake/WordConversion/ConversionScript.js" /> <CustomAction Id="CushWake.WordConversion.Ribbon" Location="CommandUI.Ribbon" RegistrationId="101" RegistrationType="List" Title="Word Conversion"> <Tab Id="CushWake.WordConversion.Ribbon.Tab" Title="Word Conversion" Sequence="501"> <MenuSection Id="CushWake.WordConversion.ConversionGroup.Section.Quick" Sequence="10" DisplayMode="Menu32"> <Controls Id="CushWake.WordConversion.ConversionGroup.Controls.Quick"> <Button Id="CushWake.WordConversion.ConversionGroup.Button.Quick.PDF" Command="WordConversionButtonCommand.ConversionQuick.PDF" Image32by32="/_layouts/images/CushWake/WordConversion/clock32.png" LabelText="PDF" Sequence="10" TemplateAlias="cust1" /> … <CommandUIHandlers> <CommandUIHandler Command="WordConversionButtonCommand.JobStatus" CommandAction="/_layouts/CushWake/WordConversion/ConversionJobs.aspx?listId={ListId}" /> <CommandUIHandler Command="WordConversionButtonCommand.ConversionQuick.PDF" CommandAction="javascript:quickConvert('PDF');" EnabledScript="javascript:isItemSelected();" /> <CommandUIHandler Command="WordConversionButtonCommand.ConversionQuick.DOCM" CommandAction="javascript:quickConvert('DOCM');" EnabledScript="javascript:isItemSelected();" /> <CommandUIHandler Command="WordConversionButtonCommand.ConversionQuick.DOTX" CommandAction="javascript:quickConvert('DOTX');" EnabledScript="javascript:isItemSelected();" />
Solution - Javascript • Asynchronous Call • function quickConvert(cfmt) { • varctx = SP.ClientContext.get_current(); • varmyItems = buildDeliminatedKeys(); • varlistGuid = SP.ListOperation.Selection.getSelectedList(ctx); • varurl = '/_layouts/XYZ/WordConversion/quickConversion.aspx?cfmt=' + cfmt + '&items=' + myItems + '&listId='+listGuid; • varreq = new Sys.Net.WebRequest(); • req.set_url(url); req.set_httpVerb("POST"); • req.add_completed(OnRequestCompleted); req.invoke(); • } • SharePoint Dialog Box • function convert() { • varctx = SP.ClientContext.get_current(); varlistGuid = SP.ListOperation.Selection.getSelectedList(ctx); varmyItems = buildDeliminatedKeys(); • var options = { url: '/_layouts/XYZ/WordConversion/Conversion.aspx?items=' + myItems + '&listId='+listGuid, tite: 'Document Batch Convert', allowMaximize: false, showClose: false, width: 700, height: 400, dialogReturnValueCallback: updateScreenCallback }; • SP.UI.ModalDialog.showModalDialog(options); • }
Solution-calling the Word service • public static ConversionJobCreateJob(SPUserTokenuserToken,SaveFormatfmt,stringjobTitle) • { • ConversionJob job = new ConversionJob("Word Automation Services"); • job.UserToken = userToken; • job.Settings.UpdateFields = true; • job.Settings.OutputFormat = fmt; • job.Name = jobTitle; • return job; • } • job.AddFile(SPContext.Current.Site.MakeFullUrl(spiDoc.Url), destFile); • Job.Start(); • Other methods • job.AddFolder • Job. AddLibrary
SOLUTION-Monitoring • ReadOnlyCollection<ConversionJobInfo> conversionJobs = ConversionJobStatus.GetAllJobs("Word Automation Services", null); • varcJob = (from job in conversionJobsorderbyjob.SubmittedTime descending select job); • GuidjobGuid = new Guid(jobGuidString); • ConversionJobStatusjobStatus = new ConversionJobStatus("Word Automation Services", jobGuid, null); • lblFailed.Text = jobStatus.Failed.ToString(); • lblJobCount.Text= jobStatus.Count.ToString(); • lblSucceeded.Text= jobStatus.Succeeded.ToString(); • lblInProgress.Text = jobStatus.InProgress.ToString();
SOLUTION-Monitoring cont’d • JobInfo.JobItemTableDataTablejobItemTable = new JobInfo.JobItemTableDataTable(); • List<ItemTypes> jobItemTypes = new List<ItemTypes>() {ItemTypes.Succeeded, ItemTypes.Canceled,ItemTypes.Failed,ItemTypes.InProgress,ItemTypes.NotStarted }; • string inputFile, outputFile; • boolisJobUrlSet=false; • string srcUrl=String.Empty, destUrl=string.Empty; • foreach (ItemTypesitemType in jobItemTypes) • { • foreach (ConversionItemInfo item in jobStatus.GetItems(itemType)) • { • inputFile = item.InputFile.Substring(item.InputFile.LastIndexOf("/")+1); • outputFile = item.OutputFile.Substring(item.OutputFile.LastIndexOf("/")+1); • jobItemTable.AddJobItemTableRow(inputFile, outputFile, item.ErrorMessage, item.StartTime.ToString(), item.CompleteTime.ToString(), itemType.ToString());
Resources • Word Automation Services Architecture • http://msdn.microsoft.com/en-us/library/ee556832.aspx • Open XML SDK 2.0 for Microsoft Office • http://www.microsoft.com/downloads/en/details.aspx?FamilyID=c6e744e5-36e9-45f5-8d8c-331df206e0d0&DisplayLang=en • Setting Up the Development Environment for SharePoint 2010 on Windows Vista, Windows 7 • http://msdn.microsoft.com/en-us/library/ee554869(office.14).aspx
Issue, resolution,& Guidelines • Word Automation Services has to be explicitly enabled. • Using OpenXml had trouble finding System.IO.Packing for .Net 4.0 add the WindowsBase to your project • Word Automation Service Settings • Worker processes = #CPU – 1 • Max of 90 documents per worker process per minute • Invalid document have a high memory cost • All memory is reclaim when the process is restarted • You can set the # of times to try to convert the document