0

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"


 }
Paolo Stefan
  • 10,112
  • 5
  • 45
  • 64
Peter3
  • 2,549
  • 4
  • 20
  • 40
  • It would greatly help if you mentioned what tool you are using to merge the tiff files... – Paolo Stefan Jul 15 '13 at 16:09
  • nconvert. The last line in the script is the part of the script that does the actual conversion. – Peter3 Jul 15 '13 at 17:06
  • Your assignments to `$matches`,what's going on there? I don't know much about tiff conversion, but I do code and know about powershell, so gimmie the details. – MDMoore313 Jul 15 '13 at 17:36
  • Well i am new to coding so i will try and explain best i can. The Matches has to do with the naming of the file and the output path. The number corresponds to each spot in the array that is created by the -match parameter. Where the patterns are spelled out at the top, the groups that have parentheses around them represent one place in the array. – Peter3 Jul 15 '13 at 17:42
  • Can you post the error that you are receiving? – MDMoore313 Jul 15 '13 at 17:43
  • GS: (C:\Program Files\gs\gs9.07\bin\gsdll64.dll) ARG 0 -dNODISPLAY ARG 1 -dQUIET ARG 2 -sPDFname=C:\Convert\2013\6\JJF555.pdf ARG 3 -sDSCname=C:\Users\PMANCA~1.SCE\AppData\Local\Temp\x_8AD5.tmp ARG 4 pdf2dsc.ps ARG 5 -c quit ==> 134 – Peter3 Jul 15 '13 at 17:45
  • ERROR: -101 GS: (C:\Program Files\gs\gs9.07\bin\gsdll64.dll) ARG 0 -dBATCH ARG 1 -dFirstPage=1 ARG 2 -dLastPage=1 ARG 3 -dMaxBitmap=300000000 ARG 4 -sDEVICE=tiff24nc ARG 5 -q ARG 6 -dNOPAUSE ARG 7 -dSAFER ARG 8 -dTextAlphaBits=4 ARG 9 -dGraphicsAlphaBits=4 ARG 10 -g611x791 ARG 11 -r72x72 ARG 12 -sOutputFile=C:\Users\PMANCA~1.SCE\AppData\Local\Temp\x_8B63.tmp ARG 13 C:\Convert\2013\6\JJF555.pdf ARG 14 -c quit ARG 15 -c quit – Peter3 Jul 15 '13 at 17:45

0 Answers0