0

下面的代码用于nconvert将多个tiff图像合并到一个pdf文件中。我的问题是:只要一个“文档或 pdf 文件”应该只包含一个 tiff 图像,脚本就会崩溃。如果有人可以查看脚本,并对为什么会出现这种情况有任何想法,将不胜感激。

$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"


 }
4

0 回答 0