Saving PDF Files in Windows Forms PDF Viewer (PdfViewerControl)

28 Apr 20213 minutes to read

The Save feature in the PdfViewerControl helps you to keep the file up to date with any modifications and prevent your work from being lost by allowing you to save the file in the local disk.

Save option in Toolbar

Save can be performed using the following steps.

  1. Open a PDF file in the PdfViewerControl and do any modifications to the file.
  2. Click the “Save As” icon on the toolbar as shown in the above picture.
  3. In the save dialog box, enter a name, and select “Save”.

Events

The PdfViewerControl notifies you at the start and end of the save operation through the BeginSave and EndSave events respectively.

Before Save

The BeginSave event occurs before initiating the save operation of the PDF file. It also allows you to cancel the save operation through the Cancel property of BeginSaveEventArgs. The following code shows how to wire the event in the PdfViewerControl.

using System.Windows.Forms;
using Syncfusion.Windows.Forms.PdfViewer;

namespace SaveEventsDemo
{
    public partial class Form1 : Form
    {
        #region Constructor
        public Form1()
        {
            InitializeComponent();

            //Wire the `BeginSave` event.
            pdfViewerControl1.BeginSave += PdfViewerControl1_BeginSave;

            //Load the PDF file.
            pdfViewerControl1.Load("../../Data/HTTP Succinctly.pdf");
        }
        #endregion

        #region Events
        private void PdfViewerControl1_BeginSave(object sender, BeginSaveEventArgs e)
        {
            //Insert your code here    
        }
        # endregion
    }
}

After Save

The EndSave event occurs after the completion of the save operation. The following code shows how to wire the event in the PdfViewerControl.

using System.Windows.Forms;
using Syncfusion.Windows.Forms.PdfViewer;

namespace SaveEventsDemo
{
    public partial class Form1 : Form
    {
        #region Constructor
        public Form1()
        {
            InitializeComponent();

            //Wire the `EndSave` event.
            pdfViewerControl1.EndSave += PdfViewerControl1_EndSave;

            //Load the PDF file.
            pdfViewerControl1.Load("../../Data/HTTP Succinctly.pdf");
        }
        #endregion

        #region Events
        private void PdfViewerControl1_EndSave(object sender, EndSaveEventArgs e)
        {
            //Insert your code here
        }
        # endregion
    }
}

NOTE

The complete sample project of the Save Events is available in the GitHub.