使用 Acrobat 插件打印多个 PDF (axAcroPDF1)

发布于 2024-07-30 18:01:34 字数 646 浏览 5 评论 0原文

我有一个 Windows 应用程序,我想将列表框中的 PDF 列表发送到打印机。 单步执行下面的代码,我可以看到 *axAcroPDF1.LoadFile(s) 正在加载应用程序中的每个文件,但 Acrobat 似乎只将 lbPDFList 列表框中的最后一项打印到打印机(例如,如果有 4 个 PDF 需要打印)打印,它总是只打印最后一个 PDF)?

 int iListCounter = lbPDFList.Items.Count;
                for (int i=0; i < iListCounter; i++)
                {
                    String s = null;
                    lbPDFList.SetSelected(i,true);
                    s = lbPDFList.SelectedItem.ToString();
                    axAcroPDF1.LoadFile(s);
                    axAcroPDF1.Show();
                    axAcroPDF1.printAllFit(true);
                }

这是线程问题吗?

I've got a windows app where I want to send to printer a list of PDF's in a listbox.
Stepping through the code below, I can see that *axAcroPDF1.LoadFile(s) is loading each file in my application, but Acrobat only seems to print the last item in the lbPDFList listbox to the printer (eg. if there is 4 PDF's to print, it will always only print the last PDF)?

 int iListCounter = lbPDFList.Items.Count;
                for (int i=0; i < iListCounter; i++)
                {
                    String s = null;
                    lbPDFList.SetSelected(i,true);
                    s = lbPDFList.SelectedItem.ToString();
                    axAcroPDF1.LoadFile(s);
                    axAcroPDF1.Show();
                    axAcroPDF1.printAllFit(true);
                }

Is this a threading issue?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

愿得七秒忆 2024-08-06 18:01:34

答案很简单! 忽略 axAcroPDF 对象,仅使用 Windows 打印功能进行打印(在循环中使用下面的代码来打印每个 PDF):

 // start a new cmd process
        Process objP = new Process();
        objP.StartInfo.FileName = strFilePath;
        objP.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;         //Hide the window. 
    //!! Since the file name involves a nonexecutable file(.pdf file), including a verb to specify what action to take on the file. 
    //The action in our case is to "Print" a file in a selected printer.
    //!! Print the document in the printer selected in the PrintDialog !!//
    objP.StartInfo.Verb = "printto";
    objP.StartInfo.Arguments = "/p /h \"" + strFilePath + "\" \"" + pd.PrinterSettings.PrinterName + " \"";//pd.PrinterSettings.PrinterName;
    objP.StartInfo.CreateNoWindow = true;   //!! Don't create a Window. 
    objP.Start();                           //!! Start the process !!// 
    objP.CloseMainWindow();

The answer was simple! Ignore the axAcroPDF object and just print using the windows print function (use the code below inside a loop to print each PDF):

 // start a new cmd process
        Process objP = new Process();
        objP.StartInfo.FileName = strFilePath;
        objP.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;         //Hide the window. 
    //!! Since the file name involves a nonexecutable file(.pdf file), including a verb to specify what action to take on the file. 
    //The action in our case is to "Print" a file in a selected printer.
    //!! Print the document in the printer selected in the PrintDialog !!//
    objP.StartInfo.Verb = "printto";
    objP.StartInfo.Arguments = "/p /h \"" + strFilePath + "\" \"" + pd.PrinterSettings.PrinterName + " \"";//pd.PrinterSettings.PrinterName;
    objP.StartInfo.CreateNoWindow = true;   //!! Don't create a Window. 
    objP.Start();                           //!! Start the process !!// 
    objP.CloseMainWindow();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文