C # display the PDF file. winform opens the PDF file and displays it in the form.

Source: Internet
Author: User

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.