I'm using Word Automation Service to convert docx to PDF in memory. Word document is created from scratch and it contains only auto generated text using syntax "=LOREM(5,5)"
This is the code snippet I'm using
string wordAutomationServiceName = "Word Automation Service"; string siteUrl = "http://avasrv01/sites/pub2"; using (SPSite spSite = new SPSite(siteUrl)) { SyncConverter sc = new SyncConverter(wordAutomationServiceName); sc.UserToken = spSite.UserToken; sc.Settings.OutputFormat = SaveFormat.PDF; sc.Settings.OutputSaveBehavior = SaveBehavior.AlwaysOverwrite; using (FileStream inputFile = File.OpenRead(@"C:\temp\Lorem.docx")) { using (MemoryStream outputStream = new MemoryStream()) { ConversionItemInfo info = sc.Convert(inputFile, outputStream); if (info.Succeeded) { Console.WriteLine("Succeded"); } else { Console.WriteLine("ErrorCode {0}", info.ErrorCode); Console.WriteLine("ErrorMessage {0}", info.ErrorMessage); } } } }
Execution this code I always get an the error
ErrorCode:65543
ErrorMessage: "The file could not be converted; it may be corrupt or otherwise invalid (the conversion process failed). Please try opening the file
in Microsoft Word, resaving it, and then resubmitting the file for conversion. If this does not resolve the issue,
contact your system administrator."
This is exception coming from ULS log
AppWorker:c9fb4a38-aa85-4ce8-8e73-86fdd1fc7fe9 worker call failed System.ServiceModel.FaultException: The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameterhttp://tempuri.org/:request. The InnerException message was 'Element 'http://tempuri.org/:request' contains data from a type that maps to the name 'http://schemas.datacontract.org/2004/07/Microsoft.Office.ConversionServices.Local:LocalWorkerRequest'.
The deserializer has no knowledge of any type that maps to this name. Consider using a DataContractResolver or add the type corresponding to 'LocalWorkerRequest' to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding
it to the list of known types passed to DataContractSerializer.'. Please see InnerException for more details. Server stack trace:
at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message) Exception rethrown
at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at Microsoft.Office.Web.Conversion.Framework.Remoting.IAppChannelCallback.Initialize(WorkerRequest request, FileItem fileItem)
at Microsoft.Office.Web.Conversion.Framework.AppWorker.ProcessRequest(ConversionSession session). Worker name WordAutomationServices, Document 00000000-0000-10ed-8033-f3c105e6928a
Marco Rizzi @Avanade Italy http://blog.marcorizzi.com