burn all annotions on all pages

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

Moderator: Alex

GHWels
Posts: 38
Joined: Thu Apr 09, 2015 7:57 am

burn all annotions on all pages

Post by GHWels »

Hello Alex!

I want to draw annotions an all pages of a file.
and bevor saving i want to burn all annotions on all pages.

mfg GH
Alex
Site Admin
Posts: 2303
Joined: Thu Jul 10, 2008 2:21 pm

Re: burn all annotions on all pages

Post by Alex »

Hello Gunther,

Sorry for the delay.

Here is an article that contains an example that shows how to annotate images and save images to a TIFF file:
http://www.vintasoft.com/docs/vsimaging ... oller.html

Here is an example that shows how to load TIFF file, annotate it, save annotated TIFF file to new TIFF file:
http://www.vintasoft.com/docs/vsimaging ... _Tiff.html

Here is an example that shows how to load PDF document, annotate it, save annotated document to new PDF document:
http://www.vintasoft.com/docs/vsimaging ... e_Pdf.html

Here is an article that contains an example that shows how to burn annotations on image:
http://www.vintasoft.com/docs/vsimaging ... oller.html

Please see examples and let me know if you will have any question or problem.

Best regards, Alexander
GHWels
Posts: 38
Joined: Thu Apr 09, 2015 7:57 am

Re: burn all annotions on all pages

Post by GHWels »

Hello Alex!

I know how to write annotations on TIF or PDF
I also know how to burn the annotations on the first page, but i could not find a easy solution to burn ALL annotations on ALL pages.
The task is to burn the date/time on every page after scanning.

Thank you for your help
GH
Alex
Site Admin
Posts: 2303
Joined: Thu Jul 10, 2008 2:21 pm

Re: burn all annotions on all pages

Post by Alex »

I know how to write annotations on TIF or PDF
I also know how to burn the annotations on the first page, but i could not find a easy solution to burn ALL annotations on ALL pages.
The task is to burn the date/time on every page after scanning.
For doing your task you need do the following steps:
  • For each image in image collection
    • Add annotation to an image
    • Burn annotation on image (call the AnnotationViewController.BurnAnnotationCollectionOnImage method)
  • Save image collection to an image file
Best regards, Alexander
GHWels
Posts: 38
Joined: Thu Apr 09, 2015 7:57 am

Re: burn all annotions on all pages

Post by GHWels »

Hello Alex!

Im am sorry, i can't solve the Problem to burn the date on all pages.

Code: Select all

Private Sub C1Button1_Click(sender As Object, e As EventArgs) Handles C1Button1.Click

    Dim imageCollection As New ImageCollection()
    imageCollection.Add("\\hh4\scandaten$\KOFAX\Rechnungen\00206B816A87160627071702_1.tif")

    ' Create annotation controllers associated with image collection.
    Dim annotationDataController As New AnnotationDataController(imageCollection)
    Dim annotationViewController As New AnnotationViewController(annotationDataController)

    Dim _Data As New TextAnnotationData()
    _Data.AutoSize = True
    _Data.Location = New PointF(100, 40)
    _Data.Text = String.Format("{0}: {1}", "Scan", Now)
    _Data.Border = False
    _Data.Font = New AnnotationFont("Arial", 12)
    _Data.FontBrush = New AnnotationSolidBrush(System.Drawing.Color.Red)

    Dim _TAV As TextAnnotationView = New TextAnnotationView(_Data)

    annotationViewController(0).Add(_TAV)

    annotationViewController.BurnAnnotationCollectionOnImage(0)

    imageCollection.SaveSync("c:\temp\test.tif", True)

End Sub
mfg GH
Alex
Site Admin
Posts: 2303
Joined: Thu Jul 10, 2008 2:21 pm

Re: burn all annotions on all pages

Post by Alex »

In your code you are adding annotation only to the first image.

Here is correct code:

Code: Select all

Private Sub C1Button1_Click(sender As Object, e As EventArgs) Handles C1Button1.Click

    Dim imageCollection As New ImageCollection()
    imageCollection.Add("\\hh4\scandaten$\KOFAX\Rechnungen\00206B816A87160627071702_1.tif")

    ' Create annotation controllers associated with image collection.
    Dim annotationDataController As New AnnotationDataController(imageCollection)
    Dim annotationViewController As New AnnotationViewController(annotationDataController)

    For imageIndex As Integer = 0 To imageCollection.Count - 1
        Dim _Data As New TextAnnotationData()
        _Data.AutoSize = True
        _Data.Location = New PointF(100, 40)
        _Data.Text = String.Format("{0}: {1}", "Scan", Now)
        _Data.Border = False
        _Data.Font = New AnnotationFont("Arial", 12)
        _Data.FontBrush = New AnnotationSolidBrush(System.Drawing.Color.Red)

        Dim _TAV As TextAnnotationView = New TextAnnotationView(_Data)

        annotationViewController(imageIndex).Add(_TAV)

        annotationViewController.BurnAnnotationCollectionOnImage(imageIndex)
    Next

    imageCollection.SaveSync("c:\temp\test.tif", True)

End Sub
Best regards, Alexander
GHWels
Posts: 38
Joined: Thu Apr 09, 2015 7:57 am

Re: burn all annotions on all pages

Post by GHWels »

Hello Alex!

Thank you for your help, but now the file is growing very much.

TIF before (111KB 1 page) after inserting the date (390KB)
TIF before (443KB 12 pages) after inserting the date (4080KB)

Best regards
GH
Alex
Site Admin
Posts: 2303
Joined: Thu Jul 10, 2008 2:21 pm

Re: burn all annotions on all pages

Post by Alex »

Hello Gunther,

I think the resulting TIFF file is greater than source TIFF file because TIFF files have different encoding settings (compression, ...).

Here is an example that shows how to burn annotation on TIFF image and save changed TIFF image back to the source file with the encoding setting from source file:

Code: Select all

Imports System.Drawing
Imports Vintasoft.Imaging
Imports Vintasoft.Imaging.Codecs.Encoders
Imports Vintasoft.Imaging.Metadata
Imports Vintasoft.Imaging.Annotation
Imports Vintasoft.Imaging.Annotation.UI

Module Module1

    Sub Main()
        ChangeAndSaveTiffFile("DocCleanMultipage.tif")
    End Sub

    ''' <summary>
    ''' Loads image(s) from a TIFF file,
    ''' burns annotation on TIFF image,
    ''' saves image(s) back to the source TIFF file with the encoding settings from source TIFF image(s).
    ''' </summary>
    ''' <param name="filename">Path to a TIFF file.</param>
    Private Sub ChangeAndSaveTiffFile(ByVal filename As String)
        ' create image collection
        Using images As New ImageCollection()
            ' add images from TIFF file to the image collection
            images.Add(filename, False)

            ' create annotation controllers associated with image collection
            Dim annotationDataController As New AnnotationDataController(images)
            Dim annotationViewController As New AnnotationViewController(annotationDataController)

            ' for each image
            For imageIndex As Integer = 0 To images.Count - 1
                ' create annotation data
                Dim _Data As New TextAnnotationData()
                _Data.AutoSize = True
                _Data.Location = New PointF(100, 40)
                _Data.Text = String.Format("{0}: {1}", "Scan", Now)
                _Data.Border = False
                _Data.Font = New AnnotationFont("Arial", 12)
                _Data.FontBrush = New AnnotationSolidBrush(System.Drawing.Color.Red)

                ' create annotation view
                Dim _TAV As TextAnnotationView = New TextAnnotationView(_Data)

                ' add annotation to an image
                annotationViewController(imageIndex).Add(_TAV)

                ' burn annotation on image
                annotationViewController.BurnAnnotationCollectionOnImage(imageIndex)
            Next

            ' create TIFF encoder
            Using encoder As New TiffEncoder()
                ' specify that image collection must change source after saving
                encoder.SaveAndSwitchSource = True

                ' subscribe to the image saving event
                AddHandler encoder.ImageSaving, New EventHandler(Of ImageSavingEventArgs)(AddressOf EncoderImageSaving)
                ' save images synchronously
                images.SaveSync(filename, encoder)
                ' unsubscribe from the image saving event
                RemoveHandler encoder.ImageSaving, AddressOf EncoderImageSaving
            End Using

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

    ''' <summary>
    ''' Handler of the image saving event.
    ''' </summary>
    Private Sub EncoderImageSaving(ByVal sender As Object, ByVal e As ImageSavingEventArgs)
        ' get TIFF encoder
        Dim encoder As TiffEncoder = DirectCast(sender, TiffEncoder)
        ' get TIFF encoder settings from source TIFF image
        encoder.Settings = GetTiffEncoderSettings(e.Image.Metadata)
    End Sub

    ''' <summary>
    ''' Gets the TIFF encoder settings from metadata of TIFF image.
    ''' </summary>
    ''' <param name="metadata">The metadata.</param>
    Private Function GetTiffEncoderSettings(ByVal metadata As VintasoftImageMetadata) As TiffEncoderSettings
        ' create TIFF encoder settings
        Dim settings As New TiffEncoderSettings()
        ' get page metadata of TIFF file
        Dim tree As TiffPageMetadata = TryCast(metadata.MetadataTree, TiffPageMetadata)
        ' if metadata is TIFF image metadata
        If tree IsNot Nothing Then
            ' get compression of TIFF file
            settings.Compression = tree.Compression
            settings.UseTiles = False
            settings.UseStrips = False
            ' find RowsPerStrip tag of TIFF file
            Dim rowsPerStripTag As TiffTagMetadata = tree.FindChildNode(Of TiffTagMetadata)("RowsPerStrip")
            ' if tag exists (TIFF image data are stored in strips)
            If rowsPerStripTag IsNot Nothing Then
                ' specify that encoder must use strips
                settings.UseStrips = True
                ' set row count in a strip of TIFF file
                settings.RowsPerStrip = Convert.ToInt32(rowsPerStripTag.Value)
            Else
                ' if tag does NOT exist (TIFF image data are stored in tiles)
                ' find TileWidth tag of TIFF file
                Dim tileWidthTag As TiffTagMetadata = tree.FindChildNode(Of TiffTagMetadata)("TileWidth")
                ' if tag exists
                If tileWidthTag IsNot Nothing Then
                    ' find TileLength tag of TIFF file
                    Dim tileLengthTag As TiffTagMetadata = tree.FindChildNode(Of TiffTagMetadata)("TileLength")

                    ' get tile width and height of TIFF file
                    Dim tileWidth As Integer = Convert.ToInt32(tileWidthTag.Value)
                    Dim tileHeigth As Integer = Convert.ToInt32(tileLengthTag.Value)

                    ' specify that encoder must use tiles
                    settings.UseTiles = True
                    ' set size of tile of TIFF file
                    settings.TileSize = New Size(tileWidth, tileHeigth)
                End If
            End If
        End If
        Return settings
    End Function

End Module
Best regards, Alexander
GHWels
Posts: 38
Joined: Thu Apr 09, 2015 7:57 am

Re: burn all annotions on all pages

Post by GHWels »

Hello Alex!

Thank you very much, it works perfect.

GH
GHWels
Posts: 38
Joined: Thu Apr 09, 2015 7:57 am

Re: burn all annotions on all pages

Post by GHWels »

Hello Alex!

I'll think the procedure is not working on big files.
the procedure crashes on page 60.

mfg GH
Post Reply