0

我正在制作一个用于打印 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;

    }
}

}

4

1 回答 1

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();
于 2013-04-10T05:44:52.630 回答