Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function Get-CroppedText
{
$pdftotext="C:\Program Files\xpdf\pdftotext.exe"
$bbox=$args[0]
$inFile=$args[1]
pdfcrop --bbox $bbox $inFile tmp2.pdf | Out-Null
& $pdftotext -nopgbrk tmp2.pdf - | Select-Object -First 1 | foreach { $_.Trim() }
rm tmp2.pdf
}
function Get-PageNum
{
pdftk $args[0] cat 1-1 output tmp.pdf | Out-Null
$pagenum=Get-CroppedText "250 36 260 43" tmp.pdf
$iPagenum=0
if ($pagenum -eq $nil -or ![System.Int32]::TryParse($pagenum, [ref]$iPagenum))
{
$pagenum=Get-CroppedText "250 16.5 260 21" tmp.pdf
}
if ($pagenum -eq $nil -or ![System.Int32]::TryParse($pagenum, [ref]$iPagenum))
{
$pagenum=Get-CroppedText "250 23.5 260 28" tmp.pdf
}
rm tmp.pdf
return $pagenum
}
$files=ls *.pdf | foreach { $pagenum=Get-PageNum $_.Name; @{pagenum=$pagenum; file=$_.Name} }
$files=($files | sort-object -property { [System.Int32]::Parse($_["pagenum"]) })
$f=cat list.txt; pdftk $f cat output VOLII.pdf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.