打印PDF文档编程 [英] Print a PDF Document Programmatically

查看:160
本文介绍了打印PDF文档编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过编程打印PDF文档?

How can i Print a Pdf document through programmatically?

我现在用的follwing code打印PDF file.but当我打印图标直接点击它开始printing.but我不希望它。

i am using the follwing code to print a PDF file.but when i click on print icon directly it starts printing.but i dont want it.

 <asp:ImageButton ID="PrintButton" runat="server" ImageUrl="~/images/print-icon.png"
                   OnClick="PrintButton_Click" ToolTip="Print Document" />

我的铯code是

My Cs Code is

protected void PrintButton_Click(object sender, EventArgs e)
    {
        ProcessStartInfo infoPrint = new ProcessStartInfo();
        infoPrint.FileName = Session["filename"].ToString();
        infoPrint.Verb = "PrintTo";
        infoPrint.CreateNoWindow = true;
        infoPrint.WindowStyle = ProcessWindowStyle.Normal;
        infoPrint.UseShellExecute = true;
        Process printProcess = new Process();
        printProcess = Process.Start(infoPrint);            

    }      

我想开一个打印对话框,当用户点击打印icon.if在打印对话框中的打印按钮,用户点击,然后我要开始打印文档。我的PDF文件是我希望它通过编程在asp.net打印服务器上的文件夹中。

i want to open a print dialog box when the user clicks on print icon.if the user clicks on Print Button in Print dialog box then i want to start printing the document. My PDF file is in a folder on the server i want it to be printed through programmatically in asp.net.

推荐答案

这code将在服务器而不是客户端上运行。在开发服务器和客户端是同一台计算机,本地工作站。一旦部署完毕,这将在服务器上执行,而不是用户的本地工作站。

this code will run on the server not the client. while developing the server and client are the same machine, your local workstation. Once deployed, this would execute on the server, not the user's local work station.

您可以使用JavaScript打开打印对话框

you can open a print dialog box using javascript

window.print();

不过,将打印整个webapge,而不是专门的文件

However that will print the entire webapge, not the document specifically.

如果您想只打印PDF,需要流的文件浏览器(而不是整个网络表格)。然后,用户可以充分利用在Adobe Reader内在本地打印选项的优势。有许多例子网上有关如何将文档传输到客户端的浏览器。

If you would like to print only the PDF, you need to stream the file to browser (not an entire webform). The user can then take advantage of the native print options within the adobe reader. There are many examples online about how to stream documents to the client's browser.

这篇关于打印PDF文档编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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