SIGN UP MEMBER LOGIN:    
ARTICLE

How to convert docx to pdf document in SharePoint 2010 using Word Automation Services: Part 3

Posted by Vijai Anand Articles | SharePoint December 27, 2010
In this article we will be seeing how to convert .docx document to pdf document in SharePoint 2010.
Reader Level:


In this article we will be seeing how to convert .docx document to pdf document in SharePoint 2010.

Word Automation Services is a new feature available in SharePoint 2010. It supports converting Word documents to other formats. Here we are going to convert the word document into pdf document. In the API for Word Automation Services there are different ways to convert documents including AddFile(), AddFolder() and AddLibrary() methods. Here we will be using AddFolder() method to convert the word document. You need to specify two folders inputFolder (where the word documents are present) and the outputFolder (where the converted pdf files should be created).

This article describes the following steps to show how to call the Word Automation Services to convert a document:

  • Add a word document to the SharePoint Shared Documents.
  • Create a console Application.
  • Add a reference to the Microsoft.Office.Word.Server assembly.

Add a word document in the Shared Documents:

share1.gif

Create a console application:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Word.Server.Conversions;
using Microsoft.SharePoint;

namespace Test
{
    static class Program
    {
        static void Main(string[] args)
        {                 
            using (SPSite spSite = new SPSite( "http://servername:4040/"))
            {
                using(SPWeb web=spSite.OpenWeb())
                {
                 SPFolder inputFolder=web.GetFolder("Shared Documents/Word Documents");
                 SPFolder outputFolder = web.GetFolder("Shared Documents/PDF Documents");              
                //Defines a collection of settings for all conversions within a single conversion job.
                ConversionJobSettings jobSettings=new ConversionJobSettings();
                jobSettings.OutputFormat = SaveFormat.PDF;
                //Represents a collection of file conversions (of single files or entire libraries) that share a common set of conversion properties and are logically tracked as a single unit.
                ConversionJob pdfConversion = new ConversionJob("Word Automation Services", jobSettings);
                // Set the credentials to use when running the conversion job.
                pdfConversion.UserToken = spSite.UserToken;
                pdfConversion.AddFolder(inputFolder, outputFolder, false);
                pdfConversion.Start();
                }
            }
        }
    }
}

  • Build the solution and hit F5.

  • Go to the Shared Documents => PDF Documents folder; pdf files are successfully created.

    share2.gif

Login to add your contents and source code to this article
share this article :
post comment
 

Thanks so much for this great tutorial of how to convert <a href="http://www.ecrion.com/landingpage/docxtopdf.aspx">docx to pdf</a>. I can't wait to get home and try it out! Thanks again.

Posted by Ginny Crandall Apr 20, 2011

Hi , i follow ur article step by step, but unfortunately i got error : "The server did not provide a meaningful reply; this might be caused by a contract mismatch, a premature session shutdown or an internal server error." Can u help me!!!!!

Posted by Dhaval Mevada Jan 28, 2011
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
    ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
Team Foundation Server Hosting
Become a Sponsor