I had wrote a code to print a pdf with C#. It's work but it's open me the window of Adobe Reader and i don't want it.
Here is my code :
filename = "Doc1.pdf";
ProcessStartInfo psInfo = new ProcessStartInfo();
psInfo.FileName = #"C:\Program Files\Adobe\Reader 11.0\Reader\AcroRd32.exe";
psInfo.Arguments = String.Format("/n /s /o /h /p{0}", filename);
psInfo.CreateNoWindow = true;
psInfo.UseShellExecute = true;
psInfo.WindowStyle = ProcessWindowStyle.Hidden;
Process process = Process.Start(psInfo);
It's show me for 1 or 2 seconds the pdf at adobe reader and then show me the adore reader window without any pdf on it. I don't want to show anything. Just to print the pdf.
ProcessStartInfo psi = new ProcessStartInfo();
psi.UseShellExecute = true;
psi.Verb = "print";
psi.WindowStyle = ProcessWindowStyle.Hidden;
psi.FileName = path + "/Invoice" + print + ".pdf";
Process.Start(psi);
Related
I want to open a pdf file with Adobe Reader. I used this code shown here, but it doesn't open it. I do see the Adobe Acrobt Reader in the proccess list in Task Manager, but it does not show the window with my PDF file:
ProcessStartInfo startInfo = new ProcessStartInfo(AdobPath);
startInfo.UseShellExecute = true;
startInfo.CreateNoWindow = false; ;
startInfo.Arguments = string.Format("/A \"page={0}\" \"{1}\"", pn, PdfPath);
Process process = new Process();
process.StartInfo = startInfo;
process.Start();
if (process.HasExited == false)
process.WaitForExit(10000);
process.Close();
System.Diagnostics.Process process1;
process1= new System.Diagnostics.Process();
process1.EnableRaisingEvents = false;
string strCmdLine;
strCmdLine = "/k " +textBox3.Text;
System.Diagnostics.Process.Start("CMD.exe",strCmdLine);
This will run a command on cmd ..
Want to save that CMD command text on text file..
Using this for save but not working..
ProcessStartInfo PSI = new ProcessStartInfo();
PSI.FileName = "c:\\WINDOWS\\System32\\cmd.exe";
PSI.RedirectStandardInput = true;
PSI.RedirectStandardOutput = true;
PSI.RedirectStandardError = true;
PSI.UseShellExecute = false;
Process p = Process.Start(PSI);
string output = p.StandardOutput.ReadToEnd();
StreamWriter st = new StreamWriter(#"C:\test.txt");
st.Write(output);
st.Close();
Try this
using System.Diagnostics;
Process.Start("cmd", "/k " + textBox3.Text + #" > C:\test.txt");
Also, read Embedding a Console in a C# Application - CodeProject
I am installing cab file of my application using wceload.exe. When my application already exists it gives message "My application is already installed.Reinstall?" How to avoid this message? Cab file installation launches when I use
ProcessStartInfo info = new ProcessStartInfo();
info.FileName = #"\windows\wceload.exe";
info.Arguments = "\\My_Installer.cab";
Process proc = new Process();
proc.StartInfo = info;
proc.Start();
proc.WaitForExit();
When I use
info.Arguments = "\\My_Installer.cab /silent";
or
info.Arguments = "/noaskdest /noui \\My_Installer.cab";
nothing happens. What am I doing wrong?
Here is complete solution, if it will be necessary for somebody:
ProcessStartInfo info = new ProcessStartInfo();
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
Process proc = new Process();
// uninstalls application
doc.LoadXml("<wap-provisioningdoc>" +
"<characteristic type=\"UnInstall\">" +
"<characteristic type=\"MyManufactuer MyApplication\">"+
"<parm name=\"uninstall\" value=\"1\"/>" +
"</characteristic>" +
"</characteristic>" +
"</wap-provisioningdoc>");
Microsoft.WindowsMobile.Configuration.ConfigurationManager.ProcessConfiguration(doc, false);
// installs application
info.FileName = #"\windows\wceload.exe";
info.Arguments = #"\My_Installer.cab";
// start the process
proc.StartInfo = info;
proc.Start();
proc.WaitForExit();
I tried to print a pdf file from my windows service.It didnt work.Later i wrote a console app to print a pdf file.Console app did work!.Afterwords i i called that console app from service to print pdf file it didn'work. Why is that "print" doesnt work with windows service? following are the code snippets i tried
1.Used adobe reader:
PdfReportGeneration.Log logs = new PdfReportGeneration.Log();
logs.writeLog("PrintDocument filepath:-" + filepath);
Process process = new Process();
process.StartInfo.FileName = filepath;
process.StartInfo.UseShellExecute = true;
process.StartInfo.Verb = "printTo";
process.StartInfo.Arguments = "HP LaserJet P1005";
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process.Start();
process.WaitForInputIdle();
process.Kill();
2. Used foxit reader/adobe reader both didnt work
string sArgs = " /t \"" + filepath + "\" \"" + "HP LaserJet P1005" + "\"";
System.Diagnostics.ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = #"C:\Program Files\Foxit Software\Foxit Reader\Foxit Reader.exe";
startInfo.Verb = "printTo";
startInfo.Arguments = sArgs;
startInfo.CreateNoWindow = true;
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
System.Diagnostics.Process proc = Process.Start(startInfo);
proc.WaitForExit(100000); // Wait a maximum of 10 sec for the process to finish
if (!proc.HasExited)
{
proc.Kill();
proc.Dispose();
// return false;
}*/
Done a lots of google bing yahoo.. no use!!
Service is usually run by different account. I would try to run service as user. Could be a problem that system user doesn't have mapped that printer. Service install class would look like this:
[RunInstaller(true)]
public class ServiceInstall : Installer
{
public ServiceInstall()
{
ServiceInstaller serviceInstaller = new ServiceInstaller();
ServiceProcessInstaller serviceProcessInstaller = new ServiceProcessInstaller();
serviceProcessInstaller.Account = ServiceAccount.User;
serviceProcessInstaller.Username = "User";
serviceProcessInstaller.Password = "Password";
serviceInstaller.DisplayName = "Some Service";
serviceInstaller.StartType = ServiceStartMode.Automatic;
serviceInstaller.ServiceName = "Some Service";
this.Installers.Add(serviceProcessInstaller);
this.Installers.Add(serviceInstaller);
}
}
somehow, with Adobe Acrobat X, PdfFilePrinter cannot prevent Adobe from silently printing PDF pages.
here's my code:
PdfFilePrinter.AdobeReaderPath = PDFExecPath;
var printer = new PdfFilePrinter(this.documentPath, this.printer);
printer.Print();
here's the PdfSharp's source:
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = PdfFilePrinter.adobeReaderPath;
string args = String.Format("/t \"{0}\" \"{1}\"", this.pdfFileName, this.printerName);
//Debug.WriteLine(args);
startInfo.Arguments = args;
startInfo.CreateNoWindow = true;
startInfo.ErrorDialog = false;
startInfo.UseShellExecute = false;
if (this.workingDirectory != null && this.workingDirectory.Length != 0)
startInfo.WorkingDirectory = this.workingDirectory;
solved:
PdfFilePrinter.AdobeReaderPath = PDFExecPath;
var printer = new PdfFilePrinter(this.documentPath, this.printer);
printer.Print(1000);
The Print(int milliseconds) overload kills the adobe acrobat program.