How to Open and Show a PDF file in C#
By FoxLearn 3/25/2025 1:36:53 AM 16.98K
This requires the Adobe Acrobat Reader software to be installed on the machine.
How to Open and Show a PDF file in C#?
Open Visual Studio, then click New Project, then select Visual C# on the left, then Windows and then select Windows Forms Application. Name your project "PdfViewer" and then click OK
You need to install Adobe Acrobat Reader, then add a reference to Interop.AcroPDFLib
, AxInterop.AcroPDFLib
control in your Windows Forms project.
How to add the ActiveX Control to the Visual Toolbox?
In Visual Studio, right-click on the Toolbox and select Choose Items....Go to the COM Components tab, then look for Adobe PDF Reader
or AcroPDF.dll
in the list, and check it.
Next, Click OK button to add the Adobe PDF Reader control to the Toolbox.
Drag and drop the Adobe PDF Reader control from the Toolbox onto your form.
Add a click event handler to Open button allows load and display a PDF file in the form
For example, net pdf viewer for winforms
1 2 3 4 5 6 7 8 9 10 11 12 13 |
// open pdf in c# private void btnOpen_Click( object sender, EventArgs e) { // c# pdf file using (OpenFileDialog ofd = new OpenFileDialog() { ValidateNames = true , Multiselect = false , Filter = "PDF|*.pdf" }) { if (ofd.ShowDialog() == DialogResult.OK) { // c# open pdf file by loading the PDF into the Adobe PDF Reader control axAcroPDF.src = ofd.FileName; // pdf c# in file } } } |
When you added the control, Visual Studio should have automatically added a reference to the AcroPDFLib
in your project.
VIDEO TUTORIAL
- How to Get all Forms and Open Form with Form Name in C#
- How to zoom an image in C#
- How to Print a Picture Box in C#
- How to update UI from another thread in C#
- How to Search DataGridView by using TextBox in C#
- How to read and write to text file in C#
- How to save files using SaveFileDialog in C#
- How to Print DataGridView with Header & Footer with Landscape in C#