日期:2014-05-18  浏览次数:20366 次

打印
如何利用asp.net打印类似增值税发票的文档.
要求:
利用针式打印机
纸张大小可以自定义
各项内容位置固定
可以连打

谁能给个建议啊


------解决方案--------------------
activex或winform等富客户端
------解决方案--------------------
NET 打印 入门2008-06-11 17:07using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Drawing.Printing;
namespace ExcelPrj
{
public partial class Test : Form
{
/// <summary>
/// .NET 框架提供了相关的类实现文档的打印功能,这些类在 System.Drawing.Printing 命名空间内.为了实现打印功能,通常首先需要建立PringDocument 类的实例化对象,PrintDocument 类用于设置打印文档的属性和方法
/// 调用PringDocument类的 Print 方法后,会间接调用打印控制器类的方法,这些方法包括 OnStartPrint, OnEndPring,OnStartPage,OnEndPage,由这些方法来完成把文档内容输出到打印机的工作
/// 在打印之前,还可以选择用于输出的打印机.在.NET 框架中,PringDialog 类可以实现打印机设置对话框,在此对话框中可以选择输出的打印机,打印方法,和文档分数
/// 与 PrintPreviewDialog 类类似, PrintDialog 也是间接调用打印控制器的相关方法实现打印输出的阿功能
/// .NET 框架还提供了 PringPreviewDialog 类实现打印预览的功能.PringviewDialog 在屏幕上显示通用的打印预览窗口,窗口中 的内容是通过 Pringdocument 类间接调用打印控制器的方法,显示在屏幕上.
/// </summary>
public Test()
{
InitializeComponent();
}
private void Test_Load(object sender, EventArgs e)
{
DataSet ds = Bind();
this.dataGridView1.DataSource = ds.Tables[0];
}
private DataSet Bind()
{
SqlConnection conn = new SqlConnection("Server=.;Database=testManage;Integrated Security=SSPI");
SqlDataAdapter da = new SqlDataAdapter("select FNumber,FExamNum,FName,FSex,FJobAdd,FCardID,FBirDate from stuInfo", conn);
DataSet ds = new DataSet();
da.Fill(ds);
return ds;
}
/// <summary>
/// [1] 编写打印逻辑步骤
/// 将 PringPreviewDialog1 的Document属性设置为 PringDocument1.当PringPreviewDialog1对象执行ShowDialog方法之后,会触发PringDocument1对象的 PringPage 事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
{
this.pageSetupDialog1.Document = this.printDocument1;

Font objFont = new Font("Tahoma", 11, FontStyle.Regular);
Brush objBrush = Brushes.Black;
Pen objPen = new Pen(objBrush);

objPen.Width = 2;

//象打印预览窗口添加内容
int nLeft = this.pageSetupDialog1.PageSettings.Margins.Left;
int nTop = this.pageSetupDialog1.PageSettings.Margins.Top;
int nWidth=this.pageSetupDialog1.PageSettings.PaperSize.Width-(this.pageSetupDialog1.PageSettings.Margins.Left+this.pageSetupDialog1.PageSettings.Margins.Right);
int nHeight=this.pageSetupDialog1.PageSettings.PaperSize.Height-(this.pageSetupDialog1.PageSettings.Margins.Top+this.pageSetupDialog1.PageSettings.Margins.Bottom);

//画出页面的有效区域
e.Graphics.DrawLine(objPen, nLeft, nTop, nLeft + nWidth, nTop);
e.Graphics.DrawLine(objPen, nLeft, nTop + nHeight, nLeft + nWidth,nTop+nHeight);
e.Graphics.DrawLine(objPen, nLeft, nTop, nLeft, nTop+nHeight);
e.Graphics.DrawLine(objPen, nLeft + nWidth, nTop, nLeft + nWidth, nTop + nHeight);

// 打印表头
e.Graphics.DrawString("学号", new Font("Garamond", 20, FontStyle.Regular), Brushes.Blue, nLeft + 30, nTop + 10);
e.Graphics.DrawString("姓名", new Font("Garamond", 20, FontSt