VintaSoft Imaging .NET SDK 15.1: Документация для .NET разработчика
В этом разделе
PDF: Печать PDF документов в WinForms
В этом разделе
Элемент управления ImagePrintDocument предназначен для печати изображений, и он рендерит PDF страницы перед печатью. Рендеринг PDF страницы может занять много времени и потребовать много памяти, особенно если PDF страница отображается с большим разрешением.

Класс PdfPrintDocument, производный от класса ImagePrintDocument, позволяет избежать описанной выше ситуации, поскольку класс печатает PDF страницы в векторном виде. Рекомендуется использовать класс PdfPrintDocument вместо класса ImagePrintDocument, если коллекция печатаемых изображений включает в себя PDF страницы. Класс PdfPrintDocument печатает растровые изображения так же, как и при использовании класса ImagePrintDocument. Класс PdfPrintDocument предоставляет все настройки печати, доступные в классе ImagePrintDocument.


Вот C#/VB.NET код, который демонстрирует, как распечатать PDF документ на принтере по умолчанию, причем каждая страница документа будет напечатана на отдельном листе в режиме BestFit:
/// <summary>
/// The printing PDF pages.
/// </summary>
Vintasoft.Imaging.ImageCollection _printingPdfPages;

/// <summary>
/// The index of printing PDF page.
/// </summary>
int _printingPdfPageIndex;

/// <summary>
/// Prints pages of the PDF document on default printer.
/// </summary>
/// <param name="pdfFilePath">Path to the PDF file.</param>
public void PrintPdfPagesOnDefaultPrinter(string pdfFilePath)
{
    // create printing page collection
    _printingPdfPages = new Vintasoft.Imaging.ImageCollection();
    _printingPdfPages.Add(pdfFilePath);
    _printingPdfPageIndex = 0;

    // create print manager
    Vintasoft.Imaging.Pdf.Print.PdfPrintDocument pdfPrintDocument =
        new Vintasoft.Imaging.Pdf.Print.PdfPrintDocument();
    // specify that each image must be resized to fit within the page margins,
    // image proportions are not changed
    pdfPrintDocument.PrintScaleMode = Vintasoft.Imaging.Print.PrintScaleMode.BestFit;

    // subscribe to the PrintImage event
    pdfPrintDocument.PrintImage +=
        new System.EventHandler<Vintasoft.Imaging.Print.PrintImageEventArgs>(pdfPrintDocument_PrintImage);

    // start print
    pdfPrintDocument.Print();

    // clear collection and dispose images
    _printingPdfPages.ClearAndDisposeItems();
}

private void pdfPrintDocument_PrintImage(object sender, Vintasoft.Imaging.Print.PrintImageEventArgs e)
{
    e.Image = _printingPdfPages[_printingPdfPageIndex];

    _printingPdfPageIndex++;

    if (_printingPdfPageIndex >= _printingPdfPages.Count)
    {
        Vintasoft.Imaging.Print.ImagePrintDocument imagePrintDocument =
            (Vintasoft.Imaging.Print.ImagePrintDocument)sender;
        // unsubscribe from the PrintImage event
        imagePrintDocument.PrintImage -=
            new System.EventHandler<Vintasoft.Imaging.Print.PrintImageEventArgs>(pdfPrintDocument_PrintImage);
        // indicate that there is no more images to print
        e.HasMoreImages = false;
    }
    else
    {
        // indicate that there are additional images to print
        e.HasMoreImages = true;
    }
}
''' <summary>
''' The printing PDF pages.
''' </summary>
Private _printingPdfPages As Vintasoft.Imaging.ImageCollection

''' <summary>
''' The index of printing PDF page.
''' </summary>
Private _printingPdfPageIndex As Integer

''' <summary>
''' Prints pages of the PDF document on default printer.
''' </summary>
''' <param name="pdfFilePath">Path to the PDF file.</param>
Public Sub PrintPdfPagesOnDefaultPrinter(pdfFilePath As String)
    ' create printing page collection
    _printingPdfPages = New Vintasoft.Imaging.ImageCollection()
    _printingPdfPages.Add(pdfFilePath)
    _printingPdfPageIndex = 0

    ' create print manager
    Dim pdfPrintDocument As New Vintasoft.Imaging.Pdf.Print.PdfPrintDocument()
    ' specify that each image must be resized to fit within the page margins,
    ' image proportions are not changed
    pdfPrintDocument.PrintScaleMode = Vintasoft.Imaging.Print.PrintScaleMode.BestFit

    ' subscribe to the PrintImage event
    AddHandler pdfPrintDocument.PrintImage, New System.EventHandler(Of Vintasoft.Imaging.Print.PrintImageEventArgs)(AddressOf pdfPrintDocument_PrintImage)

    ' start print
    pdfPrintDocument.Print()

    ' clear collection and dispose images
    _printingPdfPages.ClearAndDisposeItems()
End Sub

Private Sub pdfPrintDocument_PrintImage(sender As Object, e As Vintasoft.Imaging.Print.PrintImageEventArgs)
    e.Image = _printingPdfPages(_printingPdfPageIndex)

    _printingPdfPageIndex += 1

    If _printingPdfPageIndex >= _printingPdfPages.Count Then
        Dim imagePrintDocument As Vintasoft.Imaging.Print.ImagePrintDocument = DirectCast(sender, Vintasoft.Imaging.Print.ImagePrintDocument)
        ' unsubscribe from the PrintImage event
        RemoveHandler imagePrintDocument.PrintImage, New System.EventHandler(Of Vintasoft.Imaging.Print.PrintImageEventArgs)(AddressOf pdfPrintDocument_PrintImage)
        ' indicate that there is no more images to print
        e.HasMoreImages = False
    Else
        ' indicate that there are additional images to print
        e.HasMoreImages = True
    End If
End Sub


Печать PDF страниц с аннотациями Vintasoft

Если коллекция изображений, предназначенных для печати, может включать некоторые PDF страницы и изображения с аннотациями в формате VintaSoft, созданные с помощью VintaSoftAnnotation.NET Plug-in , то рекомендуется использовать для печати класс AnnotatedPdfPrintDocument вместо класса AnnotatedImagePrintDocument.