Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 用C在Asp.Net中打印_C#_Asp.net - Fatal编程技术网

C# 用C在Asp.Net中打印

C# 用C在Asp.Net中打印,c#,asp.net,C#,Asp.net,最近,我在一个项目教育管理系统中工作,该系统使用C.net在Windows应用程序上运行,我使用打印文档控件打印标记表布局,并且运行良好。。但我必须在Asp.net网站上进行转换,以便任何打印标记页布局的打印方法都与打印文档的质量相同,并且标记页的内容从数据库中获取。 任何有助于用C、Java脚本打印的代码。任何与打印相关的代码,但由于标记页打印,打印质量是必需的 我有它的窗口应用程序相关的代码,但我想要基于Web的解决方案 private void printDocument2_PrintPa

最近,我在一个项目教育管理系统中工作,该系统使用C.net在Windows应用程序上运行,我使用打印文档控件打印标记表布局,并且运行良好。。但我必须在Asp.net网站上进行转换,以便任何打印标记页布局的打印方法都与打印文档的质量相同,并且标记页的内容从数据库中获取。 任何有助于用C、Java脚本打印的代码。任何与打印相关的代码,但由于标记页打印,打印质量是必需的

我有它的窗口应用程序相关的代码,但我想要基于Web的解决方案

private void printDocument2_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
    {
        e.Graphics.DrawRectangle(Pens.Black, rectangleShape1.Location.X, rectangleShape1.Location.Y, rectangleShape1.Width, rectangleShape1.Height);
        //////////////////////////////
        e.Graphics.DrawString(label24.Text, label24.Font, Brushes.DarkBlue, label24.Location.X, label24.Location.Y);
        e.Graphics.DrawString(label25.Text, label25.Font, Brushes.DarkBlue, label25.Location.X, label25.Location.Y);
        e.Graphics.DrawString(label26.Text, label26.Font, Brushes.Brown, label26.Location.X, label26.Location.Y);
        e.Graphics.DrawString(label27.Text, label27.Font, Brushes.Black , label27.Location.X, label27.Location.Y);
        e.Graphics.DrawString(label28.Text, label28.Font, Brushes.Black, label28.Location.X, label28.Location.Y);
        e.Graphics.DrawString(label29.Text, label29.Font, Brushes.Black, label29.Location.X, label29.Location.Y);
        e.Graphics.DrawString(label30.Text, label30.Font, Brushes.Black, label30.Location.X, label30.Location.Y);
        e.Graphics.DrawString(label31.Text, label31.Font, Brushes.Black, label31.Location.X, label31.Location.Y);
         ////////////////////////////
        e.Graphics.DrawString(txtRollno.Text, txtRollno.Font, Brushes.Black, txtRollno.Location.X, txtRollno.Location.Y);
        e.Graphics.DrawString(txtName.Text, txtName.Font, Brushes.Black, txtName.Location.X, txtName.Location.Y);
        e.Graphics.DrawString(txtfathernameid.Text, txtfathernameid.Font, Brushes.Black, txtfathernameid.Location.X, txtfathernameid.Location.Y);
        e.Graphics.DrawString(txtAddress.Text, txtAddress.Font, Brushes.Black, txtAddress.Location.X, txtAddress.Location.Y);
        e.Graphics.DrawString(txtContact.Text, txtContact.Font, Brushes.Black, txtContact.Location.X, txtContact.Location.Y);
    ////////////////
        e.Graphics.DrawImage(pictureBox1.Image, pictureBox1.Location.X, pictureBox1.Location.Y, pictureBox1.Width, pictureBox1.Height);
    }


 private void btnPrintPreview2_Click(object sender, EventArgs e)
    {
        printPreviewDialog1.Document = printDocument2;
        printPreviewDialog1.Show Dialog();
    }

ASP.Net中没有像Windows版的.Net中那样可用的控件。一种可能的方法是首先将报告/文档呈现为PDF/Word或XLS格式,然后打印。有很多开源项目可以动态创建PDF/XLS文件。我最喜欢的是,最近在PDFsharp库的基础上,他们添加了MigraDoc库,这对创建PDF文档和打印文档非常有帮助。

要使用javascript打印页面,请使用:

window.print();

谢谢你的回复,但是我听着,我们也可以通过java脚本打印HTML页面,所以任何用于打印的java scrip代码都可以打印HTML。是的,您可以打印HTML,非常简单,只需调用window.print。为了获得更好的效果,您可能需要为打印媒体创建一个单独的css样式表。