web打印发票! 求助!

fgh0302 2010-04-12 01:04:28
发票 不是那种用专用纸的,只要自己拼好 格式 直接打印就可以!

主要功能就是 点击一个按钮事件
{
拼好样式+填充数据
打印!
}

主要是不想出现打印设置==一些东西,点击按钮 打印机直接就打印
...全文
2828 40 打赏 收藏 转发到动态 举报
写回复
用AI写文章
40 条回复
切换为时间正序
请发表友善的回复…
发表回复
dong0738 2011-12-13
  • 打赏
  • 举报
回复
我用过一个免费的Web打印控件可以很方便的实现此功能,该控件的演示地址:http://www.xinyuerj.com/ASP.NET/
笑傲IT 2011-07-19
  • 打赏
  • 举报
回复
http://www.fcsoft.com.cn/webprint.htm可以参考一下
fgh0302 2010-04-13
  • 打赏
  • 举报
回复
呵呵 。net 这么强大应该没难倒的问题 大家一起进步
S314324153 2010-04-13
  • 打赏
  • 举报
回复
WEB打印,失败者泪流满面的经过
YnSky 2010-04-13
  • 打赏
  • 举报
回复
帮顶!!!!!!!!!!!!!!!!!
fgh0302 2010-04-13
  • 打赏
  • 举报
回复
[Quote=引用 33 楼 itliyi 的回复:]
下载一个工具直接用就可以了
[/Quote]
这个我不知道你们怎么要求的,我们公司宗旨是不能给客户增加负担,麻烦!


itliyi 2010-04-13
  • 打赏
  • 举报
回复
下载一个工具直接用就可以了
xrongzhen 2010-04-13
  • 打赏
  • 举报
回复
学习。。。。
hangang7403 2010-04-13
  • 打赏
  • 举报
回复
这个应该简单,说说思路:
1 用一个html 做模板 格式就是要打印的格式
2 写一个函数把数据装入 上面的模版中
3 把装入数据的模板 装入用户页面 这里直接用label 装入就可以,就是说把模板直接装入用户界面的label中
4 在用户界面用js 函数 直接调用web 打印函数就可以了
fgh0302 2010-04-13
  • 打赏
  • 举报
回复
。。。。。。。。。。。。。。。。。。。
fgh0302 2010-04-12
  • 打赏
  • 举报
回复
阿泰 我这也是同事 从网上找的再根据自己情况改的 道理也不是很懂

你要有时间给大家讲解下1
fgh0302 2010-04-12
  • 打赏
  • 举报
回复
e 感谢 大家帮忙,我目前自己写了一个 测试好像没什么问题 贴上来大家参考下!

default.aspx.cs

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
using System.Windows.Forms;
using System.Drawing.Printing;
using System.Text;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//PrintDocument pd1 = new PrintDocument();
//System.Windows.Forms.Label lab = new System.Windows.Forms.Label();

//pd1.PrinterSettings.CanDuplex = true;
//pd1.PrinterSettings.
//pd1.Container.Add(lab,"label");
//lab.Text = "print test";
//pd1.Print();
int d=1000;
string aa = "1111111111111111111";
string b = "---------------------";
string c = "总价 "+d.ToString();
StringBuilder a = new StringBuilder();
a.Append(aa+"\r\n");
a.Append(b + "\r\n");
a.Append(c + "\r\n");
PrintService ps = new PrintService();

byte[] byteArray = Encoding.ASCII.GetBytes(a.ToString());
MemoryStream stream = new MemoryStream(byteArray);

ps.StartPrint(stream, "txt");

//FileStream fs=new FileStream("c:\\RHDSetup.log", FileMode.Open);
// StringBuilder d=new StringBuilder(fs);
//ps.StartPrint(new FileStream("c:\\RHDSetup.log", FileMode.Open), "txt");

}

}

PrintService.cs 代码如下
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Drawing.Printing;
using System.Windows.Forms;
using System.IO;
using System.Text;
/// <summary>
///PrintService 的摘要说明
/// </summary>
public class PrintService
{
public PrintService()
{
this.docToPrint.PrintPage += new PrintPageEventHandler(docToPrint_PrintPage);
}//将事件处理函数添加到PrintDocument的PrintPage中

// Declare the PrintDocument object.
private System.Drawing.Printing.PrintDocument docToPrint = new System.Drawing.Printing.PrintDocument();//创建一个PrintDocument的实例
private System.IO.Stream streamToPrint;
string streamType;

// This method will set properties on the PrintDialog object and
// then display the dialog.
public void StartPrint(Stream streamToPrint, string streamType)
{

this.streamToPrint = streamToPrint;
this.streamType = streamType;
// Allow the user to choose the page range he or she would
// like to print.
// System.Windows.Forms.PrintDialog PrintDialog1 = new PrintDialog();//创建一个PrintDialog的实例。
// PrintDialog1.AllowSomePages = true;

// Show the help button.
// PrintDialog1.ShowHelp = true;

// Set the Document property to the PrintDocument for
// which the PrintPage Event has been handled. To display the
// dialog, either this property or the PrinterSettings property
// must be set
//PrintDialog1.Document = docToPrint;//把PrintDialog的Document属性设为上面配置好的PrintDocument的实例

//DialogResult result = PrintDialog1.ShowDialog();//调用PrintDialog的ShowDialog函数显示打印对话框

// If the result is OK then print the document.
//if (result == DialogResult.OK)
//{
docToPrint.Print();//开始打印
//}

}

// The PrintDialog will print the document
// by handling the document's PrintPage event.
private void docToPrint_PrintPage(object sender,
System.Drawing.Printing.PrintPageEventArgs e)//设置打印机开始打印的事件处理函数
{

// Insert code to render the page here.
// This code will be called when the control is drawn.

// The following code will render a simple
// message on the printed document
switch (this.streamType)
{
case "txt":
string text = null;
System.Drawing.Font printFont = new System.Drawing.Font
("Arial", 12, System.Drawing.FontStyle.Regular);

// Draw the content.
System.IO.StreamReader streamReader = new StreamReader(this.streamToPrint);
text = streamReader.ReadToEnd();
e.Graphics.DrawString(text, printFont, System.Drawing.Brushes.Black, e.MarginBounds.X, e.MarginBounds.Y);
break;
case "image":
System.Drawing.Image image = System.Drawing.Image.FromStream(this.streamToPrint);
int x = e.MarginBounds.X;
int y = e.MarginBounds.Y;
int width = image.Width;
int height = image.Height;
if ((width / e.MarginBounds.Width) > (height / e.MarginBounds.Height))
{
width = e.MarginBounds.Width;
height = image.Height * e.MarginBounds.Width / image.Width;
}
else
{
height = e.MarginBounds.Height;
width = image.Width * e.MarginBounds.Height / image.Height;
}
System.Drawing.Rectangle destRect = new System.Drawing.Rectangle(x, y, width, height);
e.Graphics.DrawImage(image, destRect, 0, 0, image.Width, image.Height, System.Drawing.GraphicsUnit.Pixel);
break;
default:
break;
}

}
}

浏览就会直接打印 大家可以测试下 讨论下 希望不再有这种问题出项在asp.net版
阿泰 2010-04-12
  • 打赏
  • 举报
回复
如果可以的话,可以用水晶报表试试。
可以从服务器端发起打印任务
gdlpc 2010-04-12
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 wosizy 的回复:]
web打印插件FAZU
http://bbs.siteserver.cn/showtopic-16336.html
免费web打印控件
http://www.91aion.com/soft/40459.htm
[/Quote]是否真正免费
phf0313 2010-04-12
  • 打赏
  • 举报
回复
免费打印控件
fgh0302 2010-04-12
  • 打赏
  • 举报
回复
继续等待 太短太短
flyerwing 2010-04-12
  • 打赏
  • 举报
回复
调试好后直接打印了。
设置不设置不都是一样的了
fgh0302 2010-04-12
  • 打赏
  • 举报
回复
[Quote=引用 20 楼 wosizy 的回复:]
你要怎么从服务器端打印?

根据服务器端定义的打印格式从客户端直接控制打印机打印出需要的报表

http://kb.cnblogs.com/a/732742/
[/Quote]

我想法就是 前面前辈提供的都要弹出那个选择打印机的框

我不想它出现,我后台 拼好格式 打印机直接打印出来就可以 没有页眉 页脚 也没什么按钮需要隐藏的问题
wosizy 2010-04-12
  • 打赏
  • 举报
回复
你要怎么从服务器端打印?

根据服务器端定义的打印格式从客户端直接控制打印机打印出需要的报表

http://kb.cnblogs.com/a/732742/
加载更多回复(19)

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧