打印PDF而不显示它们但显示printdialog

时间:2014-07-24 00:17:45

标签: c# pdf printing itextsharp

点击打印按钮,我必须打印pdf文档。此外,我需要显示打印对话框,但不应向用户显示实际的pdf。并且根据所选的打印对话框属性,pdf应打印在用户选择的打印机中。

对于生成的pdf,我可以使用以下代码添加printdialog属性: -

  writer.SetOpenAction(new PdfAction(PdfAction.PRINTDIALOG));

但是当选择按钮时,我无法打印pdf。能否请你为我提供一些指导。

完整代码: - (PDF作为内存流传递到打印按钮视图)。

using (MemoryStream m1 = new MemoryStream())
{
    // MemoryStream m1 = new MemoryStream();
    Int32 i = 0;
    PdfWriter writer = PdfWriter.GetInstance(document, m1);
    document.Open();
    PdfContentByte content = writer.DirectContent;

    document.NewPage();

    PdfImportedPage page = writer.GetImportedPage(reader, i + 1);
    content.AddTemplate(page, 0, 0);
    writer.SetOpenAction(new PdfAction(PdfAction.PRINTDIALOG));
    document.Close();

    return m1;

}

1 个答案:

答案 0 :(得分:0)

您可以使用 Ghostscript 打印pdf文件。

如果您需要.NET的Ghostscript包装,您可以查看 Ghostscript.NET 库。

可以在此处找到通过Ghostscript.NET打印样本: https://ghostscriptnet.codeplex.com/discussions/470946

打印对话框是一个常见的对话框,您可以在此处找到有关如何从.NET显示打印对话框的更多信息: Show Print Dialog before printing