Advertisement
E-M-R

Uber Invoice PDF Scaper

Nov 12th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Need to install the Dll first
  2. Add-Type -Path "G:\Uber Reciepts\iTextSharp.5.5.13\lib\itextsharp.dll"
  3. $pdfs = gci "G:\Uber Reciepts" *.pdf
  4. $export = "G:\Uber Reciepts\export.csv"
  5.  
  6.  
  7. foreach($pdf in $pdfs) {
  8.  
  9.     Write-Host "Processing -" $pdf.FullName
  10.  
  11.     # prepare the pdf
  12.     $reader = New-Object iTextSharp.text.pdf.pdfreader -ArgumentList $pdf.FullName
  13.  
  14.     # for each page
  15.     for($page = 1; $page -le $reader.NumberOfPages; $page++) {
  16.  
  17.         # set the page text
  18.         $pageText = [iTextSharp.text.pdf.parser.PdfTextExtractor]::GetTextFromPage($reader,$page).Split([char]0x000A)
  19.  
  20.         $invoiceDate = $pageText | Select-String -Pattern '.*Invoice Date:\s*([^\n\r]*)' | %{"$($_.matches[0].groups[1].value)"}
  21.         $invoiceNo = $pageText | Select-String -Pattern '.*Invoice Number:\s*([^\n]*)' | %{"$($_.matches[0].groups[1].value)"}
  22.         $gross = $pageText | Select-String -Pattern '.*Gross Amount\s*([^\n]\d+.\d+)' | %{"$($_.matches[0].groups[1].value)"}  
  23.    
  24.         "$invoiceDate,$invoiceNo,$gross" | Out-File -FilePath $export -Append
  25.        
  26.     }
  27.     $reader.Close()
  28. }
  29.  
  30. Write-Host ""
  31. Write-Host "Done"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement