Search code examples
c#asp.netpdfprintingitext

Can you print a pdf file using ITextSharp (c#) ? If yes how?


I have an ASPX page which builds a report. I have a print button which builds a pdf file using ITextSharp. Now I want to print that file.

I have two questions:

How do I print it with out even saving the file ?

and If I can't do this, can I at least print the saved file ?

Thanks in advance.


Solution

  • @Jared. Well what we did was to start the acrobat reader with printing parameters after we saved it on the file system. Something like:

       ProcessStartInfo newProcess = new ProcessStartInfo(pdfPath, dfArguments);
    
       newProcess.CreateNoWindow = true;
       newProcess.RedirectStandardOutput = true;
       newProcess.UseShellExecute = false;
    
       Process pdfProcess = new Process();
       pdfProcess.StartInfo = newProcess;
       pdfProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
       pdfProcess.Start();
       pdfProcess.WaitForExit();
    

    (please note this is not the actual code we used I got this from here) this should get you started.

    For initializing adobe acrobat with printing parameters see this.

    Hope it helps.