I used this code to print a pdf file from acrobat reader.
private void SendToPrinter()
{
ProcessStartInfo info = new ProcessStartInfo();
info.Verb = "print";
info.FileName = #"c:\output.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();
}
However, it prints through default printer.
How can I select the printer to send it to? default.
I have tried with a property for ex: info.Arguments, but that doesn't work.
Use the /t command line argument to force adobe to use a specific printer:
AcroRd32.exe /t path "printername" "drivername" "portname"
See the PDF developer FAQ for more info:
http://partners.adobe.com/public/developer/en/acrobat/sdk/pdf/intro_to_sdk/DeveloperFAQ.pdf
How about using the "printto" verb? pasing "\\\server\printer" for info.Arguments
Related
I'm tring to make a program that saves a textbox text to a text file and prints the text file.
I found this code:
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(#"TempDocument.txt");
psi.Verb = "PRINT";
Process.Start(psi);
Here
But it doesn't open a dialog it's just printing.
I want to have a dialog in order to choose another printer or open in OneNote.
To show a printDialog, you can try :
However, I don't know which kind of project your talking about, so maybe this will not fit.
printDialog = new PrintDialog();
//when you click on OK
if (printDialog.ShowDialog() == DialogResult.OK)
{
//path is your documents to print location
ProcessStartInfo info = new ProcessStartInfo(path);
info.Arguments = "\"" + printDialog.PrinterSettings.PrinterName + "\"";
info.CreateNoWindow = true;
info.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
info.UseShellExecute = true;
info.Verb = "PrintTo";
System.Diagnostics.Process.Start(info);
}
I open a pdf file when my form is loaded with the following code:
Process process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
process.StartInfo = startInfo;
startInfo.FileName = #"F:\STAGE\test.pdf";
process.Start();
This works fine but now I want to open a specific page. For example page number 5 of the document test.pdf? Does any one have an idea? Tried some stuff but dind't work!
Thanks!
Try
process.StartInfo.Arguments = "/A \"page=n\" \"F:\\STAGE\\test.pdf"";
changing n to the page number you want
Checkout this : http://partners.adobe.com/public/developer/en/acrobat/PDFOpenParameters.pdf
It explain what arguments Adobe Reader can receive.
And it has a Page argument.
Your code must be :
Process process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
process.StartInfo = startInfo;
startInfo.Arguments = "/A \"page=N\"";
startInfo.FileName = #"F:\STAGE\test.pdf";
process.Start();
Where N is your page number.
call it like what was suggested here: Adobe Reader Command Line Reference
So it would be:
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "EXE_PATH\\AcroRd32.exe";
startInfo.Arguments = "/A \"page=PAGE_NUM\" \"FILE_PATH\"";
Process.Start(startInfo);
you can try this code.
Process myProcess = new Process();
myProcess.StartInfo.FileName = #"C:\Program Files\Adobe\Reader 11.0\Reader\AcroRd32.exe";
myProcess.StartInfo.Arguments = "/A \"page={pagenum}\" \"c:\\Classic\\Manual\\DocumentationManual.pdf\"";
myProcess.Start();
please change the path of AcroRd32.exe as per your directory.
Thanks
Try this.
Note: you must have acrobat reader installed in your pc before you can use axAcroPDF .
int n = 5; //page number
string filePath = "F:\STAGE\test.pdf";
axAcroPDF1.LoadFile(filePath);
axAcroPDF1.setCurrentPage(n);
I have made a Windows Form application and I want to print an existing PDF document with my default printer.
I have the file, stored in c:\users\marten\document.pdf.
I have searched a long time for some examples, but the only examples I found was printing a text file or printing a string into a document.
Can someone give me a good example or tutorial?
This uses the installed pdf reader to print the file against the default printer on the machine.
string path = "" <- your path here.
if (path.EndsWith(".pdf"))
{
if (File.Exists(path))
{
ProcessStartInfo info = new ProcessStartInfo();
info.Verb = "print";
info.FileName = path;
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();
}
}
Is it possible to redirect just stdin but also allow stdout to be written to the console?
I have a process which starts child processes and needs to read the output of those processes, but also display it in the console. Is it possible? I tried to just create my own console process but I can't write to it unless I UseShellExecute and the purpose is to show the output in the console.
protected void startp() {
Process p = new Process();
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = "cmd.exe";
psi.Arguments = "/k";
//Can't redirect output without UseShellExecute = false
psi.RedirectStandardInput = true;
psi.UseShellExecute = false;
psi.CreateNoWindow = false;
p.StartInfo = psi;
p.Start();
//Can't write to StandardInput with UseShellExecute = true
p.StandardInput.WriteLine("#ECHO OFF");
p.StandardInput.WriteLine("echo | set /p=Child Process");
Console.ReadLine();
p.StandardInput.WriteLine("exit");
}
currently I have a process that runs, but it requires the user to enter
y <return>
<return>
The code I am using is as follows
ProcessStartInfo psi = new ProcessStartInfo();
string exepath = Directory.GetParent(System.Reflection.Assembly.GetExecutingAssembly().Location).ToString();
Process proc = new Process();
psi.FileName = exepath + #"\lib\dnaml";
psi.RedirectStandardInput = true;
psi.Arguments = "y\r \r";
psi.UserShellExecute = true;
proc.StartInfo = psi;
proc.Start();
proc.WaitForExit();
I want to hard type these inputs in. Any suggestions? Thanks
The Arguments property corresponds to the command-line, not data entered via standard input.
The RedirectStandardInput property is part of the puzzle. Then you also need to write to the stream connected to the StandardInput property. Also note that standard input redirection is incompatible with ShellExecute, it needs CreateProcess to work. So set UseShellExecute = false.
psi.RedirectStandardInput = true;
psi.UseShellExecute = false;
proc.StartInfo = psi;
proc.Start();
proc.StandardInput.WriteLine("y ");
proc.StandardInput.WriteLine();
proc.WaitForExit();