1

I have used word automation service on farm solution to convert document to PDF.

When I upload document less than 10,000 KB it's worked.

Here is my VS code to convert doc to PDF

  byte[] result = spfile.OpenBinary();
        try
        {
            if (spfile != null)
            {
                using (Stream read = spfile.OpenBinaryStream())
                {
                    using (MemoryStream write = new MemoryStream())
                    {

                        if (Path.GetExtension(spfile.Name) == ".docx" || Path.GetExtension(spfile.Name) == ".doc")
                        {
                            WordServiceApplicationProxy proxy =
                                (WordServiceApplicationProxy)
                                    SPServiceContext.GetContext(sitefortoken)
                                        .GetDefaultProxy(typeof(WordServiceApplicationProxy));
                            //SyncConverter sc = new SyncConverter((WordServiceApplicationProxy)proxy);

                            SyncConverter sc = new SyncConverter(proxy);
                            //SyncConverter sc = new SyncConverter(proxy);
                            sc.UserToken = usrToken;
                            sc.Settings.UpdateFields = true;
                            sc.Settings.OutputFormat = SaveFormat.PDF;
                            sc.Settings.OutputSaveBehavior = SaveBehavior.AppendIfPossible;
                            sc.Settings.FixedFormatSettings.Bookmarks = FixedFormatBookmark.Headings;
                            sc.Settings.FixedFormatSettings.BalloonState = BalloonState.OnlyCommentsAndFormatting;
                            sc.Settings.MarkupView = MarkupTypes.Text;
                            sc.Settings.RevisionState = RevisionState.OriginalShowingMarkup;
                            sc.Settings.FixedFormatSettings.IncludeDocumentProperties = true;
                            //// Convert to PDF
                            ConversionItemInfo info = sc.Convert(read, write);
                            if (info.Succeeded)
                            {
                                result = write.ToArray();
                            }
                        }
                    }
                }
            }

When I am upload document which size is more then 10,000 KB is give following error on VS

 Error code :- 65545
 Error Message is
 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.

I have also tried using PowerShell but no luck. below is PowerShell code

    Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue
    # Input parameters for the script
    $wordFile="http://my word file url"
    $date = Get-Date -format yyyy_MM
    $pdfFile="http://destination file url"+$date+".pdf"

    # Get the Word Automation Service Proxy

    $wasp = Get-SPServiceApplicationProxy -Identity "842a5801-4f73-4148-8c57-96c7893ed054"

    #Create the Conversion job
    $conversionJob = New-Object Microsoft.Office.Word.Server.Conversions.ConversionJob($wasp)

    # Get the web url
    $web = Get-SPWeb "http://my sherepoint web site url"

    # Set the credentials to use when running the conver$sion job.
    $conversionJob.UserToken = $web.CurrentUser.UserToken

    # Conversion Job Name
    $conversionJob.Name = "Convert docx to PDF"
    $conversionJob.Settings.OutputFormat = [Microsoft.Office.Word.Server.Conversions.SaveFormat]::PDF
    $conversionJob.AddFile($wordFile,$pdfFile)

    # Start the conversion job
    $conversionJob.Start()

My SharePoint Environment is 2013

1
  • Check SharePoint ULS logs. Commented Feb 10, 2017 at 10:57

1 Answer 1

0

Try to run this code in power-shell

$sp = Get-SPServiceApplication | where {$_.TypeName.Equals("Word Automation Services")}
$sp.DisableSandbox = $true
$sp.Update()

Reset IIS after operation completed, for more detail visit this link

1
  • 1
    Sorry, In 2013 SharePoint when tried to execute this PowerShell it's say "DisableSandbox" is not available Commented Feb 10, 2017 at 11:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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