ARTICLE

How to convert docx to pdf document in SharePoint 2010 using Word Automation Services - Part 1

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


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 AddFile() method to convert the word document (this method will convert the word document within the same list).

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:

1.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
{
    class Program
    {
        static void Main(string[] args)
        {                
            using (SPSite spSite = new SPSite( "http://servername:4040/"))
            {  

           //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.AddFile("http://servername:4040/Shared%20Documents/ExternalList.docx",
                    "http://servername:4040/Shared%20Documents/ExternalList.pdf");
                pdfConversion.Start();
            }
        }
    }

}

2.gif

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

I am a complete novice at creating webpages. I want to use Sharepoint to convert maybe 20 Word (2007) documents into web pages. These documents have 10-15 thousand hyperlinks in them, all pointing to bookmarks in either the same document or in other of the documents to be converted. I want to know if the hyperlink-to-bookmark relationships will be maintained when the Word documents are converted to webpages. I especially want to know if clicking on a hyperlink in one of the documents will take the reader directly to the bookmark in the target document (and not just to the top of the page in the target document.) If this can be done, is it complicated or can it be accomplished automatically through some feature of Sharepoint? Thank you

Posted by Rich Thatcher Jul 08, 2011

Vijai, This code is right fit for my problem. I am very new to the C# coding. So could you please give a me some suggesstions how to change this code to make it a generic code to accept any DOC file and conver that to PDF. As well how to attach this code to a GRAPHIC button so as to make it easy for the user with a click of a button to accomplish this. Appreciate your help and thanks in advance. VijayMohan

Posted by VijayMohan Vasu Jan 03, 2011
COMMENT USING
PREMIUM SPONSORS
DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and add new content to existing PDF documents from within your applications.
Get Career Advice from Experts
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Join a Chapter