Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
2.60/5 (2 votes)
Is it possible to print stand alone html page without print dialog through c# activex.
i don't want to show print dialog i want to print html page silently.
if it is possible..... help me....
Posted
Updated 28-Nov-15 23:15pm
v3
Comments
Sinisa Hajnal 23-Nov-15 6:02am    
What are you trying to do? Question "Is it possible" is not good for Q&A...it is (very probably) possible, but there may be a better way.
[no name] 23-Nov-15 9:29am    
can you re frame your question with clearly
Krunal Rohit 29-Nov-15 6:14am    
Print-preview dialog is a browser feature, you can't just disable it.

-KR

1 solution

"i don't want to show print dialog i want to print html page silently."

I can't really think of any legitimate reason to do this.

c# activex.

You are a special kind of evil. haha.

Oh, here is what you are looking for i think.

C#
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PdfPrinter
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] files = Directory.GetFiles(@"c:\temp");
            foreach (string file in files.Where(
                        file => file.ToUpper().Contains(".PDF")))
            {
                 Pdf.PrintPDFs(file);
            } 
        }
    }//END Class

    public class Pdf
    {
        public static Boolean PrintPDFs(string pdfFileName)
        {
            try
            {
                Process proc = new Process();
                proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                proc.StartInfo.Verb = "print";

                //Define location of adobe reader/command line
                //switches to launch adobe in "print" mode
                proc.StartInfo.FileName = 
                  @"C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe";
                proc.StartInfo.Arguments = String.Format(@"/p /h {0}", pdfFileName);
                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;

                proc.Close();
                KillAdobe("AcroRd32");
                return true;
            }
            catch
            {
                return false;
            }
        }

        //For whatever reason, sometimes adobe likes to be a stage 5 clinger.
        //So here we kill it with fire.
        private static bool KillAdobe(string name)
        {
            foreach (Process clsProcess in Process.GetProcesses().Where(
                         clsProcess => clsProcess.ProcessName.StartsWith(name)))
            {
                 clsProcess.Kill();
                 return true;
            }
            return false;
        }
    }//END Class
}//END Namespace
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900