0

I am making a C# Windows application for printing a PDF.

When I open the application, it only opens the Acrobat Reader window and no more printing. Is there anything I have missed in the function of 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;

    }
}

}

Adam Lear
  • 38,111
  • 12
  • 81
  • 101
Jeff Bootsholz
  • 2,971
  • 15
  • 70
  • 141
  • I think you should check this thread. He/She get the same with your problem http://stackoverflow.com/questions/5566186/print-pdf-in-c-sharp – Hùng Lê Xuân Aug 09 '12 at 03:37
  • I have followed the answer given from santa in [link]http://stackoverflow.com/questions/5566186/print-pdf-in-c-sharp But it does not work – Jeff Bootsholz Aug 09 '12 at 03:41

1 Answers1

2

you try this

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();
sreeju kp
  • 143
  • 9