Tuesday, 2 November 2010

Convert Word documents to PDF in SharePoint Server 2010 using PowerShell

SharePoint Server 2010 Standard and Enterprise editions includes a feature called Word Automation Services. There is an excellent article here explaining it in more detail, but in summary, the feature provides the capability for converting documents from one Microsoft Word format to another (e.g., .doc to .docx), converting Word documents to .pdf or .xps, and execute tasks during the opening of a document – such as updating the Table of Contents or index fields.

Whilst there are probably more applications for converting documents in workflows and event receivers, a batch of documents can also be converted using PowerShell. In this article I shall run through the basic steps involved in converting documents with an example of how to convert Word documents to PDF, plus some information on how you can speed up the conversion process and also remove the original Word documents from SharePoint, once successfully converted.

Before you can start converting documents, you will need to create a Word Automation Service Application instance from the Manage Service Applications page in Central Administration, and start the Word Automation Services service from the Manage services on server page, also in Central Administration. I’m also assuming that you have a site ready with a document library containing the Word documents to be converted, as shown below.


Once you have your service application running, you can type the following two lines in PowerShell to connect to the Word Automation Services Proxy and set up the variable for a new conversion job:

$wasp = Get-SPServiceApplicationProxy | where { $_.TypeName -eq "Word Automation Services Proxy" }
$job = New-Object Microsoft.Office.Word.Server.Conversions.ConversionJob($wasp)

Next, we will get the site, folder containing the Word documents to be converted, and folder to store the converted PDF documents (this folder can be the same). Note that in addition to converting documents in folders, the ConversionJob class also contains methods to add individual files or complete document libraries, if preferred:

$web = Get-SPWeb http://portal/team
$inputFolder = $web.GetFolder("Shared Documents/Word Documents")
$outputFolder = $web.GetFolder("Shared Documents/PDF Documents")

We can now set up our conversion job using the properties available in the ConversionJob class. This includes a description for the job, specifying PDF as the save format, and choosing to overwrite any PDF documents with the same name that currently exist in the folder:

$job.UserToken = $web.CurrentUser.UserToken
$job.Name = "Convert Hello Docs to PDF"
$job.Settings.OutputFormat = [Microsoft.Office.Word.Server.Conversions.SaveFormat]::PDF
$job.Settings.OutputSaveBehavior = [Microsoft.Office.Word.Server.Conversions.SaveBehavior]::AlwaysOverwrite

The AddFolder method below includes the input folder (source folder containing the Word documents), output folder (destination folder into which the converted PDF documents will be copied), and a boolean option specifying whether you want to include sub-folders under the input folder. For example, if this is set to $true, then documents will be converted from the input folder and all documents in sub-folders below it:

#Add input and output folders and start conversion
$job.AddFolder($inputFolder, $outputFolder, $false)

You can view the status of your job by typing the following commands:

$status = New-Object Microsoft.Office.Word.Server.Conversions.ConversionJobStatus($wasp.Id, $job.JobId, $null)

An example of a conversion status report is shown below:

If you are wondering why the status for your documents are shown as “NotStarted”, it is because they are converted by a timer job, which by default runs every 15 minutes. If you want to start this timer job now instead of waiting, type the following:

$watj = Get-SPTimerJob "Word Automation Service Application"

Once the timer job has been run, the updated status will look as follows:


There is a nice bit of C# code in this article from the Microsoft Word product team blog which waits until all documents have been converted and then deletes the successfully converted Word documents from the input location. I have adapted this for use in PowerShell below. Just tack it on to the end of the timer job commands if you want to include it in a PS1 script file:

[bool]$done = $false
write-host "Converting files - Please wait..."
    Start-Sleep -s 5
    $status = New-Object Microsoft.Office.Word.Server.Conversions.ConversionJobStatus($wasp.Id, $job.JobId, $null)
    if ($status.Count -eq ($status.Succeeded + $status.Failed + $status.Canceled))
        $done = $true
        #Delete original Word files successfully converted to PDF
        #Remove this code if you want to keep the documents in their original location
        $itemType = [Microsoft.Office.Word.Server.Conversions.ItemTypes]::Succeeded
        $items = $status.GetItems($itemType)
        foreach($item in $items) {
            $file = $web.GetFile($item.InputFile)
write-host "Conversion operation complete - Status report:"

Once the job has completed, you should see the converted PDF files in the output location specified in the script:



  1. Replies
    1. Great Article IoT Projects for Students

      Deep Learning Projects for Final Year

      JavaScript Training in Chennai

      JavaScript Training in Chennai

      The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training

  2. So I've got your code running, many thanks! Question: my word doc has some embedded links to external files (when you open the doc, it asks to get the latest content from the linked files). When I add the $job.Settings.UpdateFields = $True
    I was hoping those links would be refreshed. No such luck. Any ideas?

  3. Thanks, great work!

    Here is another solution to create PDF documents:

    The solution is dynamically creating a PDF document from a SharePoint list using a template engine to customize the PDF output.

  4. To enhance document conversion (including conversion in PDF) in sharepoint workflows, there is HarePoint Workflow Extensions software
    ( http://www.harepoint.com/Products/HarePointWorkflowExtensions/ ) - about 200 new workflow activities, including free ones.

  5. Great post Phil!

    Have you run this against newer SP2010 CU patch levels? I am able to run the above PowerShell against RTM, but not against SP1 or SP1+Dec CU. Below is a thread where others are seeing the same WCF failure. Any ideas would be greatly appreciated! !



  6. Hi,
    Thanks for your post.
    How to add text in to the Pdf?...

  7. You would have to add text to the Word document before converting it.

  8. Hi,

    Thanks for a good article. Anyone know if it´s possible to get the metadata from the doc to be written into the pdf item?

  9. Very niced post and it was a great help for me.
    keep up good work!

  10. تعد الاخلاص افضل شركة تنظيف ومكافحة حشرات بالطائف فهى تقدم افضل الخدمات وباقل الاسعار لانها تتميز بانها افضل :
    افضل شركة رش مبيدات بالطائف
    افضل شركة مكافحة حشرات بالطائف
    افضل شركة تنظيف خزانات بالطائف
    شركة تنظيف منازل بالطائف
    تسليك مجاري بالطائف
    شركة عزل خزانات بالطائف
    نستخدم افضل المبيدات في عمليات الرش للقضاء النهائي على الحشرات بجميع انواعها ونوفر عدة خدمات تنظيف اخرى فدوما يمكنك الاتصال بنا للحصول على افضل الخدمات وباسعار مناسبة
    شركة رش مبيدات بالرياض
    افضل شركة تنظيف خزانات بالرياض
    شركة عزل اسطح بالرياض
    افضل شركة تنظيف بالخرج
    شركة نقل اثاث بالخرج
    افضل شركة تنظيف مجالس بالطائف
    افضل شركة تنظيف منازل بالطائف
    افضل شركة عزل اسطح بالطائف
    افضل شركة نقل عفش بالطائف

  11. لابد من الاستعانة بشركة متخصصة في مكافحة النمل الابيض للتخلص منه وتلافي اخطاره فالاول تعد من افضل شركات مكافحة الحشرات وخدماتها تغطى جميع مناطق المملكة فالاول افضل شركة مكافحة النمل الابيض بالرياض وافضل شركة مكافحة النمل الابيض بجدة وافضل شركة مكافحة النمل الابيض بمكة وافضل شركة مكافحة النمل الابيض بالخبر وافضل شركة مكافحة النمل الابيض بالقصيم وتقوم ايضا بمكافحة النمل الابيض قبل البناء
    شركة مكافحة النمل الابيض بالمدينة المنورة
    الفبرونيل وهي مادة قوية جدا وفعالة جدا للنمل الابيض وهناك مادة البايفلكس
    بايفلكس Biflex TCشركة مكافحة النمل الابيض بالجبيل
    شركة مكافحة النمل الابيض بالاحساء
    - شركة مكافحة النمل الابيض بابها - شركة مكافحة النمل الابيض بينبع

  12. This comment has been removed by the author.

  13. The main reason why people use the typing services is because the services aid in facilitating the daily routine. typing documents

  14. Selamat menunaikan ibadah puasa Salam dari Obat Epilepsi Semoga barokah

  15. needed to thank you for this very good read! pantangan kista

  16. There are a whole range of software that are available to help you convert PDF files into different formats and let us have a look at some of the popular PDF Applications that are available online. Adobe After Effects CS6

  17. thank for information, is the nice post. Informasi yang sangat bermanfaat sekali, terima kasih banyak atas informasinya yah obat iritasi kulit wajah karena kosmetik

    obat asam lambung tinggi untuk ibu hamil

  18. I'll review this blog as An and it demonstrates how much exertion has been put into this.
    eidas compliance

  19. It is great to have visited your website. Thanks for sharing useful information. And also visit my website about health. God willing it will be useful too

    Obat Sakit Dada
    Obat Tumor Jinak diatas Bola Mata
    Obat Penghilang Nyeri Lutut
    Obat Penghilang Nyeri Pada Payudara
    Pengobatan penyakit Meningioma
    Obat Luka Bernanah bekas Caesar

  20. I want to say thanks to you. I have bookmark your site for future updates. https://www.altoconvertpdftoword.com/

  21. I think this is an informative post and it is very useful and knowledgeable. therefore, I would like to thank you for the efforts you have made in writing this article. business document software

  22. También puede visitar una tienda de ladrillo y mortero de Michael Kors o su sitio web y comprar directamente un bolso Michael Kors desde allí. Usar un bolso de Michael Kors les permite a los demás reconocer que el habitante urbano educado toma la moda realmente con seriedad. Los bolsos de hombro son particularmente refinados y elegantes.

    {Bolsas Michael Kors Precios | Bolsos Michael Kors Outlet | Michael Kors Rebajas}

    En vacker konstnärlig skapelse av vävt läder, som ger ett skalskaligt utseende - liknar en snakeskin eller fiskhud, linjer utsidan av påsen. Läderens bältros är små läderringar. Det finns också gyllene accenter på väskan. Slutresultatet är svagt liknar kedjepost.

    {Michael Kors Rea | Michael Kors Väska Rea | Michael Kors Plånbok}

  23. Some essential instruments are the devices that can make PDF records from Microsoft Word archives. https://www.altoconvertwordtopdf.com/blog/word_and_pdf_are_just_one_step_apart

  24. Intriguing post. I Have Been pondering about this issue, so much obliged for posting. Really cool post.It "s truly extremely pleasant and Useful post.Thanks dokument

  25. Luckily, Word 2007 accompanies an implicit utility to make a PDF record! You should simply type up your report and afterward tap on the Office button (in the upper left corner), and snap Save As > PDF or XPS. https://ds11.pdffiller.com/en/features.htm

  26. They can clarify how science frequently propels with the presentation of new advances and how tackling innovative issues regularly results in new logical learning. diebestenvpn

  27. A beautiful purse or handbag from Coach Outlet Online can last for many years, and represent a great overall value.
    There are Michael Kors Bags Outlet in a large number of shopping malls located throughout the country.
    Cheap Michael Kors Bags is a great way to determine which models best suit your needs.
    Official Coach Factory Outlet Online all strive to provide comfort and convenience for their owners and the seams are double-stitched for maximum durability.
    Michael Kors Factory Store, has one of the most popular handbag and accessory lines on the market today.
    Coach Handbags Wholesale says a lady is classy, elegant and sophisticated.
    Coach Store Near Me trends come and go, but a Coach stands the test of time.
    The official Michael Kors Handbags On Sale Outlet regularly posts various handbags being offered for sale.
    Compare your Coach Bags On Sale Outlet to the logo provided on the website to make sure it is similar.
    All Michael Kors Outlet Online Store have serial numbers.

  28. No matter what type of Michael Kors Bags Outlet each individual got, they all had one thing in common. We all know that getting something on sale is like winning a mini lottery, but to find a name brand handbag like Michael Kors Black Friday Sale for instance, discounted is like a slice of heaven on earth. I have personally attacked my husband with hugs and kisses when finding Official Coach Outlet Online at discounted prices.

    Michael Kors Factory Outlet stores can be found in malls all over. MK Outlet and other Coach merchandise can also be found in some boutiques. Inspired by the same material baseball gloves are made from, these Coach Bags On Sale Online are versatile and stylish. Since it's conception, the Michael Kors Handbags Outlet has been produced into a variety of designs, colors, shapes, and styles that have won top pick of millions of women the world over.

    New Michael Kors Bags are the most sought after handbag. Since Coach Outlet Online is one of the most recognized name brands in the world of fashion, you will find A-list celebrities down to small girls wearing them.

    tags:Coach Outlet|Coach Bags Factory Outlet|Coach Purses Outlet

  29. Excellent article. Very interesting to read. I really love to read such a nice article. Thanks! keep rocking. liquid stoomtovenaar nicsalt tropical

  30. Thanks for posting this info. I just want to let you know that I just check out your site and I find it very interesting and informative. I can't wait to read lots of your posts. water softener system los angeles

  31. Took me time to read all the comments, but I really enjoyed the article. It proved to be Very helpful to me and I am sure to all the commenters here! It’s always nice when you can not only be informed, but also entertained! berry jaga

  32. What a fantabulous post this has been. Never seen this kind of useful post. I am grateful to you and expect more number of posts like these. Thank you very much. Led backpack

  33. I would like to say that this blog really convinced me to do it! Thanks, very good post. Pressure Washing Portland Oregon

  34. Great article Lot's of information to Read...Great Man Keep Posting and update to People..Thanks pressure cleaning

  35. New web site is looking good. Thanks for the great effort. noticias de estilo de vida

  36. I read that Post and got it fine and informative. Pressure Washing

  37. I appreciated your work very thanks wichita jewelry

  38. Wow! Such an amazing and helpful post this is. I really really love it. It's so good and so awesome. I am just amazed. I hope that you continue to do your work like this in the future also Product Creation

  39. I admire this article for the well-researched content and excellent wording. I got so involved in this material that I couldn’t stop reading. I am impressed with your work and skill. Thank you so much. Private investigator San Diego

  40. I definitely enjoying every little bit of it. It is a great website and nice share. I want to thank you. Good job! You guys do a great blog, and have some great contents. Keep up the good work. San Diego Private investigator

  41. سرویس و تعمیر اتو در مرکز جامع تعمیرات تخصصی انواع لوازم خانگی

    دسته تعمیرات اتو