VintaSoft Imaging .NET SDK v8.8 for .NET Framework
Vintasoft.Imaging.Pdf.Print Namespace / PdfPrintDocument Class
Members Example



In This Topic
    PdfPrintDocument Class
    In This Topic
    Sends images to a printer. PDF pages will be printed in vector form, other image types will be printed in a raster form.
    Object Model
    PdfPrintDocument Class
    Syntax
    'Declaration
     
    <ToolboxBitmapAttribute(Vintasoft.Imaging.Print.ImagePrintDocument, "ImagePrintDocument.bmp")>
    <DesignerCategoryAttribute("Component")>
    <ToolboxItemFilterAttribute("System.Drawing.Printing")>
    <DefaultPropertyAttribute("DocumentName")>
    <SRDescriptionAttribute("PrintDocumentDesc")>
    <DefaultEventAttribute("PrintPage")>
    Public Class PdfPrintDocument 
       Inherits Vintasoft.Imaging.Print.ImagePrintDocument
    [ToolboxBitmap(Vintasoft.Imaging.Print.ImagePrintDocument, "ImagePrintDocument.bmp")]
    [DesignerCategory("Component")]
    [ToolboxItemFilter("System.Drawing.Printing")]
    [DefaultProperty("DocumentName")]
    [SRDescription("PrintDocumentDesc")]
    [DefaultEvent("PrintPage")]
    public class PdfPrintDocument : Vintasoft.Imaging.Print.ImagePrintDocument 
    [ToolboxBitmap(Vintasoft.Imaging.Print.ImagePrintDocument, "ImagePrintDocument.bmp")]
    [DesignerCategory("Component")]
    [ToolboxItemFilter("System.Drawing.Printing")]
    [DefaultProperty("DocumentName")]
    [SRDescription("PrintDocumentDesc")]
    [DefaultEvent("PrintPage")]
    public __gc class PdfPrintDocument : public Vintasoft.Imaging.Print.ImagePrintDocument 
    [ToolboxBitmap(Vintasoft.Imaging.Print.ImagePrintDocument, "ImagePrintDocument.bmp")]
    [DesignerCategory("Component")]
    [ToolboxItemFilter("System.Drawing.Printing")]
    [DefaultProperty("DocumentName")]
    [SRDescription("PrintDocumentDesc")]
    [DefaultEvent("PrintPage")]
    public ref class PdfPrintDocument : public Vintasoft.Imaging.Print.ImagePrintDocument 
    Remarks
    Class will print PDF page in vector form only if PDF page does NOT contain transparent content.
    Example
    This example shows how to print a PDF document on a default printer, each page of the document will be printed in BestFit mode:
    ''' <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.Pdf.PdfRenderingSettings = TryCast(image.RenderingSettings, Vintasoft.Imaging.Pdf.PdfRenderingSettings)
    	' if PDF rendering settings are not specified
    	If renderingSettings Is Nothing Then
    		' create PDF rendering settings
    		renderingSettings = New Vintasoft.Imaging.Pdf.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.Pdf.PdfRenderingSettings renderingSettings =
            image.RenderingSettings as Vintasoft.Imaging.Pdf.PdfRenderingSettings;
        // if PDF rendering settings are not specified
        if (renderingSettings == null)
        {
            // create PDF rendering settings
            renderingSettings = new Vintasoft.Imaging.Pdf.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;
    }
    Inheritance Hierarchy

    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

    Requirements

    Target Platforms: Windows 10, Windows 8, Windows 7, Windows Vista, Windows XP, Windows Server 2012, Windows Server 2008, Windows Server 2003

    See Also