7

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?

1

Your code looks fine, I seriously doubt that is the cause of the problem. According to Microsoft's WAS documentation. Error 65545 means the following:

"The file could not be converted; it may be corrupt or otherwise invalid (the conversion process stopped responding). 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."

Ah yeah, the good old "contact your system administrator" answer.

Now, I work in the 'PDF Conversion for SharePoint' field so have considerable experience with all kind of relevant technologies including WAS. Although I am somewhat biased, WAS deserves its own place in hell. It is slow, has an awkward programming model (slightly better in SP2013, which I see you are using) and is overall just not particularly reliable as you have noticed. You may want to look into some third party software to deal with document conversion and manipulation in SharePoint, I can recommend a really good product :-)

Not perhaps the most helpful answer, or the answer you wanted, but please consider something other than WAS if you care about reliability.

-1

See if you have Active Directory on the same server where WAS is started: Reference

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.