The code below uses nconvert
to merge multiple tiff
images into one pdf
file. My issue is: whenever one "document or pdf file" is supposed to contain only one tiff image, the script will crash. If anyone can take a look at the script, and has any ideas on why this might be the case, it would be greatly appreciated.
$InputLocation = "C:\Convert"
$output = "C:\Convert"
$Inputbdf = "C:\Convert\0001.bdf"
$patternCN = "\|([^\|]*)\|([^\|]*)\|"
$patternD = "(\d)/\d\d/(\d\d\d\d)"
$docs = gci "$inputLocation\*0001.tif"
$docs.count
foreach($tiff in $docs){
$pattern = $tiff.FullName.Substring($tiff.FullName.length-12,4)
$patternI = "$pattern.*"
$pages = gci "$inputLocation\$pattern*.tif"
$pagen = $pages.count
$lines = Get-Content($inputbdf)|
Foreach-object{
write-host $PatternI
if($_ -match "C:\\[some folder]\\$patternI.TIF$patternCN$patternD"){
$a = $matches[2]
$b = $matches[1]
$c = $matches[4]
$d = $matches[3]
}
}
if((test-path -path "$output\$c") -eq $false){
New-Item $output\$c -type directory
if((test-path -path "$output\$c\$d") -eq $false){
new-Item $output\$c\$d -type directory
}
}
$tiff = $tiff.Name.split('.')[0]
cd C:\[my desktop folder]\Nconvert\XnView
#./nconvert -help > nchelp.txt
.\nconvert.exe -quiet -out pdf -c 3 -multi -n 1 $pagen 1 -o "$output\$c\$d\$a$b.pdf" "$InputLocation\$pattern####.tif"
}