vendredi 26 décembre 2014

Unable to convert the document to pdf using word automation service



I have created custom action in which the document is converted to .pdf file. To do so, I am using Word Automation Services to convert document from .docx to .pdf.


My code is as per below.



using (SPSite site = new SPSite("http://"))
{
using (SPWeb web = site.OpenWeb())
{
FileStream fileStream = null;
string filePath = @"C:\converted.pdf";
string destFilePath = @"C:\1 - Copy.docx";
using (FileStream wordContents = new FileStream(destFilePath, FileMode.Open))
{
using (MemoryStream pdfContents = new MemoryStream())
{
// Initialise Word Automation Service
SyncConverter sc = new SyncConverter("Word Automation Service Application");
sc.UserToken = web.CurrentUser.UserToken;
sc.Settings.UpdateFields = true;
sc.Settings.OutputFormat = SaveFormat.PDF;
// Convert to PDF
ConversionItemInfo info = sc.Convert(wordContents, pdfContents);
if (info.Succeeded)
{
fileStream = new FileStream(filePath, FileMode.Create, FileAccess.ReadWrite);
pdfContents.WriteTo(fileStream);
}
else
{
}
}
if (fileStream != null)
{
fileStream.Close();
}
wordContents.Close();
}

}
}


If document contains .emf file then the error occurred with the error-code 65545. When I remove the .emf file and try to convert the document using above mentioned code then it converts document successfully. Is there anything that the word automation services does not convert the document if .emf file is there or am I missing something in my code?








0 commentaires:

Enregistrer un commentaire