
'Declaration Public Class AnnotatedPdfPrintDocument Inherits Vintasoft.Imaging.Pdf.Print.PdfPrintDocument
public class AnnotatedPdfPrintDocument : Vintasoft.Imaging.Pdf.Print.PdfPrintDocument
public __gc class AnnotatedPdfPrintDocument : public Vintasoft.Imaging.Pdf.Print.PdfPrintDocument
public ref class AnnotatedPdfPrintDocument : public Vintasoft.Imaging.Pdf.Print.PdfPrintDocument
''' <summary> ''' The images, which must be printed. ''' </summary> Private _images As Vintasoft.Imaging.ImageCollection = Nothing ''' <summary> ''' The annotation data controller. ''' </summary> Private _annotationDataController As Vintasoft.Imaging.Annotation.AnnotationDataController ''' <summary> ''' Indicates whether the image collection and annotation data controller must be disposed after print. ''' </summary> Private _disposeImageCollectionAndDataControllerAfterPrint As Boolean ''' <summary> ''' The index of image, which must be printed. ''' </summary> Private _currentImageIndex As Integer ''' <summary> ''' Prints the images of annotation viewer. ''' </summary> ''' <param name="viewer">The annotation viewer.</param> Public Sub PrintAnnotatedDocument(viewer As Vintasoft.Imaging.Annotation.UI.AnnotationViewer) PrintAsync(viewer.Images, viewer.AnnotationDataController, False) End Sub ''' <summary> ''' Prints the annotated document. ''' </summary> ''' <param name="documentPath">The document path.</param> Public Sub PrintAnnotatedDocument(documentPath As String) ' create image collection Dim images As New Vintasoft.Imaging.ImageCollection() ' load document images.Add(documentPath) ' create annotation data controller Dim annotationDataController As New Vintasoft.Imaging.Annotation.AnnotationDataController(images) ' print the image collection PrintAsync(images, annotationDataController, True) End Sub ''' <summary> ''' Asynchronously prints the specified images. ''' </summary> ''' <param name="images">The images, which must be printed.</param> ''' <param name="annotationDataController">The annotation data controller.</param> ''' <param name="disposeImageCollectionAndDataControllerAfterPrint"> ''' Determines whether the image collection and annotation data controller must be disposed after print. ''' </param> Private Sub PrintAsync(images As Vintasoft.Imaging.ImageCollection, annotationDataController As Vintasoft.Imaging.Annotation.AnnotationDataController, disposeImageCollectionAndDataControllerAfterPrint As Boolean) _images = images _annotationDataController = annotationDataController _disposeImageCollectionAndDataControllerAfterPrint = disposeImageCollectionAndDataControllerAfterPrint ' create print manager Dim printManager As New Vintasoft.Imaging.Annotation.Pdf.Print.AnnotatedPdfPrintDocument(annotationDataController) ' 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.Annotation.Pdf.Print.AnnotatedPdfPrintDocument) 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.Annotation.Pdf.Print.AnnotatedPdfPrintDocument) 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.Annotation.Pdf.Print.AnnotatedPdfPrintDocument) RemoveHandler printManager.PrintImage, AddressOf PrintManager_PrintImage RemoveHandler printManager.EndPrint, AddressOf PrintManager_EndPrint End Sub ''' <summary> ''' Prints image. ''' </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.Annotation.Pdf.Print.AnnotatedPdfPrintDocument)) ' if image collection and annotation data controller must be disposed If _disposeImageCollectionAndDataControllerAfterPrint Then ' dispose annotation data controller _annotationDataController.Dispose() ' dispose image collection _images.ClearAndDisposeItems() _images.Dispose() End If _annotationDataController = Nothing _images = Nothing End Sub
/// <summary> /// The images, which must be printed. /// </summary> Vintasoft.Imaging.ImageCollection _images = null; /// <summary> /// The annotation data controller. /// </summary> Vintasoft.Imaging.Annotation.AnnotationDataController _annotationDataController; /// <summary> /// Indicates whether the image collection and annotation data controller must be disposed after print. /// </summary> bool _disposeImageCollectionAndDataControllerAfterPrint; /// <summary> /// The index of image, which must be printed. /// </summary> int _currentImageIndex; /// <summary> /// Prints the images of annotation viewer. /// </summary> /// <param name="viewer">The annotation viewer.</param> public void PrintAnnotatedDocument(Vintasoft.Imaging.Annotation.UI.AnnotationViewer viewer) { PrintAsync(viewer.Images, viewer.AnnotationDataController, false); } /// <summary> /// Prints the annotated document. /// </summary> /// <param name="documentPath">The document path.</param> public void PrintAnnotatedDocument(string documentPath) { // create image collection Vintasoft.Imaging.ImageCollection images = new Vintasoft.Imaging.ImageCollection(); // load document images.Add(documentPath); // create annotation data controller Vintasoft.Imaging.Annotation.AnnotationDataController annotationDataController = new Vintasoft.Imaging.Annotation.AnnotationDataController(images); // print the image collection PrintAsync(images, annotationDataController, true); } /// <summary> /// Asynchronously prints the specified images. /// </summary> /// <param name="images">The images, which must be printed.</param> /// <param name="annotationDataController">The annotation data controller.</param> /// <param name="disposeImageCollectionAndDataControllerAfterPrint"> /// Determines whether the image collection and annotation data controller must be disposed after print. /// </param> private void PrintAsync( Vintasoft.Imaging.ImageCollection images, Vintasoft.Imaging.Annotation.AnnotationDataController annotationDataController, bool disposeImageCollectionAndDataControllerAfterPrint) { _images = images; _annotationDataController = annotationDataController; _disposeImageCollectionAndDataControllerAfterPrint = disposeImageCollectionAndDataControllerAfterPrint; // create print manager Vintasoft.Imaging.Annotation.Pdf.Print.AnnotatedPdfPrintDocument printManager = new Vintasoft.Imaging.Annotation.Pdf.Print.AnnotatedPdfPrintDocument(annotationDataController); // 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.Annotation.Pdf.Print.AnnotatedPdfPrintDocument 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.Annotation.Pdf.Print.AnnotatedPdfPrintDocument 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.Annotation.Pdf.Print.AnnotatedPdfPrintDocument printManager) { printManager.PrintImage -= PrintManager_PrintImage; printManager.EndPrint -= PrintManager_EndPrint; } /// <summary> /// Prints image. /// </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.Annotation.Pdf.Print.AnnotatedPdfPrintDocument)sender); // if image collection and annotation data controller must be disposed if (_disposeImageCollectionAndDataControllerAfterPrint) { // dispose annotation data controller _annotationDataController.Dispose(); // dispose image collection _images.ClearAndDisposeItems(); _images.Dispose(); } _annotationDataController = null; _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
Target Platforms: Windows 10, Windows 8, Windows 7, Windows Vista, Windows XP, Windows Server 2012, Windows Server 2008, Windows Server 2003