我想要使用c#从网页打印标准大小的信封。有谁知道如何做这样的事情?我会从系统加载地址的数据并传递给它。我只需要这样做的基本步骤。从网站打印信封?
Q
从网站打印信封?
1
A
回答
2
我确实最终用PDF格式。我们使用PDFSharp,这是一个免费的PDF创作者工具。我使用此处的函数即时创建PDF,然后在页面上,我只是将此页面作为新窗口加载。这是我最终为任何想要做类似事情的人创建的方法。
protected void DisplayPDFEnvelope()
{
try
{
PdfDocument document = new PdfDocument();
PdfPage pdfpage = new PdfPage();
XUnit pdfWidth = new XUnit(4.125, XGraphicsUnit.Inch);
XUnit pdfHeight = new XUnit(9.5, XGraphicsUnit.Inch);
pdfpage.Height = pdfHeight;
pdfpage.Width = pdfWidth;
pdfpage.Orientation = PageOrientation.Landscape;
XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always);
document.AddPage(pdfpage);
// Create a font
XFont font = new XFont("ARIAL", 1, XFontStyle.Regular, options);
// Get an XGraphics object for drawing beneath the existing content
XGraphics gfx = XGraphics.FromPdfPage(pdfpage, XGraphicsPdfPageOptions.Append);
// This method just returns a formatted address from the DB using \n to
// do line breaks, i.e. 'Test Person\nAddress Line1\City, State Zip'
string address = GetAddress();
// Get the size (in point) of the text
XSize size = gfx.MeasureString(address, font);
// Create a graphical path
XGraphicsPath path = new XGraphicsPath();
path.AddString(address, font.FontFamily, XFontStyle.Regular, 10,
new XPoint(345, 160), XStringFormats.Default);
// Create a dimmed pen and brush
XPen pen = new XPen(XColor.FromGrayScale(0), 0); // XColor.FromArgb(50, 75, 0, 130), 3);
XBrush brush = new XSolidBrush(); // XColor.FromArgb(50, 106, 90, 205));
// Stroke the outline of the path
gfx.DrawPath(pen, brush, path);
MemoryStream stream = new MemoryStream();
document.Save(stream, false);
Page.Response.Clear();
Page.Response.ContentType = "application/pdf";
Page.Response.AppendHeader("Content-Length", stream.Length.ToString());
Page.Response.AppendHeader("Content-Type", "application/pdf");
Page.Response.AppendHeader("Content-Disposition", "inline;filename=envelope.pdf");
Page.Response.BinaryWrite(stream.ToArray());
Page.Response.Flush();
stream.Close();
HttpContext.Current.ApplicationInstance.CompleteRequest();
}
catch (Exception ex)
{
throw ex;
}
}
0
你将不得不使用的ActiveX这样做。
这可能有助于 http://www.sharewareconnection.com/print-preview-activex-control.htm
1
理论上你可以使用CSS http://www.w3.org/TR/css-print/做到这一点。取决于你需要支持多少浏览器,它可能是一个很大的痛苦,因为它们的工作方式稍有不同。
你很可能与页面大小和方向的一些问题为您的用户或许我的许多歧打印机。从flash,pdf或silverlight 3打印可能是简单的路线。
+0
对PDF的+1,尽管CSS *可能能够做到这一点 - PDF是明显的第一选择。 – 2009-05-01 23:14:24
0
您可以从this site打印信封。
它增加了条形码和一切。从网络打印。
相关问题
- 1. 从perl网站打印头
- 2. .net从网站打印?
- 3. 从网站自动打印PDF
- 4. 如何打印从ASPX.net网站Visual Basic
- 5. 网站打印和flash
- 6. 打印OSC网站的URL
- 7. 从网站/网络应用程序打印到标签打印机?
- 8. 收据打印机 - 从网页打印
- 9. 从ASP.NET打印到网络打印机
- 10. rake db:在我的网站上打印的种子信息
- 11. 在控制台打印一个网站的信息
- 12. 从打印网站隐藏元(网址,页面标题,页码)
- 13. 使打印机打印出网站背景
- 14. 从网站存储信息
- 15. 从网站阅读信息
- 16. 从网站提取信息
- 17. 无法在网站上打印内容
- 18. 可能的网站打印自定义?
- 19. 显示PDF用于网站打印
- 20. 如何强制网站打印
- 21. 网站:使用脚注打印版本?
- 22. 在网站上打印图像
- 23. 从网上打印几步
- 24. 从网站打开文件
- 25. 从UITabBarController打开网站
- 26. 从Windows打印服务器轮询打印机信息
- 27. 打印版,试图打印信息
- 28. 只打印5使用抓取链接的循环从网站
- 29. 无法从ASP.NET网站加载客户端打印控件?
- 30. 从网站打印多个自定义的用户文档
在服务器或客户端? – 2009-05-01 23:01:42