Hello ,
I need code for print and preview of a pdf file using c#.. ca anyone help me out ??
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
sravanthi varikoti27 reputationPosted Aug 11, 2015, 2:31 AM EDT
Yashwanth MuthineniRank #1,736 · 870 reputationPosted Aug 11, 2015, 9:22 PM EDT
Upendra Pratap ShahiRank #329 · 7.5K reputationPosted Aug 11, 2015, 9:50 PM EDT
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 NamespaceYashwanth MuthineniRank #1,736 · 870 reputationPosted Aug 11, 2015, 10:55 PM EDT
Upendra Pratap ShahiRank #329 · 7.5K reputationPosted Aug 11, 2015, 11:10 PM EDT
Upendra Pratap ShahiRank #329 · 7.5K reputationPosted Aug 12, 2015, 3:10 AM EDT
Yashwanth MuthineniRank #1,736 · 870 reputationPosted Aug 12, 2015, 4:07 AM EDT
Upendra Pratap ShahiRank #329 · 7.5K reputationPosted Aug 12, 2015, 4:10 AM EDT
Yashwanth MuthineniRank #1,736 · 870 reputationPosted Aug 12, 2015, 4:12 AM EDT