如何添加asp.net打印对话框 [英] How to add asp.net print dialog box
问题描述
我有一个打印按钮,并且我的Web应用程序调用了一个打印对话框并打印文件.当我在Visual Studio中调试代码时,打印功能效果很好.但是,在发布Web应用程序的那一刻,当我尝试打印时它会引发服务器错误.任何帮助将不胜感激.
错误:
当应用程序不在UserInteractive模式下运行时,显示模式对话框或窗体是无效操作.指定ServiceNotification或DefaultDesktopOnly样式以显示来自服务应用程序的通知.
我的代码是:
I have a print button and my web application that calls a print dialog box up and prints a file. When I debug the code in Visual Studio the print functionality works great. However, the minute I publish the web application it throws a server error when I try to print. Any help would be greatly appreciated.
The error:
Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application.
My code is:
PrintDialog myPrintDialog = new PrintDialog();
ImageCollection imgCol = new ImageCollection(Page.MapPath(imgViewer.ImageUrl), null);
AnnotationController annCon = new AnnotationController();
foreach (LayerAnnotation layAnn in imgViewer.Annotations.Layers)
{
annCon.Layers.Add(layAnn);
}
AnnotatePrintDocument myAnnotatePrintDocument = new AnnotatePrintDocument(annCon, imgCol);
myAnnotatePrintDocument.ScaleMode = PrintScaleMode.FitToMargins;
myAnnotatePrintDocument.Center = true;
myAnnotatePrintDocument.Units = AnnotationUnit.Pixel;
myPrintDialog.Document = myAnnotatePrintDocument;
myPrintDialog.AllowSomePages = true;
myPrintDialog.AllowCurrentPage = true;
if (myPrintDialog.ShowDialog() == DialogResult.OK)
{
myAnnotatePrintDocument.Print();
}
推荐答案
使用javascript打印页面中存在的数据
就像
onclientclick ="javascript:window.print()"
use javascript to print data present in page
like
onclientclick="javascript:window.print()"
这不适用于网络.最快的打印方法是使用以下内容:
This doesn''t work on the web. The quickest way to print something is with something like:
<asp:button id="btnPrint" runat="server" text="Print" onclientclick="javascript:window.print();" xmlns:asp="#unknown" />
或使用类似 iTextSharp/ [ ^ ]使用您的输出创建PDF.
or use something like iTextSharp/[^] to create PDF with your output.
这篇关于如何添加asp.net打印对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!