-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPDFtoMultipleTif.ps1
More file actions
executable file
·53 lines (35 loc) · 1.94 KB
/
PDFtoMultipleTif.ps1
File metadata and controls
executable file
·53 lines (35 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
cls
#Variable to hold current input directory
$InputDirectory = 'C:\test\sample pdfs'
$InputPathFilter = $InputDirectory + '\*.pdf'
#Variable to hold current output directory
$OutputDirectory = 'C:\test\sample pdfs\'
#Variable to hold the list of PDFs from the current input directory
$PDFList = @(gci $InputPathFilter | foreach {write-output $_.name})
#Check to verify output directory does not exist and then create the output directory
if ((Test-Path $OutputDirectory) -ne $TRUE) {
New-Item $OutputDirectory -type directory
}
#Loop through list of PDF files to convert to TIF image files.
for ($j=0; $j -lt $PDFList.count; $j++) {
#Each PDF will go into its own directory/batch
#Create a variable with only the file name
$FileName = $PDFList[$j] -replace(".pdf",'')
#Create a variable of the full path, with the timestamp
$OutputFullDirectory = $OutputDirectory + $FileName
#Create the subdirectory for the current PDF
if ((Test-Path $OutputFullDirectory) -ne $TRUE) {
New-Item $OutputFullDirectory -type directory
}
#Variable of the full path to the current PDF
$InputPath = $InputDirectory + '\' + $PDFList[$j]
#Variable to hold output path of each TIF file. Filename format is that used by batches in ScerIS (i.e. 00010001.tif, 00010002.tif, etc...)
$OutputFullDirectory = $OutputFullDirectory + '\'+ $FileName + "_" + "{0:D4}" -f + '1' + '%04d.tif'
#Calls Ghostscript command line executable to process each PDF file into a group of single page TIF image files
&'C:\Program Files\gs\gs9.16\bin\gswin64c.exe' -sDEVICE=tiffg4 -dBATCH -dNOPAUSE -q -r600 "-sOutputFile=$OutputFullDirectory" "$InputPath"
#Increment the counter for the loop
$DocCounter = $j + 1
#Rename the current pdf so that it isn't processed again.
#$RenamePath = $PdfList[$j] -replace("pdf", "pd_")
# Rename-Item $InputPath $RenamePath
}