用C#打印PDF

时间:2012-08-09 03:32:58

标签: c# pdf printing

我正在制作用于打印PDF的C#Windows应用程序。

当我打开应用程序时,它只打开Acrobat Reader窗口而不再打印。在Print()的功能中有什么我错过的吗?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using Microsoft.Win32;


namespace PrintDocumentsApplication
   {
public partial class PrintForm : Form
{
    public PrintForm()
    {
        InitializeComponent();
    }

    private void printPdfButton_Click(object sender, EventArgs e)
    {
        String File = @"C:\Documents and Settings\larasasasrylo\Desktop\QRCODE_DEMO\test.pdf";
        String Printer = "\\vhssadasdasoftaweafs\\HP Color LaserJet 5550 PCL 6";
            Print(File, Printer);
    }

    public static bool Print(string file, string printer)
    {
        try
        {

            Process.Start(
               Registry.LocalMachine.OpenSubKey(
                    @"SOFTWARE\Microsoft\Windows\CurrentVersion" +
                    @"\App Paths\AcroRd32.exe").GetValue("").ToString(),
               string.Format("/h /t \"{0}\" \"{1}\"", file, printer));

            return true;

        }
        catch { }
        return false;

    }
}

}

1 个答案:

答案 0 :(得分:2)

你试试这个

Process process = new Process();

process.StartInfo.FileName = pathToPdfOrDocFile; 
process.UseShellExecute = true;
process.StartInfo.Verb = "printto";
process.StartInfo.Arguments = "\"" + printerName + "\""; 
process.Start();

process.WaitForInputIdle();
process.Kill();