Program : opens a lecture, at the end of the lecture offers to pass the test. After the test displays the result.

The project is written in windows forms. Lecture in pdf format. I open the file using Adobe PDF Reader:

string filePath = "C:\\Users\\q\\1.pdf"; this.axAcroPDF1.LoadFile(filePath); this.axAcroPDF1.src = filePath; this.axAcroPDF1.setShowToolbar(false); this.axAcroPDF1.setView("FitH"); this.axAcroPDF1.setLayoutMode("SinglePage"); this.axAcroPDF1.Show(); 

Problem : it is necessary that the pdf-file is in the project (inside .exe ), so that it can be read only in the program.

  • one
    Well, put it in the resources, if your control can read from the stream. - VladD
  • How to do this, please tell me? Using VS 15 - Kto To

2 answers 2

In my opinion, you need to abandon the acrobat and show pdf directly in your program with the help of some PdfViewer - a pdf viewing engine. I recommend google pdfium. For .Net there are wrappers for this engine. Both paid and free. We use paid, for our task, and for yours completely and free may be suitable. Pvginkel - source code on github is. Generally google Pdfium PdfViewer

  • one
    “Generally google” is bad advice, google leads back to StackOverflow. You'd better give a sample code. - VladD

On the Project menu, click Properties. Click the Resources tab. In the Resource Designer toolbar, point to Add Resources, click the arrow, then Add an existing file.

However, most likely the download from the stream will not be supported (as Vlad said) . to tell

 this.axAcroPDF1.src=WindowsFormsApplication1.Properties.Resources.1.pdf 

It will not work . Then you have to make a hellish shackle, save somewhere at a pace through the FileStream,

 File.WriteAllBytes("1.pdf", MyResources.1.pdf); 

and then open, as from a disk.

  string filePath = "1.pdf"; this.axAcroPDF1.LoadFile(filePath); this.axAcroPDF1.src = filePath; this.axAcroPDF1.setShowToolbar(false); this.axAcroPDF1.setView("FitH"); this.axAcroPDF1.setLayoutMode("SinglePage"); this.axAcroPDF1.Show(); 

After reading, clean the directory ...

if(File.Exists(filePath))File.Delete(filePath);

As always, most likely I am mistaken and there is a better way ...

  • Added file to resources (thanks, now I will know how to add). And the question immediately appeared: in the properties of this resource there is an item “Action at assembly”, what should be indicated here? - Kto To
  • second : when you try to insert the line 'System.IO.File.WriteAllBytes ("1.pdf", MyResources.1.pdf);' does not know what is MyResources. How to add it? - Kto To
  • Look at the first path, the path to the resources will be more accurate there: WindowsFormsApplication1.Properties.Resources - xSx
  • System.IO.File.WriteAllBytes("1.pdf", Properties.Resources._1); - it turned out such a line. Why "_1"? After this line, the pdf does not open ( - Kto To
  • resources, if not called, are so named (_The name of the File) so that everything is fine :) - xSx