VintaSoft Imaging .NET SDK v8.6
In This Topic
    PDF: Load PDF document
    In This Topic

    The SDK allows to load a PDF document compliant with PDF specification version 1.0 - 1.7. Each of loaded PDFs can be secured with ARC4 or AES algorithms. The SDK allows also to load damaged PDF documents.

    Here is an example that demonstrates how to load a non-secured PDF document from file:

    ' The project, which uses this code, must have references to the following assemblies:
    ' - Vintasoft.Imaging.Pdf
    
    Public Shared Function LoadPdfDocumentFromFile(filename As String) As Vintasoft.Imaging.Pdf.PdfDocument
        Return New Vintasoft.Imaging.Pdf.PdfDocument(filename)
    End Function
                  
    
    // The project, which uses this code, must have references to the following assemblies:
    // - Vintasoft.Imaging.Pdf
    
    public static Vintasoft.Imaging.Pdf.PdfDocument LoadPdfDocumentFromFile(string filename)
    {
        return new Vintasoft.Imaging.Pdf.PdfDocument(filename);
    }
                    
    

    Here is an example that demonstrates how to load a PDF document, for case, when it is not known in advance that the PDF document is secured:
    ' The project, which uses this code, must have references to the following assemblies:
    ' - Vintasoft.Imaging.Pdf
    
    Namespace UserGuide.Programming.Pdf.Encryption
        Class OpenPdfDocument
            Public Shared Function Open(filename As String) As Vintasoft.Imaging.Pdf.PdfDocument
                Dim document As New Vintasoft.Imaging.Pdf.PdfDocument(filename)
                If document.IsEncrypted Then
                    While True
                        System.Console.Write("Enter password: ")
                        ' get password string
                        Dim password As String = System.Console.ReadLine()
                        ' performs authentication
                        Dim authorization As Vintasoft.Imaging.Pdf.Security.AuthorizationResult = document.Authenticate(password)
                        ' check authorization result
                        If authorization = Vintasoft.Imaging.Pdf.Security.AuthorizationResult.IncorrectPassword Then
                            System.Console.WriteLine("The password is incorrect.")
                        Else
                            System.Console.WriteLine(authorization.ToString())
                            Exit While
                        End If
                    End While
                End If
                Return document
            End Function
        End Class
    End Namespace
                  
    
    // The project, which uses this code, must have references to the following assemblies:
    // - Vintasoft.Imaging.Pdf
    
    namespace UserGuide.Programming.Pdf.Encryption
    {
        class OpenPdfDocument
        {
            public static Vintasoft.Imaging.Pdf.PdfDocument Open(string filename)
            {
                Vintasoft.Imaging.Pdf.PdfDocument document = 
                    new Vintasoft.Imaging.Pdf.PdfDocument(filename);
                if (document.IsEncrypted)
                {
                    while (true)
                    {
                        System.Console.Write("Enter password: ");
                        // get password string
                        string password = System.Console.ReadLine();
                        // performs authentication
                        Vintasoft.Imaging.Pdf.Security.AuthorizationResult authorization = 
                            document.Authenticate(password);
                        // check authorization result
                        if (authorization == Vintasoft.Imaging.Pdf.Security.AuthorizationResult.IncorrectPassword)
                        {
                            System.Console.WriteLine("The password is incorrect.");
                        }
                        else
                        {
                            System.Console.WriteLine(authorization.ToString());
                            break;
                        }
                    }
                }
                return document;
            }
        }
    }