2014-01-24 94 views
0

我有一個要求打印一堆現有的PDF文件的每天的網絡理光MP 4000打印機。我需要使用「HoldPrint」作業類型選項來打印這些文件。我可以直接打印,但我希望它做一個不會與其他用戶打印混淆的保留打印。我使用GhostScript的9.10 直接打印(通過函數調用從 「馬切伊」 的帖子)的一個:批量打印使用的Ghostscript理光MP 4000打印機的PDF文件的Adobe沒有

「-dPrinted -dBATCH -dNOPAUSE -dNOSAFER -qQUIET -sjobtype = holdprint -suserid = ABC -dNumCopies = 1 -sDEVICE = ljet4 -sOutputFile = \「\\ spool \ PrinterName \」\「C:\ Printing \ mypdffile.pdf \」「

看起來我覆蓋jobtype開關,但不知道如何得到它。

我嘗試不同的組合,但它根本不起作用。任何幫助是極大的讚賞。

-dPrinted -dBATCH -dNOPAUSE -dNumCopies = 1 -sDEVICE = ljet4 -sOutputFile =%打印機%PRINTERNAME 「C:\打印\ mypdffile.pdf」

更新:這裏是爲我工作的版本。

 /* 
     * Printer used: Ricoh Aficio MP 4000 
     * Purpose: To print PDF files as a scheduled job to a network printer. 
     * The files will be queued under a specific user id. 
     * The user prints the files under his account. 
     * Pre-requisite: Install the network printer on the job server 
     * Manually configure Printer Job settings with user id 
     * and Job type set to "Hold Print" 
     */ 
     string _sourceFolder = 「PDFFilesFolderPath」; 
     DirectoryInfo di = new DirectoryInfo(_sourceFolder); 
     var files = di.GetFiles().OrderBy(f => f.Name); 
     string _printer = "BMIS"; // Printer name as seen in the Devices and Printers section 
     foreach (var f in files) 
     { 
      PrintPDF(@"C:\Program Files\gs\gs9.10\bin\gswin32c.exe", 1, _printer, f.FullName); 
     } 


    /// <summary> 
    /// Print PDF. 
    /// </summary> 
    /// <param name="ghostScriptPath">The ghost script path. Eg "C:\Program Files\gs\gs9.10\bin\gswin32c.exee"</param> 
    /// <param name="numberOfCopies">The number of copies.</param> 
    /// <param name="printerName">Exact name of the printer as seen under Devices and Printers.</param> 
    /// <param name="pdfFileName">Name of the PDF file.</param> 
    /// <returns></returns> 

    public bool PrintPDF(string ghostScriptPath, int numberOfCopies, string printerName, string pdfFullFileName) 
    { 

     try 
     { 
      ProcessStartInfo startInfo = new ProcessStartInfo(); 
      startInfo.Arguments = " -dPrinted -dNoCancel=true -dBATCH -dNOPAUSE -dNOSAFER -q -dNumCopies=" + Convert.ToString(numberOfCopies) + " -sDEVICE=mswinpr2 -sOutputFile=%printer%" + printerName + " \"" + pdfFullFileName + "\""; 

      startInfo.FileName = ghostScriptPath; 
      startInfo.UseShellExecute = false; 
      startInfo.WindowStyle = ProcessWindowStyle.Hidden; 
      Process process = Process.Start(startInfo); 
      process.WaitForExit(30000); 
      if (process.HasExited == false) process.Kill(); 
      return process.ExitCode == 0; 
     } 
     catch (Exception ex) 
     { 
      System.Diagnostics.EventLog.WriteEntry("Application", ex.Message, EventLogEntryType.Error); 
      throw; 
     } 
    } 

回答

0

Ghostscript沒有「jobtype」開關,也沒有suserid開關,所以毫不奇怪他們沒有效果。也許你引用的帖子有一些更多的信息,但我找不到任何這樣的帖子,也許你可以指向它(URL)

[稍後]

Setup.ps必須是PostScript文件(因爲這就是Ghostscript所能理解的,它是一個PostScript解釋器)。從您要設置DocumentName(它是用戶設置字典的成員)的文檔中,輸入以下內容:

mark 
    /UserSettings << 
     /DocumentName (My name goes in here) 
    >> 
    (mswinpr2) finddevice 
    putdeviceprops 
setdevice 

白色空間僅用於說明。這個例子幾乎可以逐字解除。

所以,你需要修改「setup.ps」您爲每個作業發送。您可以爲每個設置自定義setup.ps,或者使用GS的PostScript輸入功能,並使用-c和-f開關在命令行上提供setup.ps的全部內容。在運行自己的PostScript程序(假設您將setup.ps放在命令行上的PostScript程序之前)之前,所有setup.ps都會在那裏運行PostScript。

這是非常討厭的實際,它不是設備的方式通常配置,但mswinpr2裝置最初是由別人寫的Ghostscript的團隊之外,想必通過批發。

+0

謝謝你肯。我發現部分解決方案。 「-dPrinted -dBATCH -dNOPAUSE -dNOSAFER -q -dNumCopies =」 + Convert.ToString(numberOfCopies)+ 「-sDEVICE = mswinpr2 -sOutputFile =%打印機%」 + PRINTERNAME + 「\」 「+ pdfFullFileName + 」\「」;唯一的一點是我通過它的配置選項卡直接在打印機上控制作業類型屬性。現在我遇到的問題是,打印隊列中的所有作業都被命名爲Ghost腳本文檔。尋找動態發送文檔名稱。迄今沒有成功。從gs網站,它完成使用setup.ps文件,但不知道我們如何發送每個docname! –

+0

這裏是我最初是指一篇:HTTP://stackoverflow.com/questions/2599925/how-to-print-pdf-on-default-network-printer-using-ghostscript-gswin32c-exe-she RQ = 1 –

+0

我不太確定我是否理解你的問題,不管它是什麼,聽起來都不像Ghostscript。如果你自己控制打印機,那麼這個工作名稱肯定是由你決定的?如果您參考您正在閱讀的Ghostscript文檔(文檔以HTML文件形式提供,您不需要使用該網站),也可能有所幫助。 – KenS