簡體   English   中英

使用Foxit Reader和C#打印PDF文件

[英]Print PDF file using Foxit Reader and C#

在新的過程中,我的程序通過PDF閱讀器Foxit Reader進行靜默打印。

有時,我的程序嘗試同時打印兩個PDF,這導致其中一個無法打印。

這是我的代碼:

string filename = "file.pdf";

string fileDir1 = @"C:\Program Files (x86)\Foxit Software\Foxit Reader\FoxitReader.exe";

Process pdfProcess = new Process();
pdfProcess.StartInfo.FileName = fileDir1;
pdfProcess.StartInfo.Arguments = string.Format(@"/t {0} {1}", filename ,"pos-80");
pdfProcess.StartInfo.CreateNoWindow = true;
pdfProcess.StartInfo.WorkingDirectory = Path.GetDirectoryName(fileDir1);
pdfProcess.Start();

if (!pdfProcess.WaitForExit(2500))
{
    pdfProcess.Kill();

}

請幫助我解決此問題。

確保已打開Foxit。

using System.Diagnostics;

List<Process> Processlist = Process.GetProcesses().ToList();

這為您提供了當前正在運行的進程的列表。

foreach(Process p in Processlist)
{
    Console.WriteLine("Process " + p.Id + " is named '" + p.ProcessName + "'");

}

運行上面的代碼時,您應該在輸出窗口中看到Foxit進程的名稱。

或者,在foreach行上放置一個斷點,並將鼠標懸停在列表上以該方式查看所有名稱。

bool IsFoxitProcessRunning = false;

foreach(Process p in Processlist)
{
    if(p.ProcessName == "Foxit process name here") //Replace with the name of the foxit process
    {
        IsFoxitProcessRunning  = true;

    }

}

現在,如果尚未運行新的Foxit進程,則僅啟動該進程。

if(!IsFoxitProcessRunning)
{
    //insert code to run next foxit process here.

}

筆記:

  • 您可能需要實現一個隊列,以跟蹤等待運行的pdf。

  • 如果Foxit等待5或10分鍾以上運行,您可能還希望提醒IT支持。

  • 您可以選擇使Processlist成為類屬性,並使用Timer通過調用Processlist = Process.GetProcesses().ToList();來定期刷新Processlist Processlist = Process.GetProcesses().ToList(); 在Tick事件中。 PDF等待打印時每30秒左右。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM