在C#中打印不带预览的pdf [英] Printing pdf without preview in c #

查看:132
本文介绍了在C#中打印不带预览的pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Windows应用程序中使用C#打印.pdf和.tif文件.

I am trying to print .pdf and .tif files using C# in windows application.

打印成功完成,但是我的问题是Adobe阅读器正在后台打开pdf文件,而Windows打印对话框打开了tif文件.

Printing is done successfully, but my problem is Adobe reader is opening in background for pdf files and windows print dialogue opens for tif files.

实际上,我将使用服务来运行我的方法,因此这些过程应以静默方式进行.我该怎么做才能避免这种情况?

Actually i will run my method using a service, so these process should occur silently. What can I do to avoid this?

这是我的代码

public void PrintDocument(string filepath)
        {

            //PrintDialog pd = new PrintDialog();            
            printProcess.StartInfo.FileName = filepath; 
            //Also tried usecellexcecution=false;
            //Redirect=true; something like this
            printProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            printProcess.StartInfo.Verb = "Print";
            printProcess.StartInfo.CreateNoWindow = true;
            PrinterSettings setting = new PrinterSettings();
            setting.DefaultPageSettings.Landscape = true; 
            printProcess.Start();
            printProcess.CloseMainWindow(); 
        }

我尝试使用MSDN中建议的RawprinterHelper,但它会打印垃圾字符.

I have tried to use RawprinterHelper suggested in MSDN, but it prints junk characters.

推荐答案

获取pdf流程的窗口句柄,然后将其隐藏或使用流程类的windowstyle将其最小化.

Get the window handle of the pdf process and then hide it or use process class's windowstyle to minimize it.

是的,因为您正在使用Process.Start,所以启动了它.

Yes it gets launched because you are using Process.Start.

这篇关于在C#中打印不带预览的pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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