如何使用详细选项自动打印pdf?

Kur*_*ema 10 c# printing pdf powershell

这是我想要解决的场景.我工作的公司每天都要为学生打印多个pdf.每个pdf的最后一页必须用蓝纸打印.我们当前的流程是手动打印pdf并将除最后一页之外的所有页面发送到一台装有白纸的打印机,然后将最后一页发送到托盘中有蓝纸的另一台打印机.这是耗时且乏味的.我创建了一个PowerShell脚本,它将获取给定文件夹中的所有pdf,并首先将pdf分成两部分,第一部分是所有页面,但最后一页,第二页是最后一页.然后脚本将每个pdf发送到适当的打印机.

但是这些PDF是安全的,因此脚本不起作用.通常,它们会在打开Adobe Reader几秒钟后自动解密,但由于脚本会立即打印它们,因此没有时间进行解码.

我想知道:

  1. 有没有办法解决Powershell和.中的加密问题
  2. 此外,能够在自动打印时选择纸盘,以便仅使用一台打印机正确打印彩色页面.(这将是理想的,因为页面将保持有序.目前,我们没有带两个托盘的打印机,但随着公司扩展,我们肯定会.)

据我所知,我认为#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
    }
Run Code Online (Sandbox Code Playgroud)

小智 0

在这种情况下,您可以尝试使用一些第三方解决方案,例如Google Cloud Print或类似的