473,659 Members | 3,239 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Opening PDF files from C#

2 New Member
I was trying to use Process.Start to launch Adobe Reader and open a PDF file from a C# Windows Form applicatoin. I want the file to be opened at a specific page, so I tried:

Process.Start(" C:\\ABC.pdf", "/a Page=3");

This launches Adobe Reader and brings up the correct file, but it goes to Page 1, not Page 3.

I know that from a command line the following works:

AcroRd32.exe /a Page=3 C:\ABC.pdf

But this does not:

AcroRd32.exe C:\ABC.pdf /a Page=3

I am assuming that Process.Start is putting the arguments at the end of the command line and Reader is ignoring them.

Can anyone suggest a way to make this work? I am not married to using Process.Start, so any suggestions would be greatly appreciated.

Thanks,

DP
May 6 '08 #1
2 7111
Curtis Rutland
3,256 Recognized Expert Specialist
Try something like this:
Expand|Select|Wrap|Line Numbers
  1. string acro = @"C:\Program Files\Adobe\Reader 8.0\Reader\AcroRd32.exe";
  2. System.Diagnostics.ProcessStartInfo st = new System.Diagnostics.ProcessStartInfo(acro, "/a page=2 c:\\dev\\a.pdf");
  3. System.Diagnostics.Process p = new System.Diagnostics.Process();
  4. p.StartInfo = st;
  5. p.Start();
  6.  
Note that you will have to replace the location of the AcroRd32.exe with the path to the version currently installed on your machine.

This worked for me.

I was trying to use Process.Start to launch Adobe Reader and open a PDF file from a C# Windows Form applicatoin. I want the file to be opened at a specific page, so I tried:

Process.Start(" C:\\ABC.pdf", "/a Page=3");

This launches Adobe Reader and brings up the correct file, but it goes to Page 1, not Page 3.

I know that from a command line the following works:

AcroRd32.exe /a Page=3 C:\ABC.pdf

But this does not:

AcroRd32.exe C:\ABC.pdf /a Page=3

I am assuming that Process.Start is putting the arguments at the end of the command line and Reader is ignoring them.

Can anyone suggest a way to make this work? I am not married to using Process.Start, so any suggestions would be greatly appreciated.

Thanks,

DP
May 6 '08 #2
DPolley
2 New Member
Thanks for the suggestion, the problem is that the app (which will be run on many different machines) has no way of knowing what version of Reader (or some other program for reading PDFs) the machine has installed, or where it is installed.

Thanks,
DP

Try something like this:
Expand|Select|Wrap|Line Numbers
  1. string acro = @"C:\Program Files\Adobe\Reader 8.0\Reader\AcroRd32.exe";
  2. System.Diagnostics.ProcessStartInfo st = new System.Diagnostics.ProcessStartInfo(acro, "/a page=2 c:\\dev\\a.pdf");
  3. System.Diagnostics.Process p = new System.Diagnostics.Process();
  4. p.StartInfo = st;
  5. p.Start();
  6.  
Note that you will have to replace the location of the AcroRd32.exe with the path to the version currently installed on your machine.

This worked for me.
May 7 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
714
by: PM | last post by:
Has anyone found a way to open a file exclusively where it will fail if the file is already open, i have tried the following _FileStream = new FileStream(@"C:\Data.txt", FileMode.Open, FileAccess.ReadWrite, FileShare.None); which does not prevent me from opening the file even if another user has the file open ie Notepad, it will prevent me from saving the file in notepad until i close the file in the app. I can then save changes made in...
1
4393
by: Alfons | last post by:
Hello, I have build a program that can do file transferring between a Windows XP computer and a DOS computer via a serial port. The Windows program I have build in C++ with Visual Studio 6.0. The DOS program I made in Turbo C++ 3.0. At this moment I am in a test phase of sending files and directories. The code I am using in DOS to open a file for writing looks like this (forgive me the typos, since I only have my source code at work...
1
6325
by: sunil | last post by:
Hi all, I have a web application in which I have to open a "chm" file that exists on the local file system. I am able to open other files such as PDF, DOC files by writing the Response's output stream. But I do not exactly know the Response.ContentType for chm files. I have used the following code to handle the case for chm files System.IO.StreamReader sr = new System.IO.StreamReader(this.Path); FileInfo file = new FileInfo(this.Path);...
11
3517
by: emailus | last post by:
I am webmaster for the domain <www.alpha1.org.au>. Not being an expert in html, I take advantage of my domain Registrant's web building tool, 'Instant Website'. This tool is provided as part of the fee I pay for web hosting. 'Instant Website' provides the option of having your opening page as a Flash Page, which you'll see if you visit <www.alpha1.org.au>. Well, you'll see it if you visit from a Windows machine. For some reason, when...
9
2308
compman9902
by: compman9902 | last post by:
Hello, and thank toy for reading this post. Thus far, this website has helped me a lot, (I have finally finished my encryptor: "site removed by moderator", go to the downloads link) and I will continue asking for help (so my rank may finally increase). Right now the topic at hand for me is opening file dialogs. Right now, the issue at hand is opening up a fully functional G.U.I. file prompt (both for opening and saving files please) that has...
0
5788
by: Jeremy Noring | last post by:
Hi, I have an application that loads various settings from the app.exe.config file. This has worked very well on w2k, XP, and Vista. However, recently I've been troubleshooting an issue on Windows Home Server (which is based on some variation of Windows Server 2003) and I've found that ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel) is
10
3673
by: kimiraikkonen | last post by:
Hi, I have an app which has a listbox and when i double click an associated fileS, i want their paths to be added into listbox in my application. This code works good when i try to open a "single" file with my app which works to get commandline arguments to get file paths: Dim cla As String() = Environment.GetCommandLineArgs() If cla.Length 1 Then
6
3324
by: bushwacker | last post by:
Hello all, I'm a chemical engineering student. our teacher has given us a project to do some calculations based on some equations. those equations include constants, which are to be read from a file(I don't understand why?) i took an introductory course on c programming but the curriculum didn't include opening files, searching files and getting data from files. i made some searching through google and learned about opening and closing files,...
34
5337
by: Alexnb | last post by:
Gerhard Häring wrote: No, it didn't work, but it gave me some interesting feedback when I ran it in the shell. Heres what it told me: Traceback (most recent call last): File "<pyshell#10>", line 1, in <module> os.startfile("C:\Documents and Settings\Alex\My Documents\My
1
2429
navanova
by: navanova | last post by:
Greetings, I have a problem of opening ms word and excel files on my computer. The files are there for a long time. I use to open and modify them. Suddenly, when i try to open the word files, a dialog box appears that says "There was an error opening the file". when i try to open the excel files, a dialog box appears that says "File format not valid". I have tried to create a new word and excel files, save them and when i try to open these...
0
8428
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8335
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8747
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7356
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6179
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2752
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1737
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.