Класс PdfDocumentController
В этом разделе
Управляет открытыми PDF документами.
Объектная модель
Синтаксис
'Declaration
Public MustInherit NotInheritable Class PdfDocumentController
public static class PdfDocumentController
public __gc abstract __sealed class PdfDocumentController
public ref class PdfDocumentController abstract sealed
Ремарки
Этот класс управляет доступом к PDF документу и позволяет получить доступ к одному PDF документу из нескольких объектов PdfDocument. Классы PdfEncoder и PdfDecoder используют контроллер PDF документов для управления PDF документами.
Пример
Вот пример, показывающий, как управлять внешними шрифтами PDF документов и выполнять аутентификацию зашифрованных PDF документов:
''' <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;
}
Иерархия наследования
System.Object
 Vintasoft.Imaging.Pdf.PdfDocumentController
Требования
Целевые платформы: .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5
Смотрите также