Adding PDF Full Text Search to installation script

Feb 21, 2011 at 10:20 PM

For my project, I needed to add the ability for full text searching of PDF documents. Hopefully this helps someone else out. I added this code to the Provision Enterprise Search region, just above the last writeline statement. This code assumes you've placed a PDF icon called "pdf.gif" and also placed the PDF iFilter installation msi file into the AutoSPInstaller directory. This code is primarily adapted from the code in this blog: http://itbloggen.se/cs/blogs/josko/archive/2011/02/02/use-powershell-to-configure-pdf-search-in-sharepoint-2010.aspx

#Region Add PDF Search capability to Enterprise Search
 $searchApp = Get-SPEnterpriseSearchServiceApplication -Identity $appConfig.Name -ErrorAction SilentlyContinue
 Write-Host -ForegroundColor White " - Configuring PDF Full Text Search. . . ."
 
 Write-Host -ForegroundColor White " - Copy PDF Icon"
 if (-not $(Test-Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\IMAGES\pdf.gif"))
 {
  $DestFile = "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\IMAGES\pdf.gif" 
  $pdfIcon = $dp0 + "\pdf.gif"
  Write-Host -ForegroundColor White " - PDF icon location =  $pdfIcon"
  Write-Host -ForegroundColor White " - PDF destination   = $DestFile"
  Write-Host -ForegroundColor White " - Copying the PDF icon to C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\IMAGES\pdf.gif"
  copy-item $pdfIcon -destination $DestFile -ErrorVariable err -ErrorAction "SilentlyContinue"
        if ([String]::IsNullOrEmpty($err) -eq $true) {
   Write-Host -ForegroundColor White " - Copy operation completed."
  } else {
   Write-Host -ForegroundColor White " - Copy ERROR: $err"
  }
 }
 else
 {
  Write-Host -ForegroundColor White " - PDF icon already exists."
 }
  
 Write-Host -ForegroundColor White "Adding PDF to the list of search crawl extensions in the Search Appliation..."
    $PDFcheck = get-SPEnterpriseSearchCrawlExtension "pdf" -SearchApplication $searchApp -ErrorVariable err -ErrorAction "SilentlyContinue" | Out-Null
 if ([String]::IsNullOrEmpty($PDFcheck) -eq $true){
  new-SPEnterpriseSearchCrawlExtension "pdf" -SearchApplication $searchApp -ErrorVariable err -ErrorAction "SilentlyContinue" | Out-Null
  if ([String]::IsNullOrEmpty($err) -eq $true) {
   Write-Host -ForegroundColor White " - Add completed."
  } else {
   Write-Host -ForegroundColor White "Error: $err"
  }
 }
 Else{
  Write-Host -ForegroundColor White " - The PDF extension was already in the list"
 }
 
 Write-Host -ForegroundColor White " - Adding pdfs as extension to docicons xml file"   
    $XMLfile = "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\XML\DOCICON.XML"
    [xml]$dociconxml = get-content  $XMLfile -ErrorVariable err -ErrorAction "SilentlyContinue"
 if ([String]::IsNullOrEmpty($err) -eq $true) {
        $PNGelement = $dociconxml.DocIcons.ByExtension.Mapping | Where-Object { $_.Key -eq "png" }
        $PDFnode = $dociconxml.DocIcons.ByExtension.Mapping | Where-Object { $_.Key -eq "pdf" }
        if ($PDFnode.key -eq "pdf"){
            Write-Host -ForegroundColor White " - XML document was already updated."
        }
        else{ # Add a new pdf node to the xml document
            $element = $dociconxml.DocIcons.ByExtension.Mapping[0].clone() # Duplicates an existing node
         $element.key = "pdf"
         $element.value = "pdf.gif"
         $element.OpenControl = ""
         $element.EditText = ""
         $dociconxml.DocIcons.ByExtension.InsertBefore($element,$PNGelement)  | Out-Null # Inserts the new node before the existing PNG element
            $dociconxml.save($XMLfile)
            if ([String]::IsNullOrEmpty($err) -eq $true) {
    Write-Host -ForegroundColor White " - XML updated."
   } else {
    Write-Host -ForegroundColor White " - Update ERROR: $err"
   }
        }
 } else {
  Write-Host -ForegroundColor White " - XML was not found: $err"
 }

    Write-Host -ForegroundColor White " - Running the PDF iFilter installer ($dp0\PDFFilter64installer.msi)..."
 if (-not $(Test-Path "C:\Program Files\Adobe\Adobe PDF iFilter 9 for 64-bit platforms\bin\PDFFilter.dll"))
 {
  $proc = Start-Process C:\Windows\System32\msiexec.exe " /passive /i $dp0\PDFFilter64installer.msi" -wait -ErrorVariable err -ErrorAction "SilentlyContinue" 
  if ($LASTEXITCODE -eq "0"){
   Write-Host -ForegroundColor White " - OK" }
  else{
   Write-Host -ForegroundColor White " - Probably OK (Installation returned error code: $LastExitCode)" 
  }
 }
 else
 {
  Write-Host -ForegroundColor White " - PDF iFilter already installed!"
 }
   
    Write-Host -ForegroundColor White " - Adding the PDF dll path to the system path..."
    AddSystemPaths("C:\Program Files\Adobe\Adobe PDF iFilter 9 for 64-bit platforms\bin\")
 
 Write-Host -ForegroundColor White " - Adding pdf entries for Sharepoint PDF Search in the registry..."
  # if (-not $(Test-Path -Path $InputFile -Type Leaf))
 if (-not $(Test-Path "HKLM:\SOFTWARE\Microsoft\Office Server\14.0\Search\Setup\Filters\.pdf"))
 {
  New-Item -path registry::'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office Server\14.0\Search\Setup\Filters\.pdf' | Out-Null
  New-ItemProperty -Path registry::'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office Server\14.0\Search\Setup\Filters\.pdf' -Name "Extension" -value ".pdf" -PropertyType string  | Out-Null
  New-ItemProperty -Path registry::'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office Server\14.0\Search\Setup\Filters\.pdf' -Name "Mime Types" -value "application/pdf" -PropertyType string  | Out-Null
  New-ItemProperty -Path registry::'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office Server\14.0\Search\Setup\Filters\.pdf' -Name "FileTypeBucket" -value "1" -PropertyType dword  | Out-Null
 }
 if (-not $(Test-Path "HKLM:\SOFTWARE\Microsoft\Office Server\14.0\Search\Setup\ContentIndexCommon\Filters\Extension\.pdf"))
 {
  New-Item -Path registry::'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office Server\14.0\Search\Setup\ContentIndexCommon\Filters\Extension\.pdf' | Out-Null
  New-ItemProperty -Path registry::'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office Server\14.0\Search\Setup\ContentIndexCommon\Filters\Extension\.pdf' -name "(Default)" -Value "{E8978DA6-047F-4E3D-9C78-CDBE46041603}" -PropertyType string | Out-Null
 }

    Write-Host -ForegroundColor White " - Re-register the adobe iFilter dll..."
 if (-not $(Test-Path "C:\Program Files\Adobe\Adobe PDF iFilter 9 for 64-bit platforms\bin\PDFFilter.dll"))
 {
  regsvr32.exe "C:\Program Files\Adobe\Adobe PDF iFilter 9 for 64-bit platforms\bin\PDFFilter.dll"
 }
 
 # Finally, issue an IISReset and restart the sharepoint search service
 Write-Host -ForegroundColor White " - Restarting IIS. . . ."
    Start-Process -FilePath iisreset.exe -ArgumentList "-noforce" -Wait -NoNewWindow
 Write-Host -ForegroundColor White " - Restarting the Search Service..."
    Stop-Service "OSearch14"
    Start-Service "OSearch14"
 #EndRegion

Coordinator
Apr 7, 2011 at 2:22 AM

Hey there, so I've put together a new & improved version of the script above, which will actually download & install the PDF iFilter and icon to further automate this. Just need to figure out where it will fit in the AutoSPInstaller... thanks for the suggestion and sorry for the delayed response!

Cheers
Brian

Apr 7, 2011 at 2:41 PM
Cool. It's a great tool so happy to be able to make my own small contribution....
Stephen


On Wed, Apr 6, 2011 at 7:22 PM, brianlala <notifications@codeplex.com> wrote:

From: brianlala

Hey there, so I've put together a new & improved version of the script above, which will actually download & install the PDF iFilter and icon to further automate this. Just need to figure out where it will fit in the AutoSPInstaller... thanks for the suggestion and sorry for the delayed response!

Cheers
Brian

Read the full discussion online.

To add a post to this discussion, reply to this email (autospinstaller@discussions.codeplex.com)

To start a new discussion for this project, email autospinstaller@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com


Jun 13, 2011 at 12:15 PM
brianlala wrote:

Hey there, so I've put together a new & improved version of the script above, which will actually download & install the PDF iFilter and icon to further automate this. Just need to figure out where it will fit in the AutoSPInstaller... thanks for the suggestion and sorry for the delayed response!

Cheers
Brian

Hi,

This is exactly what i'm after :D ... where could I find the version of the script with this in?

Thanks

Jenny

Coordinator
Jun 13, 2011 at 4:42 PM

I'm just about to check in some code that includes this improved PDF config function (in the AutoSPInstallerFunctionsCustom.ps1). Stay tuned!

Brian

Jun 14, 2011 at 9:14 AM

That'd be brill - eyes are peeled!

Jul 25, 2011 at 8:41 PM

Hi Brianlala, The new AutoSPInstaller Scripts connects to internet to download the pdf icon. But my dev machine does not have access to internet. Where to change in the script to do an offline install.

Jul 28, 2011 at 6:23 PM

Hi briana,

Autospinsatller is doing a great job. But only problem is at the end, when pdf installation is happeneing, it is connecting to internet to download the pdf icon. But my server do not have internet access and even i placed the gif file in 14 hive or in \sp2010\pdf folder, autospinstaller is not picking from here. Can yuo please verify and update me on this. Thanks much in advance.

Jul 28, 2011 at 6:28 PM

did you rename the PDF icon file to icpdf.gif?

Jul 28, 2011 at 8:32 PM

Yes I did

Coordinator
Jul 29, 2011 at 2:55 AM

The function looks for icpdf.gif in each of \SP2010\PDF\, \SP2010\AdobePDF\ and %TEMP%\ if it does not first find it in ...\14\Template\Images\ - check these locations, otherwise not sure why it would not find it...

Brian

Aug 4, 2011 at 5:33 PM

Sorry brianala, it is my mistake. The PDF is named as icpdf.gif.gif instead of icpdf.gif, hence the script failing for me. Today i realised it and ran AutoSpinstaller after changing the name. it worked perfectly. Thanks again.