C # display the PDF file. winform opens the PDF file and displays it in the form.
1. Add the ActiveX control provided by Adobe to the toolbox ,:
Select the COM component. I used version 7.0 to check and confirm it. On the Control toolbar, see:
Drag an Adobe PDF Reader control to the form and double-click the form. When the form is loaded, a dialog box is displayed to load the PDF file:
String filename = myopenfiledialog ();
Axacroupload 1.loadfile (filename );
The myopenfiledialog () function is:
String myopenfiledialog ()
{
Openfiledialog ofd = new openfiledialog ();
Ofd. Filter = "pdf document (*. pdf) | *. pdf ";
If (OFD. showdialog () = dialogresult. OK)
{
Return ofd. filename;
}
Else
{
Return NULL;
}
}
You can also use the code to create the Adobe PDF Reader component:
String filename = myopenfiledialog ();
Axacropdflib. axacropdf = new axacropdflib. axacropdf ();
Axwing pdf. Location = new system. Drawing. Point (0, 24 );
Axwing pdf. size = new system. Drawing. Size (292,242 );
Axacropdf. Dock = dockstyle. Fill;
Controls. Add (axw.pdf );
Axacropdf. LoadFile (filename );
However, when we drag the Adobe PDF Reader component to the form, it will automatically reference two dll: acropdflib and acropdflib,
During compilation, vs converts the Adobe PDF Reader ActiveX component to two. NET components: axinterop. acropdflib. dll and InterOP. acropdflib. dll,
Therefore, when writing code to create the Adobe PDF Reader component, You need to manually convert the Adobe PDF Reader ActiveX component to the. NET Component and reference it! The best way is to place an Adobe PDF Reader component on the form and then delete it. You do not need to manually delete it!