[英]Drawing and Printing complex document in C# (improving/replacing my PrintDocument)
[英]PrintDocument is printing filename string instead of document in c#
我正在我的 asp.net 项目中实现PrintDocument
,其中我需要打印文档的特定页面,但不是打印文档,而是打印正在打印的“fileName”字符串。 下面是我的代码
string fileName = "C:\\DocToPrint\\Sample2018.pdf";
protected void Page_Load(object sender, EventArgs e)
{
using (PrintDocument pd = new PrintDocument())
{
pd.PrinterSettings.FromPage = 1;
pd.PrinterSettings.ToPage = 1;
pd.PrinterSettings.PrintRange = PrintRange.SomePages;
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
pd.Print();
}
public void pd_PrintPage(object sender, PrintPageEventArgs ev)
{
ev.Graphics.DrawString(fileName, new Font("Arial", 10), Brushes.Black,
ev.MarginBounds.Left, 0, new StringFormat());
}
}
这里错过了什么? 请建议..谢谢
有一个名为 Spire.Pdf 的 nuget 包,使用起来非常简单。 免费版本有 10 页的限制,但是,在我的情况下,当我不想依赖 Adobe Reader 并且不想安装任何其他组件时,它是最好的解决方案。
https://www.nuget.org/packages/Spire.PDF/
PdfDocument pdfdocument = new PdfDocument();
pdfdocument.LoadFromFile(pdfPathAndFileName);
pdfdocument.PrinterName = "My Printer";
pdfdocument.PrintDocument.PrinterSettings.Copies = 1;
pdfdocument.PrintFromPage = index;
pdfdocument.PrintToPage = index;
pdfdocument.PrintDocument.Print();
pdfdocument.Dispose();
打印某些页面的示例。
https://www.e-iceblue.com/forum/print-one-page-from-pdf-t6586.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.