使用“Microsoft print to PDF”编程打印为PDF;在c# Windows 10中
本文关键字:PDF Windows 编程 Microsoft print to 使用 打印 | 更新日期: 2023-09-27 17:53:58
我试图在c#中使用"Microsoft print to pdf "打印到pdf。我非常努力地编写了下面的代码:
它正在创建一个空的pdf文件,而不是用我发送给打印机的内容填充它。
有人能帮我吗?
try
{
PrintDocument pd = new PrintDocument();
ProcessStartInfo info = new ProcessStartInfo("E:''ba''Asp.pdf");
info.Verb = "Print";
pd.PrinterSettings.PrintToFile = true;
pd.PrinterSettings.PrinterName = "Microsoft Print to PDF";
pd.PrinterSettings.PrintToFile = true;
pd.PrinterSettings.PrintFileName = Path.Combine("e://", "hktespri" + ".pdf");
pd.Print();
info.CreateNoWindow = true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
您没有给出要打印到PDF文档的内容。这是我的代码,我用它来让面板打印
protected void btnPrint_Click(object sender, EventArgs e)
{
PrintDialog pd = new PrintDialog();
PrintDocument pdoc = new PrintDocument();
pdoc.PrintPage += pdoc_PrintPage;
if (pd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
pdoc.Print();
}
}
void pdoc_PrintPage(object sender, PrintPageEventArgs e)
{
Bitmap bitmap = new Bitmap(outerPanel.Width, outerPanel.Height);
outerPanel.DrawToBitmap(bitmap, new System.Drawing.Rectangle(5, 5, outerPanel.Width, outerPanel.Height));
e.Graphics.DrawImage(bitmap, 5, 5);
bitmap.Dispose();
}