Setting some annotations as not printable.

Questions, comments and suggestions concerning VintaSoft PDF .NET Plug-in.

Moderator: Alex

Post Reply
IntegraHarlan
Posts: 84
Joined: Fri Jan 24, 2020 3:37 am

Setting some annotations as not printable.

Post by IntegraHarlan »

Hi,
I am trying to print a pdf with only some of the annotations showing.
When printing, I am iterating through the annotations on the page and setting the IsPrintable property to false on the annotations that I do not want to print. However, the annotations still show when I print them. The only way I can get the annotations to not show when printing, is to set the IsHidden property to true.

I looked at the AnnotationDemo which sets the IsPrintable property, but that also prints the annotations when the IsPrintable is set to false.
We are using the Vintasoft Winforms .Net Plug-in.

Is there a way to set specific annotations to not print with the IsPrintable property?

Below is a sample of how I am setting the annotations IsPrintable property when printing.

Code: Select all

_annotationDataController = AnnotationDataController(_documentViewer.Images); // _documentViewer is  Vintasoft.Imaging.UI.ImageViewer
AnnotatedPdfPrintDocument printManager = new AnnotatedPdfPrintDocument();
    
PdfAnnotationList annotations = null;
for (int i = 0; i < _annotationDataController.Images.Count; i++)
{
    PdfPage page = PdfDocumentController.GetPageAssociatedWithImage(_annotationDataController.Images[i]);
    annotations = page?.Annotations;
    
    foreach (PdfAnnotation annotation in annotations)
    {
        annotation.IsPrintable = false;
        annotation.Flags &= PdfAnnotationFlags.Print ^ (PdfAnnotationFlags)int.MaxValue;
    }
}

printManager.AnnotationDataController = _annotationDataController;

Thanks
Harlan
T
Alex
Site Admin
Posts: 2315
Joined: Thu Jul 10, 2008 2:21 pm

Re: Setting some annotations as not printable.

Post by Alex »

Hi Harlan,

For solving your task you need to change the PDF annotation rendering mode in AnnotatedPdfPrintDocument class:
  • Create new class MyAnnotatedPdfPrintDocument, which is derived from Vintasoft.Imaging.Annotation.Pdf.Print.AnnotatedPdfPrintDocument class (https://www.vintasoft.com/docs/vsimagin ... ument.html).
  • Override the BeginPrintImage method in MyAnnotatedPdfPrintDocument class:

    Code: Select all

    /// <summary>
    /// Begins the image printing and allows to initialize the printing settings.
    /// </summary>
    /// <param name="image">Image to print.</param>
    /// <param name="renderingSettings">Image rendering settings.</param>
    protected override void BeginPrintImage(Vintasoft.Imaging.VintasoftImage image, Vintasoft.Imaging.Codecs.Decoders.RenderingSettings renderingSettings)
    {
        // get PDF page associated with printing image
        Vintasoft.Imaging.Pdf.Tree.PdfPage page =
    Vintasoft.Imaging.Pdf.PdfDocumentController.GetPageAssociatedWithImage(image);
        // if PDF page exists
        if (page != null)
        {
            // create new PDF rendering settings
            Vintasoft.Imaging.Codecs.Decoders.PdfRenderingSettings pdfRenderingSettings =
                new Vintasoft.Imaging.Codecs.Decoders.PdfRenderingSettings();
            // copy current rendering settings into new PDF rendering settings
            renderingSettings.CopyTo(pdfRenderingSettings);
    
            // disable rendering of annotations with disabled flags 'Invisible', 'Hidden', 'Print' and 'NoView'
            pdfRenderingSettings.AnnotationRenderingMode &=
                Vintasoft.Imaging.Pdf.PdfAnnotationRenderingMode.RenderDisplayable ^ (Vintasoft.Imaging.Pdf.PdfAnnotationRenderingMode)int.MaxValue;
    
            // set new PDF rendering settings as current rendering settings
            renderingSettings = pdfRenderingSettings;
        }
    
        base.BeginPrintImage(image, renderingSettings);
    }
  • Use MyAnnotatedPdfPrintDocument class for printing your PDF documents.
Please read about available rendering modes of PDF annotations here:
https://www.vintasoft.com/docs/vsimagin ... gMode.html


Please use this solution in version 9.0. In version 9.1 this temporary solution will not be necessary because starting from version 9.1 the AnnotatedPdfPrintDocument class will use this logic as the default logic.

Best regards, Alexander
IntegraHarlan
Posts: 84
Joined: Fri Jan 24, 2020 3:37 am

Re: Setting some annotations as not printable.

Post by IntegraHarlan »

Hi Alex,
Thank you for your quick response.
This is working for me

Thanks
Harlan
Post Reply