简体   繁体   English

在asp.net C#中在客户端打印机上打印pdf文件?

[英]Printing a pdf file on client side printer in asp.net C#?

I have a problem in my project that i open a dynamically generated PDF file in popup window which working correctly. 我的项目中有一个问题,我在弹出窗口中打开一个动态生成的PDF文件,该文件正常工作。 But now i want to print that pdf directly when popup is open at client side printer, how can i solved it ?? 但是现在我想在客户端打印机打开popup时直接打印pdf,我该如何解决?

I need help of yours. 我需要你的帮助。 Please suggest me some code for this. 请为我推荐一些代码。

You need to open the popup with javascript and the fire the print() function on it. 您需要使用javascript打开弹出窗口并触发print()函数。

var opts = 'width=700,height=500,toolbar=0,menubar=0,location=1,status=1,scrollbars=1,resizable=1,left=0,top=0';
var newWindow = window.open(yourUrl,'name',opts);
newWindow.print();

Note that the url you open must be in the same domain as your current page for this to work. 请注意,您打开的网址必须与当前网页位于同一个网域才能生效。

Try This Code It will Work For You. 试试这个代码它会为你工作。

    Process printjob = new Process();

    printjob.StartInfo.FileName = @"D:\R&D\Changes to be made.pdf" //path of your file;

    printjob.StartInfo.Verb = "Print";

    printjob.StartInfo.CreateNoWindow = true;

    printjob.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;

    PrinterSettings setting = new PrinterSettings();

    setting.DefaultPageSettings.Landscape = true;

    printjob.Start();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM