> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/core/get-started/samples/pdfviewsimpletest.md).

# Simple PDF Viewer Control - PDFViewSimple

Sample C# code for using PDF viewer control in a basic project. This sample uses a number of built-in features from PDFViewCtrl to open PDF files, implement document navigation, text highlighting, mar

Sample C# code for using Apryse SDK's PDF viewer control in a basic project. This sample uses a number of built-in features from PDFViewCtrl to open PDF files, implement document navigation, text highlighting, markup, and editing. If you are looking for a sample showing how to further customize the viewer (e.g. by implementing custom tools or custom GUI elements), please take a look at the [PDFView with customization sample code](/core/get-started/samples/pdfviewform.md). Learn more about our [Server SDK](/core/get-started/frameworks/dotnet.md) and [PDF Viewer SDK](/core/viewer/viewer.md).

{% tabs %}
{% tab title="C#" %}
{% code lineNumbers="true" %}

```csharp
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

using pdftron;
using pdftron.PDF;
using pdftron.SDF;
using pdftron.Filters;
using pdftron.Common;


namespace PDFViewSimpleCS
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class PDFViewSimple : System.Windows.Forms.Form
    {
        private static pdftron.PDFNetLoader pdfNetLoader = pdftron.PDFNetLoader.Instance();
		static PDFViewSimple() {}

        private PDFViewCtrl _pdfview;
        private PDFDoc _pdfdoc;
        private String filePath;

        private IContainer components;
        private MainMenu mainMenu1;
        private MenuItem menuItem1;
        private MenuItem MenuFileOpen;
        private MenuItem MenuFileSave;
        private MenuItem MenuFileSaveAs;
        private MenuItem MenuFilePrint;
        private MenuItem MenuFileExit;
        private MenuItem menuItem2;
        private MenuItem MenuEditFind;
        private MenuItem MenuEditCopy;
        private MenuItem MenuEditSelect;
        private MenuItem menuItem3;
        private MenuItem MenuViewPageLayout;
        private MenuItem MenuViewPageView;
        private MenuItem MenuViewZoomIn;
        private MenuItem MenuViewZoomOut;
        private MenuItem MenuViewPageLayoutSingle;
        private MenuItem MenuViewPageLayoutSingleContinuous;
        private MenuItem MenuViewPageLayoutFacing;
        private MenuItem MenuViewPageLayoutFacingContinuous;
        private MenuItem MenuViewPageViewFitPage;
        private MenuItem MenuViewPageViewFitWidth;
        private MenuItem menuItem4;
        private MenuItem MenuToolPan;
        private MenuItem MenuToolStructSel;
        private MenuItem MenuToolRectSel;
        private MenuItem MenuToolRectZoomIn;
        private MenuItem MenuToolRectZoomOut;
        private MenuItem MenuToolAnnotEdit;
        private MenuItem MenuToolLineCreate;
        private MenuItem MenuToolRectCreate;
        private MenuItem MenuToolOvalCreate;
        private MenuItem MenuToolArrowCreate;
        private MenuItem MenuToolFreeHand;
        private MenuItem menuItem5;
        private MenuItem MenuPageNavNext;
        private MenuItem MenuPageNavPrev;
        private MenuItem MenuPageNavFirst;
        private MenuItem MenuPageNavLast;
        private MenuItem menuItem6;
		private System.Windows.Forms.MenuItem menuItemNavPanel;
		private System.Windows.Forms.MenuItem menuItem7;
        private MenuItem menuHelpAbout;
       

		public PDFViewSimple()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
			_pdfview = new PDFViewCtrl();
			_pdfview.Location = new System.Drawing.Point(0, 0);
			_pdfview.Dock = System.Windows.Forms.DockStyle.Fill;
            _pdfview.SetPageBorderVisibility(false);
			Controls.Add(_pdfview);
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            this.components = new System.ComponentModel.Container();
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(PDFViewSimple));
            this.mainMenu1 = new System.Windows.Forms.MainMenu();
            this.menuItem1 = new System.Windows.Forms.MenuItem();
            this.MenuFileOpen = new System.Windows.Forms.MenuItem();
            this.MenuFileSave = new System.Windows.Forms.MenuItem();
            this.MenuFileSaveAs = new System.Windows.Forms.MenuItem();
            this.MenuFilePrint = new System.Windows.Forms.MenuItem();
            this.MenuFileExit = new System.Windows.Forms.MenuItem();
            this.menuItem2 = new System.Windows.Forms.MenuItem();
            this.MenuEditFind = new System.Windows.Forms.MenuItem();
            this.MenuEditCopy = new System.Windows.Forms.MenuItem();
            this.MenuEditSelect = new System.Windows.Forms.MenuItem();
            this.menuItem3 = new System.Windows.Forms.MenuItem();
            this.MenuViewPageLayout = new System.Windows.Forms.MenuItem();
            this.MenuViewPageLayoutSingle = new System.Windows.Forms.MenuItem();
            this.MenuViewPageLayoutSingleContinuous = new System.Windows.Forms.MenuItem();
            this.MenuViewPageLayoutFacing = new System.Windows.Forms.MenuItem();
            this.MenuViewPageLayoutFacingContinuous = new System.Windows.Forms.MenuItem();
            this.MenuViewPageView = new System.Windows.Forms.MenuItem();
            this.MenuViewPageViewFitPage = new System.Windows.Forms.MenuItem();
            this.MenuViewPageViewFitWidth = new System.Windows.Forms.MenuItem();
            this.MenuViewZoomIn = new System.Windows.Forms.MenuItem();
            this.MenuViewZoomOut = new System.Windows.Forms.MenuItem();
            this.menuItem7 = new System.Windows.Forms.MenuItem();
            this.menuItemNavPanel = new System.Windows.Forms.MenuItem();
            this.menuItem4 = new System.Windows.Forms.MenuItem();
            this.MenuToolPan = new System.Windows.Forms.MenuItem();
            this.MenuToolStructSel = new System.Windows.Forms.MenuItem();
            this.MenuToolRectSel = new System.Windows.Forms.MenuItem();
            this.MenuToolRectZoomIn = new System.Windows.Forms.MenuItem();
            this.MenuToolRectZoomOut = new System.Windows.Forms.MenuItem();
            this.MenuToolAnnotEdit = new System.Windows.Forms.MenuItem();
            this.MenuToolLineCreate = new System.Windows.Forms.MenuItem();
            this.MenuToolRectCreate = new System.Windows.Forms.MenuItem();
            this.MenuToolOvalCreate = new System.Windows.Forms.MenuItem();
            this.MenuToolArrowCreate = new System.Windows.Forms.MenuItem();
            this.MenuToolFreeHand = new System.Windows.Forms.MenuItem();
            this.menuItem5 = new System.Windows.Forms.MenuItem();
            this.MenuPageNavNext = new System.Windows.Forms.MenuItem();
            this.MenuPageNavPrev = new System.Windows.Forms.MenuItem();
            this.MenuPageNavFirst = new System.Windows.Forms.MenuItem();
            this.MenuPageNavLast = new System.Windows.Forms.MenuItem();
            this.menuItem6 = new System.Windows.Forms.MenuItem();
            this.menuHelpAbout = new System.Windows.Forms.MenuItem();
            this.SuspendLayout();
            // 
            // mainMenu1
            // 
            this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
            this.menuItem1,
            this.menuItem2,
            this.menuItem3,
            this.menuItem4,
            this.menuItem5,
            this.menuItem6});
            // 
            // menuItem1
            // 
            this.menuItem1.Index = 0;
            this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
            this.MenuFileOpen,
            this.MenuFileSave,
            this.MenuFileSaveAs,
            this.MenuFilePrint,
            this.MenuFileExit});
            this.menuItem1.Text = "File";
            // 
            // MenuFileOpen
            // 
            this.MenuFileOpen.Index = 0;
            this.MenuFileOpen.Text = "Open..";
            this.MenuFileOpen.Click += new System.EventHandler(this.menuFileOpen_Click);
            // 
            // MenuFileSave
            // 
            this.MenuFileSave.Index = 1;
            this.MenuFileSave.Text = "Save";
            this.MenuFileSave.Click += new System.EventHandler(this.MenuFileSave_Click);
            // 
            // MenuFileSaveAs
            // 
            this.MenuFileSaveAs.Index = 2;
            this.MenuFileSaveAs.Text = "Save As";
            this.MenuFileSaveAs.Click += new System.EventHandler(this.MenuFileSaveAs_Click);
            // 
            // MenuFilePrint
            // 
            this.MenuFilePrint.Index = 3;
            this.MenuFilePrint.Text = "Print";
            this.MenuFilePrint.Click += new System.EventHandler(this.MenuFilePrint_Click);
            // 
            // MenuFileExit
            // 
            this.MenuFileExit.Index = 4;
            this.MenuFileExit.Text = "Exit";
            this.MenuFileExit.Click += new System.EventHandler(this.MenuFileExit_Click);
            // 
            // menuItem2
            // 
            this.menuItem2.Index = 1;
            this.menuItem2.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
            this.MenuEditFind,
            this.MenuEditCopy,
            this.MenuEditSelect});
            this.menuItem2.Text = "Edit";
            // 
            // MenuEditFind
            // 
            this.MenuEditFind.Index = 0;
            this.MenuEditFind.Text = "Find ...";
            this.MenuEditFind.Click += new System.EventHandler(this.MenuEditFind_Click);
            // 
            // MenuEditCopy
            // 
            this.MenuEditCopy.Index = 1;
            this.MenuEditCopy.Text = "Copy";
            this.MenuEditCopy.Click += new System.EventHandler(this.MenuEditCopy_Click);
            // 
            // MenuEditSelect
            // 
            this.MenuEditSelect.Index = 2;
            this.MenuEditSelect.Text = "Select All";
            this.MenuEditSelect.Click += new System.EventHandler(this.MenuEditSelect_Click);
            // 
            // menuItem3
            // 
            this.menuItem3.Index = 2;
            this.menuItem3.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
            this.MenuViewPageLayout,
            this.MenuViewPageView,
            this.MenuViewZoomIn,
            this.MenuViewZoomOut,
            this.menuItem7,
            this.menuItemNavPanel});
            this.menuItem3.Text = "View";
            // 
            // MenuViewPageLayout
            // 
            this.MenuViewPageLayout.Index = 0;
            this.MenuViewPageLayout.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
            this.MenuViewPageLayoutSingle,
            this.MenuViewPageLayoutSingleContinuous,
            this.MenuViewPageLayoutFacing,
            this.MenuViewPageLayoutFacingContinuous});
            this.MenuViewPageLayout.Text = "Page Layout";
            // 
            // MenuViewPageLayoutSingle
            // 
            this.MenuViewPageLayoutSingle.Index = 0;
            this.MenuViewPageLayoutSingle.Text = "Single Page";
            this.MenuViewPageLayoutSingle.Click += new System.EventHandler(this.MenuViewPageLayoutSingle_Click);
            // 
            // MenuViewPageLayoutSingleContinuous
            // 
            this.MenuViewPageLayoutSingleContinuous.Index = 1;
            this.MenuViewPageLayoutSingleContinuous.Text = "Single Continuous";
            this.MenuViewPageLayoutSingleContinuous.Click += new System.EventHandler(this.MenuViewPageLayoutSingleContinuous_Click);
            // 
            // MenuViewPageLayoutFacing
            // 
            this.MenuViewPageLayoutFacing.Index = 2;
            this.MenuViewPageLayoutFacing.Text = "Facing";
            this.MenuViewPageLayoutFacing.Click += new System.EventHandler(this.MenuViewPageLayoutFacing_Click);
            // 
            // MenuViewPageLayoutFacingContinuous
            // 
            this.MenuViewPageLayoutFacingContinuous.Index = 3;
            this.MenuViewPageLayoutFacingContinuous.Text = "Facing Continuous";
            this.MenuViewPageLayoutFacingContinuous.Click += new System.EventHandler(this.MenuViewPageLayoutFacingContinuous_Click);
            // 
            // MenuViewPageView
            // 
            this.MenuViewPageView.Index = 1;
            this.MenuViewPageView.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
            this.MenuViewPageViewFitPage,
            this.MenuViewPageViewFitWidth});
            this.MenuViewPageView.Text = "Page View Mode";
            // 
            // MenuViewPageViewFitPage
            // 
            this.MenuViewPageViewFitPage.Index = 0;
            this.MenuViewPageViewFitPage.Text = "Fit Page";
            this.MenuViewPageViewFitPage.Click += new System.EventHandler(this.MenuViewPageViewFitPage_Click);
            // 
            // MenuViewPageViewFitWidth
            // 
            this.MenuViewPageViewFitWidth.Index = 1;
            this.MenuViewPageViewFitWidth.Text = "Fit Width";
            this.MenuViewPageViewFitWidth.Click += new System.EventHandler(this.MenuViewPageViewFitWidth_Click);
            // 
            // MenuViewZoomIn
            // 
            this.MenuViewZoomIn.Index = 2;
            this.MenuViewZoomIn.Text = "Zoom In";
            this.MenuViewZoomIn.Click += new System.EventHandler(this.MenuViewZoomIn_Click);
            // 
            // MenuViewZoomOut
            // 
            this.MenuViewZoomOut.Index = 3;
            this.MenuViewZoomOut.Text = "Zoom Out";
            this.MenuViewZoomOut.Click += new System.EventHandler(this.MenuViewZoomOut_Click);
            // 
            // menuItem7
            // 
            this.menuItem7.Index = 4;
            this.menuItem7.Text = "-";
            // 
            // menuItemNavPanel
            // 
            this.menuItemNavPanel.Index = 5;
            this.menuItemNavPanel.Text = "Navigation Panel";
            this.menuItemNavPanel.Click += new System.EventHandler(this.menuItem7_Click);
            // 
            // menuItem4
            // 
            this.menuItem4.Index = 3;
            this.menuItem4.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
            this.MenuToolPan,
            this.MenuToolStructSel,
            this.MenuToolRectSel,
            this.MenuToolRectZoomIn,
            this.MenuToolRectZoomOut,
            this.MenuToolAnnotEdit,
            this.MenuToolLineCreate,
            this.MenuToolRectCreate,
            this.MenuToolOvalCreate,
            this.MenuToolArrowCreate,
            this.MenuToolFreeHand});
            this.menuItem4.Text = "Tool";
            // 
            // MenuToolPan
            // 
            this.MenuToolPan.Index = 0;
            this.MenuToolPan.Text = "Pan";
            this.MenuToolPan.Click += new System.EventHandler(this.MenuToolPan_Click);
            // 
            // MenuToolStructSel
            // 
            this.MenuToolStructSel.Index = 1;
            this.MenuToolStructSel.Text = "Structural Selection";
            this.MenuToolStructSel.Click += new System.EventHandler(this.MenuToolStructSel_Click);
            // 
            // MenuToolRectSel
            // 
            this.MenuToolRectSel.Index = 2;
            this.MenuToolRectSel.Text = "Rectangular Selection";
            this.MenuToolRectSel.Click += new System.EventHandler(this.MenuToolRectSel_Click);
            // 
            // MenuToolRectZoomIn
            // 
            this.MenuToolRectZoomIn.Index = 3;
            this.MenuToolRectZoomIn.Text = "Rectangular Zoom In";
            this.MenuToolRectZoomIn.Click += new System.EventHandler(this.MenuToolRectZoomIn_Click);
            // 
            // MenuToolRectZoomOut
            // 
            this.MenuToolRectZoomOut.Index = 4;
            this.MenuToolRectZoomOut.Text = "Rectangular Zoom Out";
            this.MenuToolRectZoomOut.Click += new System.EventHandler(this.MenuToolRectZoomOut_Click);
            // 
            // MenuToolAnnotEdit
            // 
            this.MenuToolAnnotEdit.Index = 5;
            this.MenuToolAnnotEdit.Text = "Annotation Editing";
            this.MenuToolAnnotEdit.Click += new System.EventHandler(this.MenuToolAnnotEdit_Click);
            // 
            // MenuToolLineCreate
            // 
            this.MenuToolLineCreate.Index = 6;
            this.MenuToolLineCreate.Text = "Line Creation";
            this.MenuToolLineCreate.Click += new System.EventHandler(this.MenuToolLineCreate_Click);
            // 
            // MenuToolRectCreate
            // 
            this.MenuToolRectCreate.Index = 7;
            this.MenuToolRectCreate.Text = "Rectangle Creation";
            this.MenuToolRectCreate.Click += new System.EventHandler(this.MenuToolRectCreate_Click);
            // 
            // MenuToolOvalCreate
            // 
            this.MenuToolOvalCreate.Index = 8;
            this.MenuToolOvalCreate.Text = "Oval Creation";
            this.MenuToolOvalCreate.Click += new System.EventHandler(this.MenuToolOvalCreate_Click);
            // 
            // MenuToolArrowCreate
            // 
            this.MenuToolArrowCreate.Index = 9;
            this.MenuToolArrowCreate.Text = "Arrow Creation";
            this.MenuToolArrowCreate.Click += new System.EventHandler(this.MenuToolArrowCreate_Click);
            // 
            // MenuToolFreeHand
            // 
            this.MenuToolFreeHand.Index = 10;
            this.MenuToolFreeHand.Text = "FreeHand Tool";
            this.MenuToolFreeHand.Click += new System.EventHandler(this.MenuToolFreeHand_Click);
            // 
            // menuItem5
            // 
            this.menuItem5.Index = 4;
            this.menuItem5.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
            this.MenuPageNavNext,
            this.MenuPageNavPrev,
            this.MenuPageNavFirst,
            this.MenuPageNavLast});
            this.menuItem5.Text = "Page Navigation";
            // 
            // MenuPageNavNext
            // 
            this.MenuPageNavNext.Index = 0;
            this.MenuPageNavNext.Text = "Go To Next Page";
            this.MenuPageNavNext.Click += new System.EventHandler(this.MenuPageNavNext_Click);
            // 
            // MenuPageNavPrev
            // 
            this.MenuPageNavPrev.Index = 1;
            this.MenuPageNavPrev.Text = "Go To Previous Page";
            this.MenuPageNavPrev.Click += new System.EventHandler(this.MenuPageNavPrev_Click);
            // 
            // MenuPageNavFirst
            // 
            this.MenuPageNavFirst.Index = 2;
            this.MenuPageNavFirst.Text = "Go To First Page";
            this.MenuPageNavFirst.Click += new System.EventHandler(this.MenuPageNavFirst_Click);
            // 
            // MenuPageNavLast
            // 
            this.MenuPageNavLast.Index = 3;
            this.MenuPageNavLast.Text = "Go To Last Page";
            this.MenuPageNavLast.Click += new System.EventHandler(this.MenuPageNavLast_Click);
            // 
            // menuItem6
            // 
            this.menuItem6.Index = 5;
            this.menuItem6.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
            this.menuHelpAbout});
            this.menuItem6.Text = "Help";
            // 
            // menuHelpAbout
            // 
            this.menuHelpAbout.Index = 0;
            this.menuHelpAbout.Text = "About ...";
            this.menuHelpAbout.Click += new System.EventHandler(this.menuHelpAbout_Click);
            // 
            // PDFViewSimple
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(619, 443);
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.Menu = this.mainMenu1;
            this.Name = "PDFViewSimple";
            this.Text = "PDFViewSimple";
            this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread] 		
		static void Main() 
		{
			PDFNet.Initialize(PDFTronLicense.Key);
			Application.Run(new PDFViewSimple());
		}


		private void menuFileOpen_Click(object sender, System.EventArgs e)
		{
			OpenFileDialog dlg = new OpenFileDialog();
			dlg.CheckFileExists = true;
			dlg.CheckPathExists = true;
			dlg.Filter="PDF (*.pdf)|*.pdf|All files (*.*)|*.*";
			dlg.DefaultExt = ".pdf";

			if(dlg.ShowDialog() == DialogResult.OK) 
			{
				OpenPDF(dlg.FileName); 
			}
		}

		public bool OpenPDF(String filename)
		{
			try 
			{
				PDFDoc oldDoc = _pdfview.GetDoc();
				_pdfdoc = new PDFDoc(filename);
                if (!_pdfdoc.InitSecurityHandler())
                {
                    AuthorizeDlg dlg = new AuthorizeDlg();
                    if (dlg.ShowDialog() == DialogResult.OK)
                    {
                        if(!_pdfdoc.InitStdSecurityHandler(dlg.pass.Text))
                        {
                            MessageBox.Show("Incorrect password");
                            return false;
                        }
                    }
                    else
                    {
                        return false;
                    }
                }
                _pdfview.SetDoc(_pdfdoc);

                // Example calls to SetupThumbnails:

                // To turn on thumbnail rendering (each 600x600), and retrieving 
                // thumbnails from the pdfs, but no persistent thumbnail caching on disk:
                //_pdfview.SetupThumbnails(true, true, false, 600, "", 0);

                // To cache 100 thumbnails, each 600x600, at "D:\\thumb_cache":
                //_pdfview.SetupThumbnails(true, true, true, 600, "D:\\thumb_cache", 600 * 600 * 4 * 100);
                // To programmatically delete the cache at "D:\\thumb_cache":
                //_pdfview.SetupThumbnails(true, true, true, 600, "D:\\thumb_cache", 0);

                // Example call to GetThumbAsync:
                //PDFViewThumbAsyncDelegate my_del = delegate(int page_num, bool was_thumb_found, System.Drawing.Bitmap thumb_buf, int thumb_width, int thumb_height, object custom_data)
                //{
                //    Console.WriteLine("Inside the callback for GetThumbAsync.");
                //};
                //_pdfview.GetThumbAsync(2, my_del, this);
                
                // Use built-in navigation (thumbnails, bookmarks, layers, etc)?
				// _pdfview.ShowNavToolbar(true);
				// _pdfview.ShowNavPanel(true);

				filePath = filename;
				if (oldDoc != null) 
                {
					oldDoc.Dispose();
				}
			}
			catch(PDFNetException ex)
			{
				MessageBox.Show(ex.Message);
				return false;
			}
			catch(Exception ex)
			{
				MessageBox.Show(ex.ToString());
				return false;
			}

			this.Text = filename;  // Set the title
			return true;
		}

	    private void MenuFileSave_Click(object sender, EventArgs e)
        {
            if (_pdfview.GetDoc() != null)
                _pdfview.GetDoc().Save(filePath, SDFDoc.SaveOptions.e_remove_unused);
        }

        private void MenuFileSaveAs_Click(object sender, EventArgs e)
        {
            SaveAs();
        }

        private void SaveAs()
        {
            if (_pdfview.GetDoc() != null)
            {
                SaveFileDialog dlg = new SaveFileDialog();
                dlg.Title = "Save Pdf File";
                dlg.Filter = "PDF (*.pdf)|*.pdf|All files (*.*)|*.*";
                dlg.DefaultExt = ".pdf";

                if (dlg.ShowDialog() == DialogResult.OK)
                    if (dlg.FileName != null)
                        _pdfview.GetDoc().Save(dlg.FileName, SDFDoc.SaveOptions.e_remove_unused);
            }
        }

        private void MenuFilePrint_Click(object sender, EventArgs e)
        {
            if (_pdfview.GetDoc() != null)
                _pdfview.Print();
        }

        private void MenuFileExit_Click(object sender, System.EventArgs e)
        {
            PDFNet.Terminate();
            //when the user clicks exit, exit the application
            Application.Exit();
        }

        private void MenuEditFind_Click(object sender, EventArgs e)
        {
            if (_pdfview.GetDoc() != null)
                _pdfview.Find();
        }

        private void MenuEditCopy_Click(object sender, EventArgs e)
        {
            if (_pdfview.GetDoc() != null)
                _pdfview.Copy();
        }

        private void MenuEditSelect_Click(object sender, EventArgs e)
        {
            if (_pdfview.GetDoc() != null)
                _pdfview.SelectAll();
        }

        private void MenuViewPageLayoutSingle_Click(object sender, EventArgs e)
        {
            _pdfview.SetPagePresentationMode(PDFViewCtrl.PagePresentationMode.e_single_page);
        }

        private void MenuViewPageLayoutSingleContinuous_Click(object sender, EventArgs e)
        {
            _pdfview.SetPagePresentationMode(PDFViewCtrl.PagePresentationMode.e_single_continuous);
        }

        private void MenuViewPageLayoutFacing_Click(object sender, EventArgs e)
        {
            _pdfview.SetPagePresentationMode(PDFViewCtrl.PagePresentationMode.e_facing);
        }

        private void MenuViewPageLayoutFacingContinuous_Click(object sender, EventArgs e)
        {
            _pdfview.SetPagePresentationMode(PDFViewCtrl.PagePresentationMode.e_facing_continuous);
        }

        private void MenuViewPageViewFitPage_Click(object sender, EventArgs e)
        {
            _pdfview.SetPageViewMode(PDFViewCtrl.PageViewMode.e_fit_page);
        }

        private void MenuViewPageViewFitWidth_Click(object sender, EventArgs e)
        {
            _pdfview.SetPageViewMode(PDFViewCtrl.PageViewMode.e_fit_width);
        }

        private void MenuViewZoomIn_Click(object sender, EventArgs e)
        {
            if (_pdfview.GetDoc() != null)
                _pdfview.SetZoom(_pdfview.GetZoom() * 2);
        }

        private void MenuViewZoomOut_Click(object sender, EventArgs e)
        {
            if (_pdfview.GetDoc() != null)
                _pdfview.SetZoom(_pdfview.GetZoom() / 2);
        }

        private void MenuToolPan_Click(object sender, EventArgs e)
        {
            _pdfview.SetToolMode(PDFViewCtrl.ToolMode.e_pan);
        }

        private void MenuToolStructSel_Click(object sender, EventArgs e)
        {
            _pdfview.SetToolMode(PDFViewCtrl.ToolMode.e_text_struct_select);
        }

        private void MenuToolRectSel_Click(object sender, EventArgs e)
        {
            _pdfview.SetToolMode(PDFViewCtrl.ToolMode.e_text_rect_select);
        }

        private void MenuToolRectZoomIn_Click(object sender, EventArgs e)
        {
            _pdfview.SetToolMode(PDFViewCtrl.ToolMode.e_zoom_in);
        }

        private void MenuToolRectZoomOut_Click(object sender, EventArgs e)
        {
            _pdfview.SetToolMode(PDFViewCtrl.ToolMode.e_zoom_out);
        }

        private void MenuToolAnnotEdit_Click(object sender, EventArgs e)
        {
            _pdfview.SetToolMode(PDFViewCtrl.ToolMode.e_annot_edit);
        }

        private void MenuToolLineCreate_Click(object sender, EventArgs e)
        {
            _pdfview.SetToolMode(PDFViewCtrl.ToolMode.e_line_create);
        }

        private void MenuToolRectCreate_Click(object sender, EventArgs e)
        {
            _pdfview.SetToolMode(PDFViewCtrl.ToolMode.e_rect_create);
        }

        private void MenuToolOvalCreate_Click(object sender, EventArgs e)
        {
            _pdfview.SetToolMode(PDFViewCtrl.ToolMode.e_oval_create);
        }

        private void MenuToolArrowCreate_Click(object sender, EventArgs e)
        {
            _pdfview.SetToolMode(PDFViewCtrl.ToolMode.e_arrow_create);
        }

        private void MenuToolFreeHand_Click(object sender, EventArgs e)
        {
            _pdfview.SetToolMode(PDFViewCtrl.ToolMode.e_ink_create);
        }

        private void MenuPageNavNext_Click(object sender, EventArgs e)
        {
            if (_pdfview.GetDoc() != null)
                _pdfview.GotoNextPage();
        }

        private void MenuPageNavPrev_Click(object sender, EventArgs e)
        {
            if (_pdfview.GetDoc() != null)
                _pdfview.GotoPreviousPage();
        }

        private void MenuPageNavFirst_Click(object sender, EventArgs e)
        {
            if (_pdfview.GetDoc() != null)
                _pdfview.GotoFirstPage();
        }

        private void MenuPageNavLast_Click(object sender, EventArgs e)
        {
            if (_pdfview.GetDoc() != null)
                _pdfview.GotoLastPage();
        }

        private void menuHelpAbout_Click(object sender, EventArgs e)
        {
            MessageBox.Show(
                "\n\t   PDFViewSimple, Version 1.0\t\n" +
                "\n\t   Copyright (c) 2009\t\n" +
                "\n\tSimple Sample of using PDFViewCtrl in Win32\t\n\n", 
                "About PDFviewSimple");
        }

		private void menuItem7_Click(object sender, System.EventArgs e)
		{
			this.menuItemNavPanel.Checked = !_pdfview.IsNavPanelVisible();
			_pdfview.ShowNavPanel(this.menuItemNavPanel.Checked);
		}

	}
}
```

{% endcode %}
{% endtab %}

{% tab title="C++" %}
{% code lineNumbers="true" %}

```cpp
//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2021 by PDFTron Systems Inc. All Rights Reserved.
// Consult legal.txt regarding legal and license information.
//---------------------------------------------------------------------------------------
// This sample shows how to add PDF viewer control in a basic Win32 project. 
// The sample uses a number of built-in features from PDFViewCtrl to implement 
// document navigation, text highlighting, markup, and editing. 
//
// PDFViewCtrl offers built-in support for a number of PDF tools (including markup, 
// link creation, forms, text selection, etc) and user interface elements (such as 
// navigation panel, find text, etc). PDFViewCtrl is highly configurable allowing 
// users to implement custom tools or to modify behavior of built-in tools. 
// Default user interface elements such as the navigation panel can be replaced 
// with a custom implementation and users can override window events and various 
// document actions. For example, by default, PDFViewCtrl will launch URL links 
// in a web browser and will jump to a destination for 'GoTo' actions. The default 
// behavior can be overridden using a custom callback function (as shown in the 
// following sample). 
//
// Besides PDFViewCtrl, the C++ version of PDFNet SDK also includes a low-level class
// called PDFView. Because PDFView does not process any window messages and does not 
// implement built-in tools it is only suitable for very low-level control development 
// (e.g. if you would like to implement a control similar to PDFViewCtrl from scratch). 
// The basic use of PDFView is illustrated in PDFView sample project.
//---------------------------------------------------------------------------------------

#include "stdafx.h"
#include "resource.h"
#include <Common/Exception.h>
#include <commdlg.h>
#include <cassert>
#include <PDF/PDFViewCtrl.h>
#include <PDF/PDFDraw.h>
#include <PDF/PDFNet.h>
#include <stdlib.h>
#include <iostream>
#include <utility>
#include <algorithm>
#include <memory>
#include "../../LicenseKey/CPP/LicenseKey.h"

using namespace pdftron;
using namespace PDF;

#define MAX_LOADSTRING 100

// Global Variables:
HINSTANCE hInst;								// current instance
TCHAR szTitle[MAX_LOADSTRING];					// The title bar text
TCHAR szWindowClass[MAX_LOADSTRING];			// the main window class name
UString m_doc_name;
std::auto_ptr<PDF::PDFDoc> mp_doc;
std::auto_ptr<PDF::PDFViewCtrl> m_view;


// Forward declarations of functions included in this code module:
ATOM				MyRegisterClass(HINSTANCE hInstance);
BOOL				InitInstance(HINSTANCE, int);
LRESULT CALLBACK	WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK	About(HWND, UINT, WPARAM, LPARAM);

int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
	UNREFERENCED_PARAMETER(hPrevInstance);
	UNREFERENCED_PARAMETER(lpCmdLine);

 	// TODO: Place code here.
	MSG msg;
	HACCEL hAccelTable;

	// Initialize global strings
	LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
	LoadString(hInstance, IDC_PDFVIEWSIMPLE, szWindowClass, MAX_LOADSTRING);
	MyRegisterClass(hInstance);

	// Perform application initialization:
	if (!InitInstance (hInstance, nCmdShow))
	{
		return FALSE;
	}

	hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_PDFVIEWSIMPLE));

	// Main message loop:
	while (GetMessage(&msg, NULL, 0, 0))
	{
		if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}

	return (int) msg.wParam;
}



//
//  FUNCTION: MyRegisterClass()
//
//  PURPOSE: Registers the window class.
//
//  COMMENTS:
//
//    This function and its usage are only necessary if you want this code
//    to be compatible with Win32 systems prior to the 'RegisterClassEx'
//    function that was added to Windows 95. It is important to call this function
//    so that the application will get 'well formed' small icons associated
//    with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
	WNDCLASSEX wcex;

	wcex.cbSize = sizeof(WNDCLASSEX);

	wcex.style			= CS_HREDRAW | CS_VREDRAW;
	wcex.lpfnWndProc	= WndProc;
	wcex.cbClsExtra		= 0;
	wcex.cbWndExtra		= 0;
	wcex.hInstance		= hInstance;
	wcex.hIcon			= LoadIcon(hInstance, MAKEINTRESOURCE(IDI_PDFVIEWSIMPLE));
	wcex.hCursor		= LoadCursor(NULL, IDC_ARROW);
	wcex.hbrBackground	= (HBRUSH)(COLOR_WINDOW+1);
	wcex.lpszMenuName	= MAKEINTRESOURCE(IDC_PDFVIEWSIMPLE);
	wcex.lpszClassName	= szWindowClass;
	wcex.hIconSm		= LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));

	return RegisterClassEx(&wcex);
}


typedef std::pair< int, PDF::PDFViewCtrl::ToolMode > ToolModeMapType;
const ToolModeMapType toolModeMap[] = {
	ToolModeMapType( IDM_TOOL_PAN                   , PDF::PDFViewCtrl::e_pan ),
	ToolModeMapType( IDM_TOOL_STRUCTURALSELECTION   , PDF::PDFViewCtrl::e_text_struct_select ),
	ToolModeMapType( IDM_TOOL_RECTANGLESELECTION    , PDF::PDFViewCtrl::e_text_rect_select ),
	ToolModeMapType( IDM_TOOL_RECTANGLEZOOMIN       , PDF::PDFViewCtrl::e_zoom_in ),
	ToolModeMapType( IDM_TOOL_RECTANGLEZOOMOUT      , PDF::PDFViewCtrl::e_zoom_out ),
	ToolModeMapType( IDM_TOOL_ANNOTATIONEDITING     , PDF::PDFViewCtrl::e_annot_edit ),
	ToolModeMapType( IDM_TOOL_TEXTANNOTCREATION     , PDF::PDFViewCtrl::e_text_annot_create ),
	ToolModeMapType( IDM_TOOL_LINECREATION          , PDF::PDFViewCtrl::e_line_create ),
	ToolModeMapType( IDM_TOOL_ARROWCREATION         , PDF::PDFViewCtrl::e_arrow_create ),
	ToolModeMapType( IDM_TOOL_RECTANGLECREATION     , PDF::PDFViewCtrl::e_rect_create ),
	ToolModeMapType( IDM_TOOL_OVALCREATION          , PDF::PDFViewCtrl::e_oval_create ),
	ToolModeMapType( IDM_TOOL_FREEHANDTOOL          , PDF::PDFViewCtrl::e_ink_create ),
	ToolModeMapType( IDM_TOOL_STAMPCREATIONTOOL     , PDF::PDFViewCtrl::e_stamp_create ),
	ToolModeMapType( ID_TOOL_HIGHLIGHTTOOL          , PDF::PDFViewCtrl::e_highlight_create ),
	ToolModeMapType( ID_TOOL_UNDERLINETOOL          , PDF::PDFViewCtrl::e_underline_create ),
	ToolModeMapType( ID_TOOL_STRIKEOUTTOOL          , PDF::PDFViewCtrl::e_strikeout_create ),
	ToolModeMapType( ID_TOOL_SQUIGGLYUNDERLINETOOL  , PDF::PDFViewCtrl::e_squiggly_create ),
	ToolModeMapType( ID_TOOL_CALLOUTTEXTBOXTOOL     , PDF::PDFViewCtrl::e_calloutbox_create ),
	ToolModeMapType( ID_TOOL_SIMPLETEXTBOXTOOL      , PDF::PDFViewCtrl::e_text_box_create ),
	ToolModeMapType( ID_TOOL_POLYGONTOOL            , PDF::PDFViewCtrl::e_polygon_create ),
	ToolModeMapType( ID_TOOL_POLYLINETOOL           , PDF::PDFViewCtrl::e_polyline_create ),
	ToolModeMapType( ID_TOOL_FILEATTACHMENTTOOL     , PDF::PDFViewCtrl::e_file_attachment ),
	ToolModeMapType( ID_TOOL_SOUNDATTACHMENTTOOL    , PDF::PDFViewCtrl::e_sound_attachment ),
	ToolModeMapType( ID_TOOL_MOVIEINSERTIONTOOL     , PDF::PDFViewCtrl::e_movie_attachment ),
	ToolModeMapType( ID_TOOL_CARETPLACEMENTTOOL     , PDF::PDFViewCtrl::e_caret_create ),
	ToolModeMapType( ID_TOOL_REDACTIONTOOL          , PDF::PDFViewCtrl::e_redaction_create ),
	ToolModeMapType( ID_TOOL_TEXTFIELDCREATION      , PDF::PDFViewCtrl::e_text_field_create ),
	ToolModeMapType( ID_TOOL_CHECKBOXCREATIONTOOL   , PDF::PDFViewCtrl::e_check_box_create ),
	ToolModeMapType( ID_TOOL_RADIOBUTTON            , PDF::PDFViewCtrl::e_radio_button_create ),
	ToolModeMapType( ID_TOOL_LISTBOX                , PDF::PDFViewCtrl::e_list_box_create ),
	ToolModeMapType( ID_TOOL_COMBOBOX               , PDF::PDFViewCtrl::e_combo_box_create ),
	ToolModeMapType( ID_TOOL_BUTTONCREATIONTOOL     , PDF::PDFViewCtrl::e_button_create )
};
const ToolModeMapType* const toolModeMapEnd = toolModeMap + sizeof(toolModeMap)/sizeof(ToolModeMapType);
struct ToolModePred {
	int m_code;
	ToolModePred( int c ) : m_code(c) {}
	bool operator()( ToolModeMapType tp ) { return tp.first == m_code; }
};



//   FUNCTION: InitInstance(HINSTANCE, int)
//
//   PURPOSE: Saves instance handle and creates main window
//
//   COMMENTS:
//
//        In this function, we save the instance handle in a global variable and
//        create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
	PDFNet::Initialize(LicenseKey);
	// PDFNet::SetColorManagement();

	HWND hWnd;
	hInst = hInstance; // Store instance handle in our global variable

		hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
		CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);


	if (!hWnd)
	{
		return FALSE;
	}

	ShowWindow(hWnd, nCmdShow);

	// Optional: PDFViewCtrl can save its UI state across different sessions.
	// In this case the config file is save in the current working folder.
	//m_view->LoadCurrentConfiguration( "my.cfg" );  
	UpdateWindow(hWnd);

	return TRUE;
}

void ErrorCallback(const char* message, void* custom_data) 
{
	static bool reported_once = false;
	if (!reported_once) {
		reported_once = true;
		HWND hwnd = (HWND) custom_data;  // Case custom data to the expected argument.
		::MessageBoxA(hwnd, message, "Error", MB_OK);
	}
}

void DownloadCallback(DownloadedType type, PDFDoc* doc, int page_num, int obj_num, const char* message, void* custom_data)
{
	switch(type)
	{
		case PDF::e_downloadedtype_opened :
			// e_opened indicates that we have a valid, but incomplete PDFDoc.
			// the PDF should be treated as read only, and only simple functions
			// should be called on the doc, until e_finished has been called.
			break;
		case PDF::e_downloadedtype_page :
			// this indicates the entire page is downloaded and it is safe to modify
			// for example add a new annotation
			break;
		case PDF::e_downloadedtype_finished :
			{
				// we now have the full PDF file and it can be treated like any other
				HWND hwnd = (HWND) custom_data;  // Case custom data to the expected argument.
				if(::MessageBoxA(hwnd, "Download complete, would you like to save the PDF locally?", 
					"PDF Downloaded", MB_YESNO)==IDYES)
				{
					::PostMessage(hwnd, WM_COMMAND, MAKELONG(IDM_FILE_SAVEAS,0), 0);
				}
			}
			break;
		case PDF::e_downloadedtype_failed :
			{
				// downloading has stopped if this occurs
				HWND hwnd = (HWND) custom_data;  // Case custom data to the expected argument.
				::MessageBoxA(hwnd, message, "Error", MB_OK);
			}
			break;
	}
}

TRN_Bool MyActionHandler( TRN_Action act, void* custom_data )
{
	Action action(act);
	if (!action.IsValid()) return 1;

	HWND hwnd = (HWND) custom_data;  // Case custom data to the expected argument.

	Action::Type type = action.GetType();
	if (type == Action::e_GoTo) 
	{
		Destination dest = action.GetDest();
		if (!dest.IsValid()) {
			MessageBoxA(hwnd, "Destination is not valid", "MyURLActionHandler", MB_OK | MB_ICONEXCLAMATION);
		}
		else {
			int page_num = dest.GetPage().GetIndex();
			char buf[256];
			sprintf(buf, "  Links to: page number %d in this document", page_num);
			MessageBoxA(hwnd, buf, "MyURLActionHandler", MB_OK | MB_ICONEXCLAMATION);
			return 0;  // -> execute the default action handler.
		}
	}
	else if (type == Action::e_URI) 
	{						
		UString uri;
		action.GetSDFObj().Get("URI").Value().GetAsPDFText(uri);

		char buf[256];
		sprintf(buf, "  Links to: %s", uri.ConvertToAscii().c_str());
		MessageBoxA(hwnd, buf, "MyURLActionHandler", MB_OK);
	}
	else  
	{
		MessageBoxA(hwnd, "Other Action Type -> Handled by PDFViewCtrl", "MyURLActionHandler", MB_OK);
		return 0;  // -> execute the default action handler.
	}

	// If this function returns true, PDFViewCtrl will not execute the default 
	// action internally (in case of URL the default action is to open the URL 
	// link in a web browser).
	return 1;
}

TRN_Bool MyMouseDoubleClickEvent( PDFViewCtrl::MouseEvent* evt, void* custom_data) 
{
	if (!evt->m_pdfviewctrl_processed) // Display the message box before the message is processed by PDFNet?
	{
		HWND hwnd = (HWND) custom_data;  // Case custom data to the expected argument.
		MessageBoxA(hwnd, "Example of a custom event", "MyMouseDoubleClickEvent", MB_OK);
		return false;  // execute built-in event. To skip event processing in PDFViewCtrl return true.
	}
	return false;
}

BOOL OpenURLProc(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam)
{
	switch( iMessage ){
	case WM_COMMAND:
		switch( LOWORD( wParam ) ){
			case IDOK :
				{
					char url[MAX_PATH];
					char pass[MAX_PATH];
					GetDlgItemTextA(hDlg, IDC_OPENURL_URL, url, MAX_PATH);
					GetDlgItemTextA(hDlg, IDC_OPENURL_PASSWORD, pass, MAX_PATH);
					m_view->CloseDoc();
					mp_doc.reset();
					// Open a PDF file at the given url. This works best with PDF's that
					// are linearized, as pages can be downloaded and viewed in random access order,
					// without the need to download the entire document. A viewing session can also be
					// persisted across multiple viewing/application sessions to remove redundant downloads 
					// and improve overall performance by using the optional cache_file parameter.
					m_view->OpenURLAsync(&url[0], "", &pass[0]);
					// IMPORTANT: PDFViewCtrl 'owns' downloaded documents, so don't take
					// ownership of the document (mp_doc == null)
				}
				// fall through
			case IDCANCEL:
				EndDialog(hDlg, wParam);
				return TRUE;
		}
		break;
	}
	return FALSE;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	int wmId, wmEvent;
	PAINTSTRUCT ps;
	HDC hdc;
	static HMENU hMenu ;

	switch (message)
	{
	case WM_CREATE:
		{
			m_view = std::auto_ptr<pdftron::PDF::PDFViewCtrl>(new pdftron::PDF::PDFViewCtrl(hWnd, hInst));
			hMenu = LoadMenu (hInst, MAKEINTRESOURCE(IDC_PDFVIEWSIMPLE));
			hMenu = GetSubMenu (hMenu, 0);

			// m_view->SetProgressiveRendering(false);
			// m_view->SetPageBorderVisibility(false);
			// m_view->SetPageSpacing(0, 0, 0, 0);
			// m_view->SetDefaultPageColor(255, 255, 255);
			// m_view->ShowNavPanel(true);
			// m_view->ShowNavToolbar(true);
			// m_view->SetAntiAliasing( true );
			// m_view->SetGamma(0.01);

			m_view->SetErrorReportHandler(ErrorCallback, hWnd);
			m_view->SetActionHandler(MyActionHandler, hWnd);
			m_view->SetDownloadReportHandler(DownloadCallback, hWnd);

			PDFViewCtrl::EventHandlers my_handlers;
			my_handlers.mouse_left_dclick = MyMouseDoubleClickEvent;
			my_handlers.custom_data = hWnd;
			m_view->SetCustomEventHandlers( &my_handlers );
		}
		break;

	case WM_COMMAND:
		{
			wmId = LOWORD(wParam);
			wmEvent = HIWORD(wParam);

			const ToolModeMapType* const wmId_it = std::find_if( toolModeMap, toolModeMapEnd, ToolModePred(wmId) );
			if( wmId_it != toolModeMapEnd )
				m_view->SetToolMode( wmId_it->second );
			else {

				switch (wmId)
				{
				case IDM_ABOUT:
					// DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
					break;
				case IDM_EXIT:
					DestroyWindow(hWnd);
					break;
				case IDM_FILE_PRINT:
					{
						if(m_view->GetDoc())
							m_view->Print();
					}
					break;
				case IDM_FILE_SAVEAS:
					{
						if(m_view->GetDoc())
						{
							TCHAR szFile[256] = { 0 };
							TCHAR *szFilter =TEXT("PDF Files (*.pdf)\0")
								TEXT("*.pdf\0")
								TEXT("All Files\0")
								TEXT("*.*\0");
							OPENFILENAME ofn;
							ZeroMemory(&ofn, sizeof(OPENFILENAME));
							ofn.lStructSize=sizeof(OPENFILENAME);
							ofn.lpstrFilter=szFilter;
							ofn.nFilterIndex=1;
							ofn.lpstrFile=szFile;
							ofn.nMaxFile=sizeof(szFile);
							ofn.lpstrTitle=_T("Save PDF File");
							ofn.nMaxFileTitle=sizeof(ofn.lpstrFile);
							//===Start the File Dialog
							if(GetSaveFileName(&ofn))
							{
								m_view->GetDoc()->Save(UString(ofn.lpstrFile), SDF::SDFDoc::e_linearized, 0);
							}
						}
					}
					break;
				case IDM_FILE_SAVE:
					{
						if(m_view->GetDoc())
						{
							if(m_view->GetDoc())
							{
								m_view->GetDoc()->Save(m_doc_name, SDF::SDFDoc::e_remove_unused, 0);	
							}
						}
					}
					break;
				case IDM_FILE_OPEN:
					{
						//===File path
						TCHAR szFile[256] = { 0 };
						//===Filter
						TCHAR *szFilter =TEXT("PDF Files (*.pdf)\0")
							TEXT("*.pdf\0")
							TEXT("All Files\0")
							TEXT("*.*\0");
						OPENFILENAME ofn;
						ZeroMemory(&ofn, sizeof(OPENFILENAME));
						ofn.lStructSize=sizeof(OPENFILENAME);
						ofn.lpstrFilter=szFilter;
						ofn.nFilterIndex=1;
						ofn.lpstrFile=szFile;
						ofn.nMaxFile=sizeof(szFile);
						ofn.lpstrTitle=_T("Open PDF File");
						ofn.nMaxFileTitle=sizeof(ofn.lpstrFile);
						//===Start the File Dialog
						if(GetOpenFileName(&ofn))
						{
							m_doc_name=UString(ofn.lpstrFile);
							try{
								std::auto_ptr<PDF::PDFDoc> doc(new PDF::PDFDoc(m_doc_name));
								if(m_view->SetDoc(*doc)) 
								{
									mp_doc=doc;
									// m_view->ShowNavPanel(true);
									// m_view->ShowNavToolbar(true);
								}
							}
							catch(...)
							{
								::MessageBoxA(hWnd,"An error occurred while opening a file","PDFViewSimple Error",MB_OK);
							}
						}
					}
					break;
				case IDM_FILE_OPENURL:
					{
						::DialogBox(hInst, MAKEINTRESOURCE(IDD_OPENURL), hWnd, DLGPROC(OpenURLProc));
					}
					break;
				case IDM_PAGELAYOUT_SINGLEPAGE:
					{
						m_view->SetPagePresentationMode(PDF::PDFViewCtrl::e_single_page);
					}
					break;
				case IDM_PAGELAYOUT_SINGLECONTINUOUS:
					{
						if(m_view->GetDoc())
						{
							m_view->SetPagePresentationMode(PDF::PDFViewCtrl::e_single_continuous);
						}
					}
					break;
				case IDM_PAGELAYOUT_FACING:
					{
						m_view->SetPagePresentationMode(PDF::PDFViewCtrl::e_facing);
					}
					break;
				case IDM_PAGELAYOUT_FACINGCONTINUOUS:
					{
						if(m_view->GetDoc())
						{
							m_view->SetPagePresentationMode(PDF::PDFViewCtrl::e_facing_continuous);
						}
					}
					break;
				case IDM_PAGELAYOUT_FACING_COVER:
					{
						if(m_view->GetDoc())
						{
							m_view->SetPagePresentationMode(PDF::PDFViewCtrl::e_facing_cover);
						}
					}
					break;
				case IDM_PAGELAYOUT_FACINGCONTINUOUS_COVER:
					{
						if(m_view->GetDoc())
						{
							m_view->SetPagePresentationMode(PDF::PDFViewCtrl::e_facing_continuous_cover);
						}
					}
					break;
				case IDM_PAGEVIEWMODE_FITPAGE:
					{
						m_view->SetPageViewMode(PDF::PDFViewCtrl::e_fit_page);
					}
					break;
				case IDM_PAGEVIEWMODE_FITWIDTH:
					{
						m_view->SetPageViewMode(PDF::PDFViewCtrl::e_fit_width);
					}
					break;
				case IDM_VIEW_ZOOMIN:
					{
						if(m_view->GetDoc())
						{
							m_view->SetZoom(m_view->GetZoom()*2);
						}
					}
					break;
				case IDM_VIEW_ZOOMOUT:
					{
						if(m_view->GetDoc())
						{
							m_view->SetZoom(m_view->GetZoom()/2);
						}
					}
					break;
				case IDM_PAGENAVIGATION_GOTONEXTPAGE:
					{
						if(m_view->GetDoc())
						{
							m_view->GotoNextPage();
						}
					}
					break;
				case IDM_PAGENAVIGATION_GOTOPREVIOUSPAGE:
					{
						if(m_view->GetDoc())
						{
							m_view->GotoPreviousPage();
						}
					}
					break;
				case IDM_PAGENAVIGATION_GOT:
					{
						if(m_view->GetDoc())
						{
							m_view->GotoLastPage();
						}
					}
					break;
				case IDM_PAGENAVIGATION_GOTOFIRSTPAGE:
					{
						if(m_view->GetDoc())
						{
							m_view->GotoFirstPage();
						}
					}
					break;
				case IDM_EDIT_COPY:
					{
						if(m_view->GetDoc())
						{
							m_view->Copy();
						}
					}
					break;
				case IDM_EDIT_FIND:
					{
						if(m_view->GetDoc())
						{
							m_view->Find();
						}
					}
					break;
				case IDM_EDIT_SELECTALL:
					{
						if(m_view->GetDoc())
						{
							m_view->SelectAll();
						}
					}
					break;
				case ID_TOGGLE_NAV_PANEL:
					m_view->ShowNavPanel(!m_view->IsNavPanelVisible());
					break;
				default:
					return DefWindowProc(hWnd, message, wParam, lParam);
				}
			}
		}
		break;
	case WM_PAINT:
		hdc = BeginPaint(hWnd, &ps);
		// TODO: Add any drawing code here...
		EndPaint(hWnd, &ps);
		break;
	case WM_CLOSE:
		//m_view->SaveCurrentConfiguration("my.cfg");
		m_view.reset();
		DestroyWindow(hWnd);
		return 0;
	case WM_DESTROY:
		PostQuitMessage(0);
		return 0;
	case WM_SIZE:
		// this is never getting called, wxWidgets handles these events internally
		break;
	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
	}
	return 0;
}

// Message handler for about box.
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
	UNREFERENCED_PARAMETER(lParam);
	switch (message)
	{
	case WM_INITDIALOG:
		return (INT_PTR)TRUE;

	case WM_COMMAND:
		if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
		{
			EndDialog(hDlg, LOWORD(wParam));
			return (INT_PTR)TRUE;
		}
		break;
	}
	return (INT_PTR)FALSE;
}
```

{% endcode %}
{% endtab %}

{% tab title="VB" %}
{% code lineNumbers="true" %}

```vb
Imports System
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms

Imports pdftron
Imports pdftron.PDF
Imports pdftron.Filters
Imports pdftron.Common
Imports pdftron.SDF

Namespace PDFViewSimpleTestVB
    Module PDFViewSimpleTestVB
        Dim pdfNetLoader As PDFNetLoader
        Sub New()
            pdfNetLoader = pdftron.PDFNetLoader.Instance()
        End Sub

        <STAThread()> Sub Main()
            PDFNet.Initialize(PDFTronLicense.Key)
            Application.Run(New PDFViewSimple)
        End Sub
    End Module
End Namespace

Public Class PDFViewSimple
    Inherits System.Windows.Forms.Form
    Private components As System.ComponentModel.IContainer
    Private mainMenu1 As System.Windows.Forms.MainMenu
    Private menuItem1 As System.Windows.Forms.MenuItem
    Private menuItem5 As System.Windows.Forms.MenuItem
    Private WithEvents MenuFileOpen As System.Windows.Forms.MenuItem
    Private WithEvents MenuFileExit As System.Windows.Forms.MenuItem
    Private _pdfview As PDFViewCtrl
    Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem
    Friend WithEvents MenuItem3 As System.Windows.Forms.MenuItem
    Friend WithEvents MenuViewZoomIn As System.Windows.Forms.MenuItem
    Friend WithEvents MenuViewZoomOut As System.Windows.Forms.MenuItem
    Friend WithEvents MenuItem4 As System.Windows.Forms.MenuItem
    Friend WithEvents MenuItem6 As System.Windows.Forms.MenuItem
    Friend WithEvents MenuItem7 As System.Windows.Forms.MenuItem
    Friend WithEvents MenuFileSave As System.Windows.Forms.MenuItem
    Friend WithEvents MenuFileSaveAs As System.Windows.Forms.MenuItem
    Friend WithEvents MenuFilePrint As System.Windows.Forms.MenuItem
    Friend WithEvents MenuEditFind As System.Windows.Forms.MenuItem
    Friend WithEvents MenuEditCopy As System.Windows.Forms.MenuItem
    Friend WithEvents MenuEditSelectAll As System.Windows.Forms.MenuItem
    Friend WithEvents MenuItem14 As System.Windows.Forms.MenuItem
    Friend WithEvents MenuSinglePage As System.Windows.Forms.MenuItem
    Friend WithEvents MenuSingleContinuous As System.Windows.Forms.MenuItem
    Friend WithEvents MenuFacing As System.Windows.Forms.MenuItem
    Friend WithEvents MenuFacingContinuous As System.Windows.Forms.MenuItem
    Friend WithEvents MenuItem15 As System.Windows.Forms.MenuItem
    Friend WithEvents MenuFitPage As System.Windows.Forms.MenuItem
    Friend WithEvents MenuFitWidth As System.Windows.Forms.MenuItem
    Friend WithEvents MenuToolPan As System.Windows.Forms.MenuItem
    Friend WithEvents MenuGotoNext As System.Windows.Forms.MenuItem
    Friend WithEvents MenuHelpAbout As System.Windows.Forms.MenuItem
    Friend WithEvents MenuGotoPrev As System.Windows.Forms.MenuItem
    Friend WithEvents MenuGotoLast As System.Windows.Forms.MenuItem
    Friend WithEvents MenuGotoFirst As System.Windows.Forms.MenuItem
    Friend WithEvents MenuToolStructSelect As System.Windows.Forms.MenuItem
    Friend WithEvents MenuToolRectSelect As System.Windows.Forms.MenuItem
    Friend WithEvents MenuToolRectZoomIn As System.Windows.Forms.MenuItem
    Friend WithEvents MenuToolRectZoomOut As System.Windows.Forms.MenuItem
    Friend WithEvents MenuToolAnnotEdit As System.Windows.Forms.MenuItem
    Friend WithEvents MenuToolLineCreate As System.Windows.Forms.MenuItem
    Friend WithEvents MenuToolRectCreate As System.Windows.Forms.MenuItem
    Friend WithEvents MenuToolOvalCreate As System.Windows.Forms.MenuItem
    Friend WithEvents MenuToolArrayCreate As System.Windows.Forms.MenuItem
    Friend WithEvents MenuToolFreeHand As System.Windows.Forms.MenuItem
    Private _pdfdoc As PDFDoc

    Public Sub New()
        InitializeComponent()
        _pdfview = New PDFViewCtrl
        _pdfview.Location = New System.Drawing.Point(0, 0)
        _pdfview.Dock = System.Windows.Forms.DockStyle.Fill
        Controls.Add(_pdfview)
    End Sub

    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Me.mainMenu1 = New System.Windows.Forms.MainMenu
        Me.menuItem1 = New System.Windows.Forms.MenuItem
        Me.MenuFileOpen = New System.Windows.Forms.MenuItem
        Me.MenuFileSave = New System.Windows.Forms.MenuItem
        Me.MenuFileSaveAs = New System.Windows.Forms.MenuItem
        Me.MenuFilePrint = New System.Windows.Forms.MenuItem
        Me.menuItem5 = New System.Windows.Forms.MenuItem
        Me.MenuFileExit = New System.Windows.Forms.MenuItem
        Me.MenuItem2 = New System.Windows.Forms.MenuItem
        Me.MenuEditFind = New System.Windows.Forms.MenuItem
        Me.MenuEditCopy = New System.Windows.Forms.MenuItem
        Me.MenuEditSelectAll = New System.Windows.Forms.MenuItem
        Me.MenuItem3 = New System.Windows.Forms.MenuItem
        Me.MenuItem14 = New System.Windows.Forms.MenuItem
        Me.MenuSinglePage = New System.Windows.Forms.MenuItem
        Me.MenuSingleContinuous = New System.Windows.Forms.MenuItem
        Me.MenuFacing = New System.Windows.Forms.MenuItem
        Me.MenuFacingContinuous = New System.Windows.Forms.MenuItem
        Me.MenuItem15 = New System.Windows.Forms.MenuItem
        Me.MenuFitPage = New System.Windows.Forms.MenuItem
        Me.MenuFitWidth = New System.Windows.Forms.MenuItem
        Me.MenuViewZoomIn = New System.Windows.Forms.MenuItem
        Me.MenuViewZoomOut = New System.Windows.Forms.MenuItem
        Me.MenuItem4 = New System.Windows.Forms.MenuItem
        Me.MenuToolPan = New System.Windows.Forms.MenuItem
        Me.MenuToolStructSelect = New System.Windows.Forms.MenuItem
        Me.MenuToolRectSelect = New System.Windows.Forms.MenuItem
        Me.MenuToolRectZoomIn = New System.Windows.Forms.MenuItem
        Me.MenuToolRectZoomOut = New System.Windows.Forms.MenuItem
        Me.MenuToolAnnotEdit = New System.Windows.Forms.MenuItem
        Me.MenuToolLineCreate = New System.Windows.Forms.MenuItem
        Me.MenuToolRectCreate = New System.Windows.Forms.MenuItem
        Me.MenuToolOvalCreate = New System.Windows.Forms.MenuItem
        Me.MenuToolArrayCreate = New System.Windows.Forms.MenuItem
        Me.MenuToolFreeHand = New System.Windows.Forms.MenuItem
        Me.MenuItem6 = New System.Windows.Forms.MenuItem
        Me.MenuGotoNext = New System.Windows.Forms.MenuItem
        Me.MenuGotoPrev = New System.Windows.Forms.MenuItem
        Me.MenuGotoLast = New System.Windows.Forms.MenuItem
        Me.MenuGotoFirst = New System.Windows.Forms.MenuItem
        Me.MenuItem7 = New System.Windows.Forms.MenuItem
        Me.MenuHelpAbout = New System.Windows.Forms.MenuItem
        Me.SuspendLayout()
        '
        'mainMenu1
        '
        Me.mainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.menuItem1, Me.MenuItem2, Me.MenuItem3, Me.MenuItem4, Me.MenuItem6, Me.MenuItem7})
        '
        'menuItem1
        '
        Me.menuItem1.Index = 0
        Me.menuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuFileOpen, Me.MenuFileSave, Me.MenuFileSaveAs, Me.MenuFilePrint, Me.menuItem5, Me.MenuFileExit})
        Me.menuItem1.Text = "File"
        '
        'MenuFileOpen
        '
        Me.MenuFileOpen.Index = 0
        Me.MenuFileOpen.Text = "Open"
        '
        'MenuFileSave
        '
        Me.MenuFileSave.Index = 1
        Me.MenuFileSave.Text = "Save"
        '
        'MenuFileSaveAs
        '
        Me.MenuFileSaveAs.Index = 2
        Me.MenuFileSaveAs.Text = "Save As"
        '
        'MenuFilePrint
        '
        Me.MenuFilePrint.Index = 3
        Me.MenuFilePrint.Text = "Print"
        '
        'menuItem5
        '
        Me.menuItem5.Index = 4
        Me.menuItem5.Text = "-"
        '
        'MenuFileExit
        '
        Me.MenuFileExit.Index = 5
        Me.MenuFileExit.Text = "Exit"
        '
        'MenuItem2
        '
        Me.MenuItem2.Index = 1
        Me.MenuItem2.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuEditFind, Me.MenuEditCopy, Me.MenuEditSelectAll})
        Me.MenuItem2.Text = "Edit"
        '
        'MenuEditFind
        '
        Me.MenuEditFind.Index = 0
        Me.MenuEditFind.Text = "Find..."
        '
        'MenuEditCopy
        '
        Me.MenuEditCopy.Index = 1
        Me.MenuEditCopy.Text = "Copy"
        '
        'MenuEditSelectAll
        '
        Me.MenuEditSelectAll.Index = 2
        Me.MenuEditSelectAll.Text = "Select All"
        '
        'MenuItem3
        '
        Me.MenuItem3.Index = 2
        Me.MenuItem3.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem14, Me.MenuItem15, Me.MenuViewZoomIn, Me.MenuViewZoomOut})
        Me.MenuItem3.Text = "View"
        '
        'MenuItem14
        '
        Me.MenuItem14.Index = 0
        Me.MenuItem14.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuSinglePage, Me.MenuSingleContinuous, Me.MenuFacing, Me.MenuFacingContinuous})
        Me.MenuItem14.Text = "Page Layout"
        '
        'MenuSinglePage
        '
        Me.MenuSinglePage.Index = 0
        Me.MenuSinglePage.Text = "Single Page"
        '
        'MenuSingleContinuous
        '
        Me.MenuSingleContinuous.Index = 1
        Me.MenuSingleContinuous.Text = "Single Continuous"
        '
        'MenuFacing
        '
        Me.MenuFacing.Index = 2
        Me.MenuFacing.Text = "Facing"
        '
        'MenuFacingContinuous
        '
        Me.MenuFacingContinuous.Index = 3
        Me.MenuFacingContinuous.Text = "Facing Continuous"
        '
        'MenuItem15
        '
        Me.MenuItem15.Index = 1
        Me.MenuItem15.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuFitPage, Me.MenuFitWidth})
        Me.MenuItem15.Text = "Page ViewMode"
        '
        'MenuFitPage
        '
        Me.MenuFitPage.Index = 0
        Me.MenuFitPage.Text = "Fit Page"
        '
        'MenuFitWidth
        '
        Me.MenuFitWidth.Index = 1
        Me.MenuFitWidth.Text = "Fit Width"
        '
        'MenuViewZoomIn
        '
        Me.MenuViewZoomIn.Index = 2
        Me.MenuViewZoomIn.Text = "Zoom In"
        '
        'MenuViewZoomOut
        '
        Me.MenuViewZoomOut.Index = 3
        Me.MenuViewZoomOut.Text = "Zoom Out"
        '
        'MenuItem4
        '
        Me.MenuItem4.Index = 3
        Me.MenuItem4.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuToolPan, Me.MenuToolStructSelect, Me.MenuToolRectSelect, Me.MenuToolRectZoomIn, Me.MenuToolRectZoomOut, Me.MenuToolAnnotEdit, Me.MenuToolLineCreate, Me.MenuToolRectCreate, Me.MenuToolOvalCreate, Me.MenuToolArrayCreate, Me.MenuToolFreeHand})
        Me.MenuItem4.Text = "Tool"
        '
        'MenuToolPan
        '
        Me.MenuToolPan.Index = 0
        Me.MenuToolPan.Text = "Pan"
        '
        'MenuToolStructSelect
        '
        Me.MenuToolStructSelect.Index = 1
        Me.MenuToolStructSelect.Text = "Structural Selection"
        '
        'MenuToolRectSelect
        '
        Me.MenuToolRectSelect.Index = 2
        Me.MenuToolRectSelect.Text = "Rectangle Selection"
        '
        'MenuToolRectZoomIn
        '
        Me.MenuToolRectZoomIn.Index = 3
        Me.MenuToolRectZoomIn.Text = "Rectangle Zoom In"
        '
        'MenuToolRectZoomOut
        '
        Me.MenuToolRectZoomOut.Index = 4
        Me.MenuToolRectZoomOut.Text = "Rectangle Zoom Out"
        '
        'MenuToolAnnotEdit
        '
        Me.MenuToolAnnotEdit.Index = 5
        Me.MenuToolAnnotEdit.Text = "Annotation Editing"
        '
        'MenuToolLineCreate
        '
        Me.MenuToolLineCreate.Index = 6
        Me.MenuToolLineCreate.Text = "Line Creation"
        '
        'MenuToolRectCreate
        '
        Me.MenuToolRectCreate.Index = 7
        Me.MenuToolRectCreate.Text = "Rectangle Creation"
        '
        'MenuToolOvalCreate
        '
        Me.MenuToolOvalCreate.Index = 8
        Me.MenuToolOvalCreate.Text = "Oval Creation"
        '
        'MenuToolArrayCreate
        '
        Me.MenuToolArrayCreate.Index = 9
        Me.MenuToolArrayCreate.Text = "Arrow Creation"
        '
        'MenuToolFreeHand
        '
        Me.MenuToolFreeHand.Index = 10
        Me.MenuToolFreeHand.Text = "FreeHand Tool"
        '
        'MenuItem6
        '
        Me.MenuItem6.Index = 4
        Me.MenuItem6.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuGotoNext, Me.MenuGotoPrev, Me.MenuGotoLast, Me.MenuGotoFirst})
        Me.MenuItem6.Text = "Page Navigation"
        '
        'MenuGotoNext
        '
        Me.MenuGotoNext.Index = 0
        Me.MenuGotoNext.Text = "Go to Next Page"
        '
        'MenuGotoPrev
        '
        Me.MenuGotoPrev.Index = 1
        Me.MenuGotoPrev.Text = "Go to Previous Page"
        '
        'MenuGotoLast
        '
        Me.MenuGotoLast.Index = 2
        Me.MenuGotoLast.Text = "Go to Last Page"
        '
        'MenuGotoFirst
        '
        Me.MenuGotoFirst.Index = 3
        Me.MenuGotoFirst.Text = "Go to First Page"
        '
        'MenuItem7
        '
        Me.MenuItem7.Index = 5
        Me.MenuItem7.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuHelpAbout})
        Me.MenuItem7.Text = "Help"
        '
        'MenuHelpAbout
        '
        Me.MenuHelpAbout.Index = 0
        Me.MenuHelpAbout.Text = "About..."
        '
        'PDFViewSimple
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(744, 512)
        Me.Menu = Me.mainMenu1
        Me.Name = "PDFViewSimple"
        Me.Text = "PDFViewSimple"
        Me.ResumeLayout(False)

    End Sub

    Private Sub menuFileOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuFileOpen.Click
        Dim dlg As OpenFileDialog = New OpenFileDialog
        dlg.CheckFileExists = True
        dlg.CheckPathExists = True
        dlg.Filter = "PDF (*.pdf)|*.pdf|All files (*.*)|*.*"
        dlg.DefaultExt = ".pdf"
        If dlg.ShowDialog = DialogResult.OK Then
            OpenPDF(dlg.FileName)
        End If
    End Sub

    Public Function OpenPDF(ByVal filename As String) As Boolean
        Try
            'close old document if opening new file was successful
            Dim olddoc As PDFDoc = _pdfview.GetDoc()
            _pdfdoc = New PDFDoc(filename)
            _pdfview.SetDoc(_pdfdoc)

            ' Use built-in navigation (thumbnails, bookmarks, layers, etc)?
            ' _pdfview.ShowNavToolbar(true)
            ' _pdfview.ShowNavPanel(true)

            If Not (olddoc Is Nothing) Then
                olddoc.Dispose()
            End If

        Catch ex As PDFNetException
            MessageBox.Show(ex.Message)
            Return False
        Catch ex As Exception
            MessageBox.Show(ex.ToString)
            Return False
        End Try
        Me.Text = filename
        Return True
    End Function

    Private Sub MenuFileSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuFileSave.Click
        If Not (_pdfdoc Is Nothing) Then
            Me.Save(Me.Text)
        End If
    End Sub

    Private Sub MenuFileSaveAs_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuFileSaveAs.Click
        If Not (_pdfdoc Is Nothing) AndAlso Not (_pdfview Is Nothing) Then
            'opens a save dialog
            Dim dlg As SaveFileDialog = New SaveFileDialog
            dlg.Filter = "PDF Files (*.pdf)|*.pdf|All Files (*.*)|*.*"
            dlg.DefaultExt = ".pdf"
            dlg.FileName = Text
            Dim res As DialogResult = dlg.ShowDialog
            If res = DialogResult.OK Then
                'saves the file
                Me.Save(dlg.FileName)
            End If
        End If
    End Sub

    Public Sub Save(ByVal fileName As String)
        _pdfdoc.Lock()
        Try
            _pdfdoc.Save(fileName, SDFDoc.SaveOptions.e_remove_unused)
        Catch ex As Exception
            MessageBox.Show(ex.ToString(), "Error during the Save")
        End Try
        _pdfdoc.Unlock()
    End Sub

    Private Sub MenuFilePrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuFilePrint.Click
        If Not (_pdfview.GetDoc() Is Nothing) Then
            _pdfview.Print()
        End If
    End Sub

    Private Sub MenuFileExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuFileExit.Click
        PDFNet.Terminate()
        Application.Exit()
    End Sub


    Private Sub MenuEditCopy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuEditCopy.Click
        If Not (_pdfview.GetDoc() Is Nothing) Then
            _pdfview.Copy()
        End If
    End Sub

    Private Sub MenuEditFind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuEditFind.Click
        If Not (_pdfview.GetDoc() Is Nothing) Then
            _pdfview.Find()
        End If
    End Sub

    Private Sub MenuEditSelectAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuEditSelectAll.Click
        If Not (_pdfview.GetDoc() Is Nothing) Then
            _pdfview.SelectAll()
        End If
    End Sub

    Private Sub MenuViewZoomIn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuViewZoomIn.Click
        If Not (_pdfview.GetDoc() Is Nothing) Then
            _pdfview.SetZoom(_pdfview.GetZoom() * 2)
        End If
    End Sub


    Private Sub MenuViewZoomOut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuViewZoomOut.Click
        If Not (_pdfview.GetDoc() Is Nothing) Then
            _pdfview.SetZoom(_pdfview.GetZoom() / 2)
        End If
    End Sub

    Private Sub MenuNextPage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuGotoNext.Click
        If Not (_pdfview.GetDoc() Is Nothing) Then
            _pdfview.GotoNextPage()
        End If
    End Sub

    Private Sub MenuPreviousPage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuGotoPrev.Click
        If Not (_pdfview.GetDoc() Is Nothing) Then
            _pdfview.GotoPreviousPage()
        End If
    End Sub

    Private Sub MenuLastPage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuGotoLast.Click
        If Not (_pdfview.GetDoc() Is Nothing) Then
            _pdfview.GotoLastPage()
        End If
    End Sub

    Private Sub MenuFirstPage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuGotoFirst.Click
        If Not (_pdfview.GetDoc() Is Nothing) Then
            _pdfview.GotoFirstPage()
        End If
    End Sub

    Private Sub MenuPageLayoutSinglePage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuSinglePage.Click
        If Not (_pdfview.GetDoc() Is Nothing) Then
            _pdfview.SetPagePresentationMode(PDFViewCtrl.PagePresentationMode.e_single_page)
        End If
    End Sub

    Private Sub MenuPageLayoutSingleContinous_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuSingleContinuous.Click
        If Not (_pdfview.GetDoc() Is Nothing) Then
            _pdfview.SetPagePresentationMode(PDFViewCtrl.PagePresentationMode.e_single_continuous)
        End If
    End Sub

    Private Sub MenuPageLayoutFacing_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuFacing.Click
        If Not (_pdfview.GetDoc() Is Nothing) Then
            _pdfview.SetPagePresentationMode(PDFViewCtrl.PagePresentationMode.e_facing)
        End If
    End Sub

    Private Sub MenuPageLayoutFacingContinuous_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuFacingContinuous.Click
        If Not (_pdfview.GetDoc() Is Nothing) Then
            _pdfview.SetPagePresentationMode(PDFViewCtrl.PagePresentationMode.e_facing_continuous)
        End If
    End Sub

    Private Sub MenuPageViewModeFitPage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuFitPage.Click
        If Not (_pdfview.GetDoc() Is Nothing) Then
            _pdfview.SetPageViewMode(PDFViewCtrl.PageViewMode.e_fit_page)
        End If
    End Sub

    Private Sub MenuPageViewModeFitWidth_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuFitWidth.Click
        If Not (_pdfview.GetDoc() Is Nothing) Then
            _pdfview.SetPageViewMode(PDFViewCtrl.PageViewMode.e_fit_width)
        End If
    End Sub

    Private Sub MenuToolPan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuToolPan.Click
        _pdfview.SetToolMode(PDFViewCtrl.ToolMode.e_pan)
    End Sub

    Private Sub MenuToolStructuralSelection_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuToolStructSelect.Click
        _pdfview.SetToolMode(PDFViewCtrl.ToolMode.e_text_struct_select)
    End Sub

    Private Sub MenuToolRectangleSelection_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuToolRectSelect.Click
        _pdfview.SetToolMode(PDFViewCtrl.ToolMode.e_text_rect_select)
    End Sub

    Private Sub MenuToolRectangleZoomIn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuToolRectZoomIn.Click
        _pdfview.SetToolMode(PDFViewCtrl.ToolMode.e_zoom_in)
    End Sub

    Private Sub MenuToolRectangleZoomOut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuToolRectZoomOut.Click
        _pdfview.SetToolMode(PDFViewCtrl.ToolMode.e_zoom_out)
    End Sub

    Private Sub MenuToolAnnotationEditing_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuToolAnnotEdit.Click
        _pdfview.SetToolMode(PDFViewCtrl.ToolMode.e_annot_edit)
    End Sub

    Private Sub MenuToolLineCreation_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuToolLineCreate.Click
        _pdfview.SetToolMode(PDFViewCtrl.ToolMode.e_line_create)
    End Sub

    Private Sub MenuToolRectangleCreation_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuToolRectCreate.Click
        _pdfview.SetToolMode(PDFViewCtrl.ToolMode.e_rect_create)
    End Sub

    Private Sub MenuToolOvalCreation_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuToolOvalCreate.Click
        _pdfview.SetToolMode(PDFViewCtrl.ToolMode.e_oval_create)
    End Sub

    Private Sub MenuToolArrowCreation_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuToolArrayCreate.Click
        _pdfview.SetToolMode(PDFViewCtrl.ToolMode.e_arrow_create)
    End Sub

    Private Sub MenuToolFreeHandToolCreation_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuToolFreeHand.Click
        _pdfview.SetToolMode(PDFViewCtrl.ToolMode.e_ink_create)
    End Sub

    Private Sub MenuHelpAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuHelpAbout.Click
        MessageBox.Show("PDFView Sample Application, Version 1.0", "About PDFViewSimple")
    End Sub

End Class
```

{% endcode %}
{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.apryse.com/core/get-started/samples/pdfviewsimpletest.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
