I try to open the Adobe Acrobat Reader and then jump to a bookmark. But it doesn't work with the following code:
System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
myProcess.StartInfo.FileName = "acrord32.exe";
myProcess.StartInfo.Arguments = "/A \"nameddest=S2\" C:\\temp\\xxx.pdf";
myProcess.Start();
How can I do this? - Important: I have to use the Acrobat Reader not Acrobat.
When I use page=2 as a parameter it works. But not with the nameddest.
When I open the pdf, I see S2 as a bookmark in the second page.
Bookmarks and named destinations are not the same thing. You will have to create a destination in your PDF. If the rest of your code is correct, that should solve your problem.
Related
I tried using the code below, using PrintDocument, etc.. but can't get it to work.
Every time I run the Code below it opens a window asking me to select a printer. Using PrintDocument always led to empty pages, but the docs got printed.
How can I print Word documents without opening any windows?
foreach (string doc in dirFiles)
{
ProcessStartInfo info = new ProcessStartInfo();
info.Verb = "print";
info.FileName = doc;
info.Arguments = SelectedDrucker; //Printername
info.CreateNoWindow = true;
Process.Start(info);
}
Only the Word application can correctly print a Word document as it interprets the content/layout as it's sent to the printer. You first need to open the document in the Word application, then use its PrintOut method.
(This is also what Windows does when a user right-clicks a Word file and selects "Print".)
So there's no way to print a document without opening a window. You can, however, minimize the Word document window once it's been opened.
I have a PDF printed from C# with this code:
ProcessStartInfo info = new ProcessStartInfo();
info.Verb = "printto";
info.FileName = segnToPrint;
info.CreateNoWindow = true;
info.WindowStyle = ProcessWindowStyle.Hidden;
info.Arguments = "\""+ stmp+ "\"";
Process p = new Process();
p.StartInfo = info;
p.Start();
p.EnableRaisingEvents = true;
p.WaitForInputIdle();
System.Threading.Thread.Sleep(1000);
// Close Acrobat regardless of version
if (p != null)
{
p.WaitForInputIdle();
p.CloseMainWindow();
}
stmp is the address of the printer. The print works fine and it's perfect but i see the windows of Acrobat Reader any time that i call this function and the page of Acrobat Reader remains open after the last file printed.
How can i hidden all the process to the user?
If you are looking to hide some window then you may try move its window left and top position outside the screen using SetWindowPos function (see C# code here).
But please be aware of user interactions as user could be confused by the program running in the taskbar but not available on desktop.
Unfortunately (as you have found) acrobat reader will always open a window. If you wish to silently print without ever seeing acrobat then the only approach would be to use something other than acrobat reader. Two possible options are to use another PDF reader like FoxIt or to try to send your PDF directly to the printer in raw form, getting round the need for 3rd party applications all-together.
I am writing an app which performs some tests and produces a number of different reports. These may be any combination of Labels, PDF for end customer, PDF for repair department, XML file etc.
Depending on the report type, I need to send the file to either the file system or to one of a number of different printers (A4, label etc). Ideally there should be no popup windows - just straight to paper.
How can I send a file (PDF, XML) to a printer? I had thought that for XML/Text I could just File.Copy to LPTn but that doesn't seem to work. For PDF I'm guessing that I could call Acrobat with some parameters which cause the PDF to be printed.
The printers I use are mapped to LPTn. Is there a better way to do this and to store the definitions in the app? i.e. Labels go to MyLabelPrinter and A4 PDFs got to MyA4Printer.
Has anyone done this?
ProcessStartInfo info = new ProcessStartInfo("[path to your file]");
info.Verb = "PrintTo";
info.Arguments = "\"[printer name]\"";
info.CreateNoWindow = true;
info.WindowStyle = ProcessWindowStyle.Hidden;
Process.Start(info);
Take a look at this webpage. You should find the info you are looking at for PDF.
For example, it will look like that:
ProcessStartInfo infoOnProcess = new ProcessStartInfo("C:/example.pdf");
info.Verb = "PrintTo";
//Put a if there, if you want to change printer depending to file extension
info.Arguments = "\"HP-example-Printer\"";
info.CreateNoWindow = true;
info.WindowStyle = ProcessWindowStyle.Hidden;
Process.Start(infoOnProcess);
I just want to open a pdf file and not to use it. If the user wants to be able to print via a glider. I want to just pressing a button will open the file if Acrobat Reader to view
To open the PDF, try using the following code with the PDF's filename as the command.
string command=#"c:\Users\User\Desktop\hello.pdf";
var process = new System.Diagnostics.Process
{
StartInfo =
new System.Diagnostics.ProcessStartInfo(command)
};
process.Start();
Visual Basic CODE:
Dim FilePath As String = "<YourFilePath>" & "<YourFileName>" & ".pdf"
Dim Process As System.Diagnostics.Process = New System.Diagnostics.Process
Process.StartInfo.FileName = FilePath
Process.Start()
Every time the relative pdf file will show on a separate window
Obviously you MUST HAVE Adobe Reader INSTALLED on the CLIENT PC
It works pefectly. Used in Visual Studio 2010.
Printing pdf document with Microsoft XPS Document Writer:
string filename = "C:\\1.pdf";
Process process = new Process();
process.StartInfo.Verb = "PrintTo";
process.StartInfo.FileName = #"C:\Program Files\Adobe\Reader 9.0\Reader\acrord32.exe";
process.StartInfo.Arguments =
"/t \"C:\\1.pdf\" \"Microsoft XPS Document Writer\" \"xps\" XPSPort:";
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.UseShellExecute = false;
process.Start();
process.StandardOutput.ReadToEnd();
process.WaitForExit();
The only problem is Save Dialog, which requests file name (*.xps) where to save result. Everbody advices DOCINFO to solve this problem, but I didn't find any example of using.
I need programatically print PDF File via Microsoft XPS Document Writer with default output file name. How should I use DOCINFO in this situation?
Can you help me?
You can't reliably print by spawning Acrobat Reader unless you give it a desktop session and there will be a user there, because it sometimes pops up dialogs that need user attention.
Also it violates Adobe's licence if used unattended.
You can, however print using Ghostscript.
There is a C# interface to Ghostscript called Ghostscript.Net that I've used successfully on some very large projects. Both Ghostscript and Ghostcript.Net are free & open source.