I have a pdf viewer which for the sake of the example, displays selected filename from a listbox. It is a simple form with a listbox an axAcroPDF and textbox to confirm correct filepath. The code is as follows and the files have been placed in a folder pdfs in the Debug folder:
using System;
using System.Windows.Forms;
namespace pdf_viewer
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
string path = AppDomain.CurrentDomain.BaseDirectory + "pdfs\\" + listBox1.SelectedItem.ToString();
textBox1.Text = path;
InitializeAdobe(path);
}
private void InitializeAdobe(string filePath)
{
axAcroPDF1.LoadFile(filePath);
axAcroPDF1.src = filePath;
axAcroPDF1.setShowToolbar(false);
axAcroPDF1.setView("Fit");
axAcroPDF1.setLayoutMode("SinglePage");
axAcroPDF1.Show();
}
}
}
It all works correctly with a few issues:
- the first time you cycle through the files it displays correctly in the window but if you go back to an entry, the second time it shows the toolbar at the right despite this being disabled in the code. The toolbar takes up the bulk of the window.
- When you close the window, it takes and inordinately long time to close, indicating to me there is a lot of housekeeping going on. Any clues on why this would be happening.
In addition to this:
- do I need both .LoadFile and .src statements in the code as both work in isolation but is one preferable to the other. Doesn't seem to change the above issues. This method was lifted from another Stack Overflow question.
Thanks
PS Since originally posting, I have tried to display in a webBrowser window but exactly the same thing happens with the toolbar panel displaying the second time you select an entry. The code is as follows:
webBrowser1.Url = new Uri(path);