[2.0] Run Acrobat Reader within UC.
Is there a way to run a program like specifically Adobe Acrobat within a .NET user control?
I am having trouble with navigation links when using the Acrobat Active X control... They don't actually work.
They work in the full-blown Acrobat Reader, but not the control.
I thought I would try and encapsulate Acro Reader in my User Control, but am open to suggestions.
Re: [2.0] Run Acrobat Reader within UC.
You can use a WebBrowser control to host an instance of Adobe Reader just as IE does.
Re: [2.0] Run Acrobat Reader within UC.
Well, we tried that and had trouble with it.
We have a series of pdf files, all in one directory. The various files reference one another.
-When we run in AcrobatReader, it all functions fine.
-When we use the IE control, links to other files work, but only to open the files, not to jump to specific bookmarks (or named destinations, whatever)
-When we use the ActiveX control, it fails to even load other files.
Since these files were created many moons ago, it is unlikely that they can be altered at this point.
So, I thought I'd try and get the Reader to operate within the confines of a User Control. Any suggestions? Am I gonna have to get the handle and "force" the reader to display?
Re: [2.0] Run Acrobat Reader within UC.
You can open an instance of Adobe Reader and then use the SetParent API to capture the window and host it within your own control. There can be issues associated with doing this sort of thing but it may be worth a try. There are examples of using Setparent posted on the forum already so a search should help.
Re: [2.0] Run Acrobat Reader within UC.
I think the issue associated with it is: It don't work. :)
This is, however exactly what I was trying to do, but it does not seem to be able to actually put the exe handle as a child of the .Net form.
Here is the code I'm using but I think it's the function call itself.
I think I may just have to launch AReader as it's own application: not the best, but certainly a solution.
Code:
public partial class Form1 : Form
{
[System.Runtime.InteropServices.DllImport("user32.dll")]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
System.Diagnostics.Process proc;
System.Diagnostics.ProcessStartInfo si;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
si = new System.Diagnostics.ProcessStartInfo();
si.FileName = "notepad.exe";
si.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
proc = System.Diagnostics.Process.Start(si);
proc.EnableRaisingEvents = true;
proc.Exited += new EventHandler(proc_Exited);
SetParent(this.Handle,proc.MainWindowHandle );
}
void proc_Exited(object sender, EventArgs e)
{
//Note this event is fired on the child application thread... no textbox displays!
//label1.Text = proc.ExitCode.ToString();
MessageBox.Show(proc.ExitCode.ToString());
}
}
[resolved][2.0] Run Acrobat Reader within UC.
Ah crud.
Spoke too soon.
Forgot a "proc.WaitForInputIdle()"
Works well enough now.
Thanks jm!