通常指定Acrobat路径以在C#中打开pdf文件 [英] To specify the Acrobat path in general for opening a pdf file in C#

查看:171
本文介绍了通常指定Acrobat路径以在C#中打开pdf文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hiii

我有在C#的特定页面上打开pdf文件的解决方案.净

Hiii

I have got solution for opening a pdf file at the particular page in C#. Net

Process myProcess = new Process();
myProcess.StartInfo.FileName = @"C:\Program Files\Adobe\Reader 8.0\Reader\AcroRd32.exe";
myProcess.StartInfo.Arguments = "/A \"page=2\" \"D:\\Doc1.pdf\"";
myProcess.Start();



但是我还有一个问题,这将在我安装了AcroRd32.exe的本地计算机上正常运行,但是在不同的
但通常为 myProcess.StartInfo.FileName 指定什么?某些机器可能会说Acrobat.exe的地方.
一般有什么方法可以指定吗?或通过其他任何方式打开pdf文件中的特定页面

谢谢和问候,
Divya.K



but i have one more issue ,this will work fine in my local machine where i have AcroRd32.exe installed,but in different
but in general what to specify for myProcess.StartInfo.FileName ? where some machines may have say Acrobat.exe .
any way is there to specify in general? Or any other way to open the particular page in a pdf file

Thanks and Regards,
Divya.K

推荐答案

否.用户将在需要时安装Acrobat. 绝对没有这样的情况,任何路径名都可以在程序代码中进行硬编码.

所有文件路径始终在运行时计算.此计算绝不应考虑工作目录-用户可以在任何目录中启动任何应用程序.路径名总是相对于应用程序可执行目录或特殊目录(例如当前本地用户的应用程序数据等)计算的.

就您而言,您可以拥有一个配置文件,其中包含Acrobat的完整路径.应记录在案,因为用户可以将Acrobat重新安装到其他位置.这是最好的.

我会质疑运行任何外部程序的整个想法.这是初学者设计的非常典型的功能.您能做的最好的就是:只需将数据导出为PDF. 用户更了解如何运行它.如果安装了Acrobat(Actobat Reader),则通常与PDF文件扩展名关联.用户只需单击某些Shell中的文件(如资源管理器)即可;并打开它.


经过与克里斯蒂安的讨论.由于Acrobat通常与文件扩展名关联,因此Shell知道它.因此,Process.Start可以仅使用文件名.像这样的东西:

No. The users will install Acrobat whenever they want. There are absolutely no such situations where any path name could be hard-coded in the code of the program.

All file paths are always calculated during run-time. This calculation should never take into account working directory — the user can start any application in any directory. The path names are always calculated relative to application executable directory or special directory such as the Application Data of the current local user, etc.

In your case, you can have a configuration file which has a full path to the Acrobat. It should be documented as the user can re-install Acrobat to a different location. This is the best you can do.

I would question the whole idea of running any external program. This is a very typical feature devised by the beginners. The best you can do is this: simply offer export of your data to PDF. The user knows better how to run it. If Acrobat (Actobat Reader) is installed, it''s usually associated with PDF file extension. The user simply clicks on the file in some Shell (like Explorer); and open it.


After discussion with Cristian. As Acrobat is usually associated with the file name extension, the Shell knows it. So Process.Start can use just the file name. Something like this:

myProcess.StartInfo.FileName = @"D:\Doc1.pdf\";
myProcess.StartInfo.Arguments = @"/A ""page=2""";

>


—SA




—SA


您正在做的事情比您需要做的要走了一步.调用Process.从PDF本身开始,然后Windows会找到acrobat并为您运行它.
What you''re doing is one step removed from what you need to do. Call Process.Start on the PDF itself, and windows will find acrobat and run it for you.


这篇关于通常指定Acrobat路径以在C#中打开pdf文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆