VintaSoft Imaging .NET SDK 14.0: Документация для .NET разработчика
Vintasoft.Imaging.Pdf.Print Namespace / PdfPrintDocument Class
Члены типа Объект Синтаксис Example Иерархия Требования Смотрите также
В этом разделе
    Класс PdfPrintDocument
    В этом разделе
    Отправляет изображения на принтер. Страницы PDF будут распечатаны в векторной форме, другие типы изображений будут распечатаны в растровой форме.
    Объектная модель
    PdfPrintDocument
    Синтаксис
    'Declaration
    
    <ToolboxBitmapAttribute("", null)>
    <DesignerCategoryAttribute("Component")>
    <DefaultPropertyAttribute("DocumentName")>
    <DefaultEventAttribute("PrintPage")>
    <SRDescriptionAttribute("Defines an object that sends output to a printer.")>
    Public Class PdfPrintDocument
       Inherits Vintasoft.Imaging.Print.ImagePrintDocument
    
    
    [ToolboxBitmap("", null)]
    [DesignerCategory("Component")]
    [DefaultProperty("DocumentName")]
    [DefaultEvent("PrintPage")]
    [SRDescription("Defines an object that sends output to a printer.")]
    public class PdfPrintDocument : Vintasoft.Imaging.Print.ImagePrintDocument
    
    
    [ToolboxBitmap("", null)]
    [DesignerCategory("Component")]
    [DefaultProperty("DocumentName")]
    [DefaultEvent("PrintPage")]
    [SRDescription("Defines an object that sends output to a printer.")]
    public __gc class PdfPrintDocument : public Vintasoft.Imaging.Print.ImagePrintDocument*
    
    
    [ToolboxBitmap("", null)]
    [DesignerCategory("Component")]
    [DefaultProperty("DocumentName")]
    [DefaultEvent("PrintPage")]
    [SRDescription("Defines an object that sends output to a printer.")]
    public ref class PdfPrintDocument : public Vintasoft.Imaging.Print.ImagePrintDocument^
    
    
    Пример

    Вот пример, показывающий, как распечатать все PDF страницы документа в режиме BestFit на принтере по умолчанию:

    
    ''' <summary>
    ''' The images, which must be printed.
    ''' </summary>
    Private _images As Vintasoft.Imaging.ImageCollection = Nothing
    
    ''' <summary>
    ''' The index of image, which must be printed
    ''' </summary>
    Private _currentImageIndex As Integer
    
    
    
    ''' <summary>
    ''' Prints the document.
    ''' </summary>
    ''' <param name="documentPath">The document path.</param>
    Public Sub PrintDocument(documentPath As String)
        ' create image collection
        _images = New Vintasoft.Imaging.ImageCollection()
        ' load document
        _images.Add(documentPath)
    
        ' create print manager
        Dim printManager As New Vintasoft.Imaging.Pdf.Print.PdfPrintDocument()
    
        ' update settings of print manager
        SetPrintSettings(printManager)
    
        ' subscribe to the events of print manager
        SubscribeToEvents(printManager)
    
        _currentImageIndex = 0
        ' start the asynchronous printing of document
        printManager.Print()
    End Sub
    
    ''' <summary>
    ''' Sets the print manager settings.
    ''' </summary>
    ''' <param name="printManager">The print manager.</param>
    Private Sub SetPrintSettings(printManager As Vintasoft.Imaging.Pdf.Print.PdfPrintDocument)
        printManager.PrintScaleMode = Vintasoft.Imaging.Print.PrintScaleMode.BestFit
        printManager.Center = True
        printManager.DistanceBetweenImages = 0
        printManager.DistanceBetweenImages = 0
        printManager.MosaicColumnCount = 1
        printManager.MosaicRowCount = 1
        printManager.DefaultPageSettings.Margins = New System.Drawing.Printing.Margins(0, 0, 0, 0)
    End Sub
    
    ''' <summary>
    ''' Subscribes to the events of print manager.
    ''' </summary>
    ''' <param name="printManager">The print manager.</param>
    Private Sub SubscribeToEvents(printManager As Vintasoft.Imaging.Pdf.Print.PdfPrintDocument)
        AddHandler printManager.PrintImage, New System.EventHandler(Of Vintasoft.Imaging.Print.PrintImageEventArgs)(AddressOf PrintManager_PrintImage)
        AddHandler printManager.EndPrint, New System.Drawing.Printing.PrintEventHandler(AddressOf PrintManager_EndPrint)
    End Sub
    
    ''' <summary>
    ''' Unsubscribes from the events of print manager.
    ''' </summary>
    ''' <param name="printManager">The print manager.</param>
    Private Sub UnsubscribeToEvents(printManager As Vintasoft.Imaging.Pdf.Print.PdfPrintDocument)
        RemoveHandler printManager.PrintImage, AddressOf PrintManager_PrintImage
        RemoveHandler printManager.EndPrint, AddressOf PrintManager_EndPrint
    End Sub
    
    ''' <summary>
    ''' Prints images.
    ''' </summary>
    Private Sub PrintManager_PrintImage(sender As Object, e As Vintasoft.Imaging.Print.PrintImageEventArgs)
        ' set image, which must be printed
        e.Image = GetImageForPrinting(_currentImageIndex)
    
        ' move to the next image in print queue
        _currentImageIndex += 1
    
        ' if there are no images to print
        If _currentImageIndex >= _images.Count Then
            ' specify that we do not have images to print
            e.HasMoreImages = False
        Else
            ' specify that we have images to print
            e.HasMoreImages = True
        End If
    End Sub
    
    ''' <summary>
    ''' Returns the image, which must be printed.
    ''' </summary>
    ''' <param name="index">The zero-based index in image collection.</param>
    ''' <returns>
    ''' The image, which must be printed.
    ''' </returns>
    Private Function GetImageForPrinting(index As Integer) As Vintasoft.Imaging.VintasoftImage
        ' if image does not exist
        If index >= _images.Count Then
            Return Nothing
        End If
    
        ' get image from image collection
        Dim image As Vintasoft.Imaging.VintasoftImage = _images(index)
    
        ' get the PDF rendering settings
        Dim renderingSettings As Vintasoft.Imaging.Codecs.Decoders.PdfRenderingSettings = TryCast(image.RenderingSettings, Vintasoft.Imaging.Codecs.Decoders.PdfRenderingSettings)
        ' if PDF rendering settings are not specified
        If renderingSettings Is Nothing Then
            ' create PDF rendering settings
            renderingSettings = New Vintasoft.Imaging.Codecs.Decoders.PdfRenderingSettings()
            image.RenderingSettings = renderingSettings
        End If
    
        ' specify that renderer must draw all PDF image-resources with interpolation,
        ' this prevents stripes in printed image
        renderingSettings.IgnoreImageInterpolateFlag = True
    
        ' returns the image
        Return image
    End Function
    
    ''' <summary>
    ''' Printing is finished.
    ''' </summary>
    Private Sub PrintManager_EndPrint(sender As Object, e As System.Drawing.Printing.PrintEventArgs)
        UnsubscribeToEvents(DirectCast(sender, Vintasoft.Imaging.Pdf.Print.PdfPrintDocument))
    
        _images.ClearAndDisposeItems()
        _images.Dispose()
        _images = Nothing
    End Sub
    
    
    
    /// <summary>
    /// The images, which must be printed.
    /// </summary>
    Vintasoft.Imaging.ImageCollection _images = null;
    
    /// <summary>
    /// The index of image, which must be printed
    /// </summary>
    int _currentImageIndex;
    
    
    
    /// <summary>
    /// Prints the document.
    /// </summary>
    /// <param name="documentPath">The document path.</param>
    public void PrintDocument(string documentPath)
    {
        // create image collection
        _images = new Vintasoft.Imaging.ImageCollection();
        // load document
        _images.Add(documentPath);
    
        // create print manager
        Vintasoft.Imaging.Pdf.Print.PdfPrintDocument printManager =
            new Vintasoft.Imaging.Pdf.Print.PdfPrintDocument();
    
        // update settings of print manager
        SetPrintSettings(printManager);
    
        // subscribe to the events of print manager
        SubscribeToEvents(printManager);
    
        _currentImageIndex = 0;
        // start the asynchronous printing of document
        printManager.Print();
    }
    
    /// <summary>
    /// Sets the print manager settings.
    /// </summary>
    /// <param name="printManager">The print manager.</param>
    private void SetPrintSettings(Vintasoft.Imaging.Pdf.Print.PdfPrintDocument printManager)
    {
        printManager.PrintScaleMode = Vintasoft.Imaging.Print.PrintScaleMode.BestFit;
        printManager.Center = true;
        printManager.DistanceBetweenImages = 0;
        printManager.DistanceBetweenImages = 0;
        printManager.MosaicColumnCount = 1;
        printManager.MosaicRowCount = 1;
        printManager.DefaultPageSettings.Margins = new System.Drawing.Printing.Margins(0, 0, 0, 0);
    }
    
    /// <summary>
    /// Subscribes to the events of print manager.
    /// </summary>
    /// <param name="printManager">The print manager.</param>
    private void SubscribeToEvents(Vintasoft.Imaging.Pdf.Print.PdfPrintDocument printManager)
    {
        printManager.PrintImage +=
            new System.EventHandler<Vintasoft.Imaging.Print.PrintImageEventArgs>(PrintManager_PrintImage);
        printManager.EndPrint += new System.Drawing.Printing.PrintEventHandler(PrintManager_EndPrint);
    }
    
    /// <summary>
    /// Unsubscribes from the events of print manager.
    /// </summary>
    /// <param name="printManager">The print manager.</param>
    private void UnsubscribeToEvents(Vintasoft.Imaging.Pdf.Print.PdfPrintDocument printManager)
    {
        printManager.PrintImage -= PrintManager_PrintImage;
        printManager.EndPrint -= PrintManager_EndPrint;
    }
    
    /// <summary>
    /// Prints images.
    /// </summary>
    private void PrintManager_PrintImage(object sender, Vintasoft.Imaging.Print.PrintImageEventArgs e)
    {
        // set image, which must be printed
        e.Image = GetImageForPrinting(_currentImageIndex);
    
        // move to the next image in print queue
        _currentImageIndex++;
    
        // if there are no images to print
        if (_currentImageIndex >= _images.Count)
            // specify that we do not have images to print
            e.HasMoreImages = false;
        else
            // specify that we have images to print
            e.HasMoreImages = true;
    }
    
    /// <summary>
    /// Returns the image, which must be printed.
    /// </summary>
    /// <param name="index">The zero-based index in image collection.</param>
    /// <returns>
    /// The image, which must be printed.
    /// </returns>
    private Vintasoft.Imaging.VintasoftImage GetImageForPrinting(int index)
    {
        // if image does not exist
        if (index >= _images.Count)
            return null;
    
        // get image from image collection
        Vintasoft.Imaging.VintasoftImage image = _images[index];
    
        // get the PDF rendering settings
        Vintasoft.Imaging.Codecs.Decoders.PdfRenderingSettings renderingSettings =
            image.RenderingSettings as Vintasoft.Imaging.Codecs.Decoders.PdfRenderingSettings;
        // if PDF rendering settings are not specified
        if (renderingSettings == null)
        {
            // create PDF rendering settings
            renderingSettings = new Vintasoft.Imaging.Codecs.Decoders.PdfRenderingSettings();
            image.RenderingSettings = renderingSettings;
        }
    
        // specify that renderer must draw all PDF image-resources with interpolation,
        // this prevents stripes in printed image
        renderingSettings.IgnoreImageInterpolateFlag = true;
    
        // returns the image
        return image;
    }
    
    /// <summary>
    /// Printing is finished.
    /// </summary>
    private void PrintManager_EndPrint(object sender, System.Drawing.Printing.PrintEventArgs e)
    {
        UnsubscribeToEvents((Vintasoft.Imaging.Pdf.Print.PdfPrintDocument)sender);
    
        _images.ClearAndDisposeItems();
        _images.Dispose();
        _images = null;
    }
    
    

    Иерархия наследования

    System.Object
       System.MarshalByRefObject
          System.ComponentModel.Component
             System.Drawing.Printing.PrintDocument
                Vintasoft.Imaging.Print.ImagePrintDocument
                   Vintasoft.Imaging.Pdf.Print.PdfPrintDocument
                      Vintasoft.Imaging.Annotation.Pdf.Print.AnnotatedPdfPrintDocument

    Требования

    Целевые платформы: .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5

    Смотрите также