2012-08-09 77 views
0

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

当我打开应用程序时,它仅打开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; 

    } 
} 

}

+0

我想你应该检查这个线程。他/她得到与你的问题相同http://stackoverflow.com/questions/5566186/print-pdf-in-c-sharp – 2012-08-09 03:37:02

+0

我遵循圣诞老人给出的答案 [link] http:// stackoverflow。 com/questions/5566186/print-pdf-in-c-sharp 但它不起作用 – 2012-08-09 03:41:05

回答

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();