在Windows窗体中使用代码打印PDF文件 [英] Print PDF File With Code In Windows Forms

查看:58
本文介绍了在Windows窗体中使用代码打印PDF文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的我觉得我找到了一个很好的解决方案,可以使用苏门答腊PDF [... a href =http://www.sumatrapdfreader.org/free-pdf-reader.htmltarget =_ blanktitle =New Window> ^ ]

远比Acrobat Reader解决方案更好,因为它没有打开任何窗口,它可以与应用程序启动路径一起提供,因为它有便携版本。





Ok I think I found good solution to print PDF Files On Fly by using Sumatra PDF[^]
It's far more better than Acrobat Reader Solution since it don't open any window and it can be shipped with application startup path since there is portable version of it.


static void Main()
        {
            ProcessStartInfo startInfo = new ProcessStartInfo();
            startInfo.FileName = "SumatraPDF.exe";
            string args = string.Format("-print-to-default \"{0}\" -exit-when-done", "xx.pdf");
            startInfo.Arguments = args;
            startInfo.CreateNoWindow = true;
            startInfo.ErrorDialog = false;
            startInfo.UseShellExecute = false;
            Process process = Process.Start(startInfo); Console.WriteLine("Start Print.");
            //process.Exited += process_Exited;
        Recheck:
            if (!process.HasExited)
            {
                Console.WriteLine("Wait 1 Sec.");
                process.WaitForExit(1000);
                goto Recheck;
            }
            else
            {
                Console.WriteLine("Print Finish.");
                Console.ReadLine();
            }
        Console.ReadLine();
}





我唯一担心的是Goto这就是为什么我在实施之前要求别人的意见我的项目。



注意事项#1:我非常关心性能和内存,我担心如果过程没有因为某些原因而没有回应它可能会让我的应用程序挂起等待直到完成,只能解决这个问题可以解决这个问题,可以计算过去几秒钟,如果(秒> 30),我会杀死这个过程。



注意事项#2:我将主要在循环中使用此代码来打印大约10个或更多的PDF文件,每个文件可以包含多个页面进行打印。



这样就够了吗?或者有更好的方法吗?



谢谢。

Tor。



the only thing worry me here is "Goto" that's why I ask for others opinion before I implement it into my project.

Note #1: I care so much for performance and memory and I'm afraid of if the process gone Not Responding for some reason it may make my application hang waiting it till finish, Only work around I can think about that can solve this is to count how many seconds past and if(sec>30) for example I kill the process.

Notes #2: I will use this code mainly in loop to print multiply PDF files about 10 or more and every file can contain more than 1 page to print.

So is this good enough? or is there better way ?

Thanks.
Tor.

推荐答案

While (!process.HasExited) {
    Console.WriteLine("Wait 1 Sec.");
    process.WaitForExit(1000);
}
Console.WriteLine("Print Finish.");
Console.ReadLine();





祝你好运。



Good luck.


这篇关于在Windows窗体中使用代码打印PDF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆