【问题标题】:Programmatically print to PDF using "Microsoft Print to PDF" in c# windows 10在 c# windows 10 中使用“Microsoft Print to PDF”以编程方式打印到 PDF
【发布时间】:2016-07-02 15:27:32
【问题描述】:

我正在尝试使用 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);

}

【问题讨论】:

  • PrintFileName 不是您提供的打印文件路径。它只是将出现在打印队列上的名称。
  • 您解决了这个问题吗?我有同样的问题
  • 嗨 Alpay,我的解决方案是更换“Microsoft Print to PDF”打印机并使用 itextsharp。我希望这会有所帮助。如果您仍有问题,请通过我的电子邮件与我联系:ropnak@gmail.com。

标签: c# pdf printing windows-10


【解决方案1】:

您还没有给出要打印到 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();
    }

【讨论】:

    猜你喜欢
    • 2017-07-04
    • 2016-04-23
    • 2015-11-01
    • 2011-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-14
    相关资源
    最近更新 更多