VintaSoft Imaging .NET SDK 12.4: Documentation for .NET developer
Vintasoft.Imaging.Pdf Namespace / PdfDocumentController Class
Members Object Syntax Remarks Example Hierarchy Requirements SeeAlso
In This Topic
    PdfDocumentController Class
    In This Topic
    Manages opened PDF documents.
    Object Model
    PdfDocumentController
    Syntax
    'Declaration
    
    Public MustInherit NotInheritable Class PdfDocumentController
    
    
    public static class PdfDocumentController
    
    
    public __gc abstract __sealed class PdfDocumentController
    
    
    public ref class PdfDocumentController abstract sealed
    
    
    Remarks

    This class manages access to PDF document and allows to access the single PDF document from several PdfDocument objects. PdfEncoder and PdfDecoder classes uses the PDF document controller to manage PDF documents.

    Example

    Here is an example that shows how to manage external fonts of PDF documents and perform authentication of encrypted PDF documents:

    
    
    ''' <summary>
    ''' Instance of an external font programs controller
    ''' that is used for every opened PDF document.
    ''' </summary>
    Private _fontProgramsController As Vintasoft.Imaging.Fonts.FontProgramsControllerBase
    
    ' MainForm constructor
    Public Sub New()
        '....
    
        ' subscribe to the DocumentOpened event for managing external fonts
        AddHandler Vintasoft.Imaging.Pdf.PdfDocumentController.DocumentOpened, New System.EventHandler(Of Vintasoft.Imaging.Pdf.PdfDocumentEventArgs)(AddressOf PdfDocumentController_DocumentOpened)
        ' subscribe to the AuthenticateRequest for performing authentication
    
            '....
        AddHandler Vintasoft.Imaging.Pdf.PdfDocumentController.AuthenticateRequest, New System.EventHandler(Of Vintasoft.Imaging.Pdf.PdfDocumentEventArgs)(AddressOf PdfDocumentController_AuthenticateRequest)
    End Sub
    
    ''' <summary>
    ''' Opens the PDF document.
    ''' </summary>
    ''' <param name="stream">The stream that contains PDF document.</param>
    Public Sub OpenPdfDocument(stream As System.IO.Stream)
        imageViewer1.Images.Add(stream, True)
    End Sub
    
    ''' <summary>
    ''' Handles the AuthenticateRequest event of the PdfDocumentController object.
    ''' </summary>
    Private Sub PdfDocumentController_AuthenticateRequest(sender As Object, e As Vintasoft.Imaging.Pdf.PdfDocumentEventArgs)
        ' document is encrypted with password, authenticate as user
    
        Dim password As String = "userpassword"
        If e.Document.AuthenticateAsUser(password) = Vintasoft.Imaging.Pdf.Security.AuthorizationResult.IncorrectPassword Then
            System.Windows.Forms.MessageBox.Show("Incorrect user password")
        End If
    End Sub
    
    ''' <summary>
    ''' Handles the DocumentOpened event of the PdfDocumentController control.
    ''' </summary>
    Private Sub PdfDocumentController_DocumentOpened(sender As Object, e As Vintasoft.Imaging.Pdf.PdfDocumentEventArgs)
        ' if the instance is not created yet
        If _fontProgramsController Is Nothing Then
            ' create font programs controller common for all PDF documents
            _fontProgramsController = New Vintasoft.Imaging.Fonts.FileFontProgramsControllerWithFallbackFont(True, "fonts")
        End If
        ' use common font programs controller to manage external fonts
        e.Document.FontProgramsController = _fontProgramsController
    End Sub
    
    
    
    
    /// <summary>
    /// Instance of an external font programs controller
    /// that is used for every opened PDF document.
    /// </summary>
    Vintasoft.Imaging.Fonts.FontProgramsControllerBase _fontProgramsController;
    
    // MainForm constructor
    public MainForm()
    {
        //....
        
        // subscribe to the DocumentOpened event for managing external fonts
        Vintasoft.Imaging.Pdf.PdfDocumentController.DocumentOpened += 
            new System.EventHandler<Vintasoft.Imaging.Pdf.PdfDocumentEventArgs>(PdfDocumentController_DocumentOpened);
        // subscribe to the AuthenticateRequest for performing authentication
        Vintasoft.Imaging.Pdf.PdfDocumentController.AuthenticateRequest += 
            new System.EventHandler<Vintasoft.Imaging.Pdf.PdfDocumentEventArgs>(PdfDocumentController_AuthenticateRequest);
        
        //....
    }
    
    /// <summary>
    /// Opens the PDF document.
    /// </summary>
    /// <param name="stream">The stream that contains PDF document.</param>
    public void OpenPdfDocument(System.IO.Stream stream)
    {
        imageViewer1.Images.Add(stream, true);
    }
    
    /// <summary>
    /// Handles the AuthenticateRequest event of the PdfDocumentController object.
    /// </summary>
    private void PdfDocumentController_AuthenticateRequest(object sender, Vintasoft.Imaging.Pdf.PdfDocumentEventArgs e)
    {
        // document is encrypted with password, authenticate as user
    
        string password = "userpassword";
        if (e.Document.AuthenticateAsUser(password) == Vintasoft.Imaging.Pdf.Security.AuthorizationResult.IncorrectPassword)
            System.Windows.Forms.MessageBox.Show("Incorrect user password");
    }
    
    /// <summary>
    /// Handles the DocumentOpened event of the PdfDocumentController control.
    /// </summary>
    private void PdfDocumentController_DocumentOpened(object sender, Vintasoft.Imaging.Pdf.PdfDocumentEventArgs e)
    {
        // if the instance is not created yet
        if (_fontProgramsController == null)
        {
            // create font programs controller common for all PDF documents
            _fontProgramsController = 
                new Vintasoft.Imaging.Fonts.FileFontProgramsControllerWithFallbackFont(true, "fonts");
        }
        // use common font programs controller to manage external fonts
        e.Document.FontProgramsController = _fontProgramsController;
    }
    
    

    Inheritance Hierarchy

    System.Object
       Vintasoft.Imaging.Pdf.PdfDocumentController

    Requirements

    Target Platforms: .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5

    See Also