VintaSoft Annotation .NET Plug-in Discussions
Questions, comments and suggestions concerning VintaSoft Annotation .NET Plug-in.
Board index < VintaSoft Imaging < VintaSoft Annotation .NET Plug-in Discussions
I know how to write annotations on TIF or PDFFor doing your task you need do the following steps:
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.
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
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
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