Docotic.Pdf Library Help > Samples > General operations > Load an existing PDF document

This sample shows how to load an existing PDF document using PdfDocument.Open method.

Note, that Open method replaces the contents of PDF document with contents of the loaded document.

You can also load an existing PDF document by passing a path to a PDF file and, optionally, password as parameters to PdfDocument class constructor.

C#
using System.Diagnostics;

namespace BitMiracle.Docotic.Pdf.Samples
{
    public static class OpenDocument
    {
        public static void Main()
        {
            // NOTE: 
            // When used in trial mode, the library imposes some restrictions.
            // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx
            // for more information.

            string pathToFile = "OpenDocument.pdf";

            using (PdfDocument pdf = new PdfDocument())
            {
                pdf.Open("Sample data/jfif3.pdf");

                PdfCanvas canvas = pdf.Pages[0].Canvas;
                canvas.Font = pdf.AddFont(PdfBuiltInFont.Helvetica);
                canvas.FontSize = 20;
                canvas.DrawString(10, 80, "This text added by Docotic.Pdf Sample Browser");

                pdf.Save(pathToFile);
            }

            Process.Start(pathToFile);
        }
    }
}
VB
Imports System.Diagnostics

Imports BitMiracle.Docotic.Pdf

Namespace BitMiracle.Docotic.Pdf.Samples
    Public NotInheritable Class OpenDocument
        Public Shared Sub Main()
            ' NOTE: 
            ' When used in trial mode, the library imposes some restrictions.
            ' Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx
            ' for more information.

            Dim pathToFile As String = "OpenDocument.pdf"

            Using pdf As New PdfDocument()
                pdf.Open("Sample data/jfif3.pdf")

                Dim canvas As PdfCanvas = pdf.Pages(0).Canvas
                canvas.Font = pdf.AddFont(PdfBuiltInFont.Helvetica)
                canvas.FontSize = 20
                canvas.DrawString(10, 80, "This text added by Docotic.Pdf Sample Browser")

                pdf.Save(pathToFile)
            End Using

            Process.Start(pathToFile)
        End Sub
    End Class
End Namespace