Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open a PDF file that is also a project resource?

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.

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?

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.

like image 352
Adam Beck Avatar asked Dec 22 '11 20:12

Adam Beck


People also ask

Why are my PDF files not opening?

Here are some of the most common culprits to consider: Your laptop doesn't have a PDF reader installed. Your PDF reader or preferred program is out of date and needs an update. Your PDF application is potentially damaged or needs to be rebooted.

Can I open a PDF in something other than Adobe?

If you need to get a Adobe reader alternative for Windows 10, Wondershare PDFelement - PDF Editor, Foxit Reader, Power PDF are all excellent choices.


2 Answers

Check this out easy to open pdf file from resource.

private void btnHelp_Click(object sender, EventArgs e)
    {            
        String openPDFFile = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\HelpDoc.pdf";//PDF DOc name
        System.IO.File.WriteAllBytes(openPDFFile, global::ProjectName.Properties.Resources.resourcePdfFileName);//the resource automatically creates            
        System.Diagnostics.Process.Start(openPDFFile);             
    }   
like image 161
M2K SOFT Avatar answered Sep 21 '22 19:09

M2K SOFT


//create a temporal file
string file = Path.GetTempFileName() + ".pdf";
//write to file
File.WriteAllBytes(file, Properties.Resources.PDF_DOCUMENT);
//open with default viewer
System.Diagnostics.Process.Start(file);
like image 20
AlejandroAlis Avatar answered Sep 24 '22 19:09

AlejandroAlis