Friday, 27 November 2015

SharePoint 2013: Replace the PDF icon




I uploaded a PDF to SharePoint 2013 and noticed that the PDD icon is not the official and recognizable Adobe PDF icon. In this article I will tell you how to replace the SharePoint 2013 PDF icon.
MS_PDF_ICON
OOTB PDF icon from SharePoint 2013
Is it a document with a belt or what ? Nevermind I don’t like it and I am very certain that most of the users out there do not recognize the icon – and that is the main purpose of the icon right?
Search_WithMSPDF
Search result with out-of-the-box SharePoint 2013 PDF icon
With SharePoint 2010 there was no PDF support out of the box – afaik there was no icon at all. I should be happy and quite right? Nope, created a small powershell that replaced the icon (either you place it next to the script or the script downloads it from the Adobe page).
The result will look like this – way better if you ask me.
Search_WithOriginalPDF
Original PDF icon – as expected!
PDF_Doclib
Same icon in a document library

Powershell to the rescue – once again!

And here comes the small script:
  1. #########################################################################################
  2. # by Max Melcher, http://melcher.it, @maxmelcher
  3. # Feel free to change and reuse as you wish - use on your own risk
  4.  
  5. # Script that replaces the OOTB SharePoint 2013 PDF icon with the orignal Adobe PDF icon.
  6. # Execute on each webfrontend
  7. #########################################################################################
  8.  
  9. #settings
  10. $destination = "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\TEMPLATE\IMAGES\icpdf.png"
  11.  
  12. #Check if the icon exists otherwise download it
  13. $item = Get-ChildItem pdficon_small.png -ErrorAction SilentlyContinue
  14.  
  15. #Helper
  16. function download{
  17. # usage: download http://url c:\temp
  18. param([string]$URL, [string]$destination)
  19. Write-Host "Downloading $URL ..."
  20. $clnt = new-object System.Net.WebClient -ErrorVariable err -ErrorAction "SilentlyContinue"
  21. $clnt.DownloadFile($url,$destination)
  22. if ([String]::IsNullOrEmpty($err) -eq $true)
  23. {
  24. Write-Output " - Download completed."
  25. }
  26. else
  27. {
  28. Write-Error "Download ERROR - Check URL: $err"
  29. }
  30. }
  31.  
  32. function RestartIIS(){
  33. $title = "Restart IIS"
  34. $message = "Do you want to restart the local IIS?"
  35. $yes = New-Object System.Management.Automation.Host.ChoiceDescription "Yes","Restarts IIS."
  36. $no = New-Object System.Management.Automation.Host.ChoiceDescription "No","Silently continues..."
  37. $options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no)
  38. $result = $host.ui.PromptForChoice($title, $message, $options, 0)
  39. if ($result -eq 0){
  40. Write-Host -ForegroundColor Yellow "Restarting IIS"
  41. iisreset /noforce
  42. }
  43. }
  44.  
  45.  
  46. if ($item)
  47. {
  48. Write-Host -ForegroundColor Yellow "Supplied icon found - overwriting"
  49. Copy-Item $item -Destination $destination -Force
  50. }
  51. else
  52. {
  53. Write-Host -ForegroundColor Yellow "Downloading icon from Adobe"
  54. Download "http://www.adobe.com/images/pdficon_small.png" $destination
  55. }
  56.  
  57. Write-Host -ForegroundColor Green "Icon replaced"
  58.  
  59. #Icon will only be changed after iisreset or reboot
  60. RestartIIS
  61.  
  62.  
  63. Write-Host -ForegroundColor Green "done!"

No comments:

Post a Comment