473,505 Members | 13,982 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 7070
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,...
1
4380
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....
1
6320
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...
11
3490
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...
9
2295
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...
0
5766
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...
10
3657
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...
6
3312
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...
34
5297
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...
1
2422
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...
0
7216
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,...
0
7367
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...
0
7471
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5613
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,...
1
5028
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...
0
3187
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1528
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 ...
1
754
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
407
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...

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.