如何打开也是项目资源的 PDF 文件? [英] How to open a PDF file that is also a project resource?

查看:25
本文介绍了如何打开也是项目资源的 PDF 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 PDF 文件,我已将其作为资源导入到我的项目中.该文件是一个帮助文档,因此我希望能够将其包含在每次部署中.我希望能够通过单击按钮打开此文件.

I have a PDF file that I have imported in as a resource into my project. The file is a help document so I want to be able to include it with every deployment. I want to be able to open this file at the click of a button.

我已将构建操作设置为嵌入资源".所以现在我希望能够打开它.但是,当我尝试访问资源 - My.Resources.HelpFile - 它是一个字节数组.如果我知道最终用户有适合打开 PDF 文档的程序,我将如何打开它?

I have set the build action to "Embedd Resource". So now I want to be able to open it. However, When I try accessing the resource - My.Resources.HelpFile - it is a byte array. How would I go about opening this if I know that the end-user has a program suitable to opening PDF documents?

如果我错过了之前的问题,请指出正确的方向.我发现了几个关于应用程序中打开 PDF 的问题,但我不在乎 Adob​​e Reader 是否单独打开.

If I missed a previous question please point me to the right direction. I have found several questions about opening a PDF within an application, but I don't care if Adobe Reader opens seperately.

推荐答案

创建新流程:

string path = Path.Combine(Directory.GetCurrentDirectory(), "PDF-FILE.pdf");
Process P = new Process {
    StartInfo = {FileName = "AcroRd32.exe", Arguments = path}
};
P.Start();

为了使其工作,必须将 Visual Studio 设置 Copy to Output Directory 设置为 PDF 文件的Copy Always.

In order for this to work, the Visual Studio setting Copy to Output Directory has to be set to Copy Always for the PDF file.

这篇关于如何打开也是项目资源的 PDF 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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