Open pdf file failed - c#

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();

Related

C# - Print a PDF Error (System.ComponentModel.Win32Exception:...)

I am trying to write an application to print PDFs.
Now I get an error message where I can't get any further after a long search.
The goal would be to print a PDF file without opening the PDF-Reader.
My Code:
using System.Diagnostics;
private void button1_Click(object sender, EventArgs e)
{
ProcessStartInfo info = new ProcessStartInfo();
info.Verb = "print";
info.FileName = #"C:\testFile.pdf";
info.CreateNoWindow = true;
info.WindowStyle = ProcessWindowStyle.Hidden;
Process p = new Process();
p.StartInfo = info;
p.Start();
p.WaitForInputIdle();
System.Threading.Thread.Sleep(3000);
if (false == p.CloseMainWindow())
p.Kill();
}
The error condition occurs at p.Start(); line.
Error message:
System.ComponentModel.Win32Exception: "The system cannot find the
specified file".
New experience: 20.01.2021
If I comment out info.Verb = "print";. Then the PDF is opened.
Is this a sign that it finds the PDF but has no access to printer?
use this code it works for me :
public static void PrintToASpecificPirnter()
{
using (PrintDialog printDialog = new PrintDialog())
{
if (printDialog.ShowDialog() == DialogResult.OK)
{
var StartInfo = new ProcessStartInfo();
StartInfo.CreateNoWindow = true;
StartInfo.UseShellExecute = true;
StartInfo.Verb = "printTo";
StartInfo.Arguments = "\"" + printDialog.PrinterSettings.PrinterName + "\"";
StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
StartInfo.FileName = fileName;
Process.Start(StartInfo);
}
}
}

System.ComponentModel.Win32Exception c#

This is my code:
string damnfile = System.IO.Path.GetDirectoryName(choofdlog.FileName);
ProcessStartInfo startInfo = new ProcessStartInfo("% ProgramFiles %\\Windows Defender\\MpCmdRun.exe");
startInfo.WindowStyle = ProcessWindowStyle.Maximized;
startInfo.Arguments = "-Scan -ScanType 3 -File" + damnfile;
Process p = new Process();
p.StartInfo = startInfo;
p.Start();
As you can see, I want to run WinDefender scan for a specific file, but it throws error that the process is not found, but this code works:
ProcessStartInfo startInfo = new ProcessStartInfo("netstat");
startInfo.WindowStyle = ProcessWindowStyle.Maximized;
startInfo.Arguments = "-a";
Process p = new Process();
p.StartInfo = startInfo;
p.Start();
Also I want in the second code to redirect the cmd output to listBox, but thats the second problem, first help me with the defender scan please.
Solveded like now its opening, because I replaced
ProcessStartInfo startInfo = new ProcessStartInfo("% ProgramFiles %\\Windows Defender\\MpCmdRun.exe");
with
ProcessStartInfo startInfo = new ProcessStartInfo(#"C:\Program Files\\Windows Defender\\MpCmdRun.exe");
Now appeared another problem: even I passed some arguments, the windows immediately close.

Printing PDF file with Custom Page size

How can I print PDF file without changing the page size? I use the code below but it changes the paper size.
ProcessStartInfo info = new ProcessStartInfo();
info.Verb = "print";
info.FileName = FilePath;
info.CreateNoWindow = true;
info.WindowStyle = ProcessWindowStyle.Hidden;
Process p = new Process();
p.StartInfo = info;
p.Start();
p.WaitForInputIdle();
System.Threading.Thread.Sleep(3000);
if (false == p.CloseMainWindow())
p.Kill();

How can i calculate percent end time when below .exe is running on ASP.NET C#

I want to press button and it should continue and display percent time when i click another page, code should on background. After that i click this page it display me results belong running .exe process.
How can i do that? I need your help.
ProcessStartInfo startInfo = new ProcessStartInfo();
Process p = new Process();
startInfo.CreateNoWindow = true;
startInfo.RedirectStandardOutput = true;
startInfo.UseShellExecute = false;
startInfo.Arguments = "/Scan http://localhost/deneme/sunucu.html /Profile web_applications /SaveToDatabase –ScanningMode=Heuristic –UseAcuSensor=TRUE –EnablePortScanning=TRUE";
startInfo.FileName = #"C:\\Program Files (x86)\\Acunetix\\Web Vulnerability Scanner 9.5\wvs_console.exe";
p.StartInfo = startInfo;
p.OutputDataReceived += (sender, args) => Console.WriteLine("received output: {0}", args.Data);
p.Start();
p.BeginOutputReadLine();
StreamReader output = p.StandardOutput //i tried beginoutputreadline
p.WaitForExit();
ListBox1.Items.Add(output.tostring());
Regards,

Print a pdf without pop up the AdobeReader window

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);

Categories