Click here to Skip to main content
13,149,756 members (67,480 online)
Click here to Skip to main content
Add your own
alternative version


1 bookmarked
Posted 12 Mar 2014

HTML to PDF Conversion using Sharepoint Management Shell 2010

, 12 Mar 2014
Rate this:
Please Sign up or sign in to vote.
HTML to PDF Conversion using Sharepoint Management Shell 2010


We create many lists in Sharepoint. So it would be better if there is a simple way to convert those lists into PDF format. By doing this, we can save storage space too.

What is wkhtmltopdf.exe??

wkhtmltopdf is a command line tool to render HTML into PDF. These run entirely "headless" and do not require a display or display service.

You can download this from Make sure that you are downloading the right version. This trick is for Windows.

Using the Code

$web = (New-Object Microsoft.SharePoint.SPSite("Site URL")).OpenWeb()
$lists = $web.Lists["List Name"]
foreach($item in $lists.Items)
$pagename= $item.File.Name -replace 'aspx','pdf'
$pageurl=    $web.url +"/"+ $item.File.url
$param= '--username <username> --password <password> '+ '
"' +$pageurl + '" '  + 'F:\FoldeName\'+$pagename
start-Process  -FilePath 'F:\wkhtmltopdf.exe' -ArgumentList $param
$pageurl+' Pagenumber:'+$count

Open Notepad with the above lines of code and save with .PS1 extension (let me consider as filename.PS1). In the given code, wkhtmltopdf.exe is downloaded and saved in F Folder. The output will be stored in F drive inside FolderName folder.

I introduced a $count variable. This is a simple way to ensure the total number of PDF created and later you can manually check to ensure all the items are converted to PDF format or not.

I have also introduced sufficient amount of Sleep to ensure the optimal performance.

How to Run the Sharepoint Management Shell Scripts ??

Open Sharepoint Management Shell and navigate to the folder where you have saved the Notepad file ( filename.PS1 ). Enter the following command:


Now the conversion process starts.

Enjoy it.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Ajith K Gatty
Software Developer (Junior)
India India
A Software Developer. Curiosity defines me. I find extreme happiness in learning new Technologies. I'm here to give something back to the community and the web from which I learned so much.Working hard to create my own identity in the world of Information and Technology.

You may also be interested in...


Comments and Discussions

QuestionMessage Closed Pin
29-Apr-14 20:46
memberpittypan29-Apr-14 20:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.170924.2 | Last Updated 12 Mar 2014
Article Copyright 2014 by Ajith K Gatty
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid