以下是需要翻译的内容:
这是我想要解决的情况。我工作的公司每天都必须为学生打印多个pdf文档。每个pdf文档的最后一页必须使用蓝色纸张打印。我们目前的流程是手动打印pdf文档,将除最后一页以外的所有页面发送到一个有白色纸张存货的打印机,然后将最后一页发送到另一个有蓝色纸张托盘的打印机。这很耗时且乏味。我创建了一个PowerShell脚本,它可以获取给定文件夹中的所有pdf文档,首先将pdf文档拆分为两部分,第一部分是除最后一页以外的所有页面,第二部分是最后一页。然后脚本将每个pdf文档发送到适当的打印机。
但是这些PDF受到保护,因此脚本无法运行。通常在打开Adobe Reader几秒钟后它们会自动解密,但由于脚本立即打印它们,因此没有时间进行解码。
我想知道:
- 是否有一种方法可以在Powershell中解决加密问题?
- 此外,是否能够选择托盘来自动打印正确的彩色页面并只使用一个打印机?(这将是理想的,因为页面仍将按顺序排列。目前,我们没有两个托盘的打印机,但随着公司的扩张,我们肯定会有。)
据我所知,我认为问题2需要使用C#,如果能够自动选择纸盒,则愿意放弃我的PowerShell脚本。
以下是我的当前脚本(它不太好看,抱歉)
# Set Up Folders
$input = "C:\batchPrintPKs\unsplit_pdfs"
$output_f = "C:\batchPrintPKs\split_pdfs_f"
$output_l = "C:\batchPrintPKs\split_pdfs_l"
# Load Adobe and PDFtk (Used to split PDFs)
$adobe= 'C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe'
$pdftk = "C:\Program Files (x86)\PDFtk Server\bin\pdftk.exe"
# Printer Names
$printername_brother='Brother DCP-L2540DW series Printer'
$printername_epson='Epson854235 (ET-4550 Series)'
# Create List of Paths to Pdfs to Work With
$files1 = Get-ChildItem “c:\batchPrintPKs\unsplit_pdfs\*.pdf”
# For All PDFs in unsplit_pdfs
foreach ($file1 in $files1){
# Calculating Indexing
$Match = 'NumberOfPages: (\d+)'
$NumberOfPages = [regex]::match((& $pdftk $file1 dump_data),$Match).Groups[1].Value
$SecondToLastPage = $NumberOfPages - 1
# Making PDF of pages 1 - Second to Last
Get-Childitem -path $input -filter *.pdf -recurse | foreach {
& $pdftk $_.Fullname cat 1-$SecondToLastPage output $output_f\"f_"$_
}
# Making PDF of last page
Get-Childitem -path $input -filter *.pdf -recurse | foreach {
& $pdftk $_.Fullname cat $NumberOfPages output $output_l\"l_"$_
}
# Removing File
Remove-Item $file1
}
sleep(5)
# Brother
# Create List of Paths to Pdfs to Work With
$files2 = Get-ChildItem “c:\batchPrintPKs\split_pdfs_f\*.pdf”
# Print Each File to the Epson
foreach ($file2 in $files2){
$arglist1='/t "{0}" "{1}"' -f $file2, $printername_Brother
Start-Process $adobe $arglist1
sleep(2)
# Removing File
Remove-Item $file2
}
# Epson
# Create List of Paths to Pdfs to Work With
$files3 = Get-ChildItem “c:\batchPrintPKs\split_pdfs_l\*.pdf”
# Print Each File to the Epson
foreach ($file3 in $files3){
$arglist2='/t "{0}" "{1}"' -f $file3, $printername_Epson
Start-Process $adobe $arglist2
sleep(2)
# Removing File
Remove-Item $file3
}
Start-Sleep
-s 3? - Scotty Hpdftk ... input_pw password ...
。 - Jacob Colvin