I´m working in a very important project and I need to find out as fast as it´s possible how to do this. Please, anybody there send me something. I can´t buy the very expensive PDFRRasterizer lib from tallcomponent.

Thanks.

I will really apreciate a lot if you can tell me something usefull about it.
I´ll read the documentation you sent.

Tks.

I plan on trying this in the next week.

http://itextsharp.sourceforge.net/

FREE pdf generator for .net

can anyone help me to print pdf files in c#
If we use process we have to wait for some minutes.so is there any way print it directly without thread.sleep and waitforexit

You could thread off the PDF creation and so your UI doesnt "wait" for minutes.. and have an event for it to call at the end with success/fail

u can print pdf files using this code .................

using System.Diagnostics;
using System.Drawing.Printing;
using System.Runtime.InteropServices;
using System.IO;
using System.Text;
Process proc = new Process();


proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.StartInfo.Verb = "print";


string pdfFileName = "sampletemplate.pdf";



proc.StartInfo.FileName = @"C:\Program Files\Adobe\Acrobat 7.0\Reader\AcroRd32.exe";
proc.StartInfo.Arguments = @"/p /h C:\sample1.pdf";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;


proc.Start();
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
if (proc.HasExited == false)
{
proc.WaitForExit(10000);
//proc.Kill();
}


proc.EnableRaisingEvents = true;
//  AcroRd32.exe
proc.CloseMainWindow();
proc.Close();

:)

Edited 3 Years Ago by happygeek: fixed formatting

Thanks for quick reply

plz see below code that i am using to print

using System.Diagnostics;
using System.Drawing.Printing;
using System.Runtime.InteropServices;
using System.IO;
using System.Text;
Process proc = new Process();

proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.StartInfo.Verb = "print";

string pdfFileName = "sampletemplate.pdf";


proc.StartInfo.FileName = @"C:\Program Files\Adobe\Acrobat 7.0\Reader\AcroRd32.exe";
proc.StartInfo.Arguments = @"/p /h C:\sample1.pdf";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;

proc.Start();
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
if (proc.HasExited == false)
{
proc.WaitForExit(10000);
//proc.Kill();
}

proc.EnableRaisingEvents = true;
// AcroRd32.exe
proc.CloseMainWindow();
proc.Close();

plz explain ur point...

If you threaded off that code, your app itself would not "wait" just that thread.

proc.WaitForExit(10000);
if we do not use waitforexit and print some big pdf it will give error, as it takes some time and process will be exited

u mean to say like this??
if (!proc.HasExited)
{
proc.Refresh();
Thread.Sleep(2000);
}

no, create a thread in your code, to do the whole PDF printing part. Your app then doesnt hang in any shape or form, and it can wait as long as it likes. And finally when its done, and either succeeded or failed, your thread can report back wether or not it failed. But your app can do other things, and in fact do more than 1 at a go.

i am not familiar with threading so can u help me ..
how 2 work with it..

here is my code

plz tell me how i can use threads here

Process proc = new Process();

proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.StartInfo.Verb = "print";

string pdfFileName = "sampletemplate.pdf";


proc.StartInfo.FileName = @"C:\Program Files\Adobe\Acrobat 7.0\Reader\AcroRd32.exe";
proc.StartInfo.Arguments = @"/p /h C:\sample1.pdf";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;

proc.Start();
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
if (proc.HasExited == false)
{
proc.WaitForExit(10000);
//proc.Kill();
}

proc.EnableRaisingEvents = true;
// AcroRd32.exe
proc.CloseMainWindow();
proc.Close();

Hi, Use foxit reader , its a free no acrobat dependency, simple standalone executable file. no installation required

 public void TestPrintPDF()
        {
            //http://www.foxitsoftware.com/downloads/index.php
            // if you dont have a real physical printer use this printer and share it on your machine as network printer, set the printer configuration so that it will automatically print to a given location
            //http://www.bullzip.com/products/pdf/info.php
            //Foxit reader is there in the \bin\debug and you are having a pdf file at c:\My Test123.pdf
            string ExternalpdfParser = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "Foxit reader.exe");
            string param = string.Format(@"-t ""{0}"" {1}", @"c:\My Test123.pdf", @"\\HomeServer\BullzipP");
            using (System.Diagnostics.Process proc = System.Diagnostics.Process.Start(ExternalpdfParser, param))
            {
                //proc.WaitForExit((int)TimeSpan.FromSeconds(2).TotalMilliseconds);
            }
        }

Edited 3 Years Ago by mike_2000_17: Fixed formatting

Comments
Don't bump old threads

There is article i hope this will help you. it use open source PDF Sharp.

<URL SNIPPED>

Edited 6 Years Ago by peter_budo: Keep It Spam-Free - Do not mention, plug or refer to any product, service, or website you are affiliated with

Hi, use this as a template, this shouldn't work yet because I couldn't test it with a printer, but you have the threadding part:

delegate string GoPrint();
Process proc = new Process();


        private void button1_Click(object sender, EventArgs e)
        {
            GoPrint print = new GoPrint(Print);
            AsyncCallback callback = new AsyncCallback(PrintCallback);
            print.BeginInvoke(callback, print);
        }

        private void PrintCallback(IAsyncResult ar)
        {
            string result = ( (GoPrint)( ar.AsyncState ) ).EndInvoke(ar);
            MessageBox.Show(result);
        }

        private string Print()
        {
            proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            proc.StartInfo.Verb = "print";

            proc.StartInfo.FileName = @"F:\Program Files\Adobe\Reader 8.0\Reader\AcroRd32.exe";
            proc.StartInfo.Arguments = @"/p /h F:\sample.pdf";
            proc.StartInfo.UseShellExecute = false;
            proc.StartInfo.CreateNoWindow = true;

            proc.Start();
            proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            if ( proc.HasExited == false )
            {
                //proc.WaitForExit(10000);
                proc.EnableRaisingEvents = true;
                // AcroRd32.exe
                proc.CloseMainWindow();
                proc.Close();              
            }
            return "Printing";
        }

Good luck!

This article has been dead for over six months. Start a new discussion instead.