LEADTOOLS Support
General
General Questions
Looking to dynamically add text to each page in a Multipage TIFF
#1
Posted
:
Saturday, April 24, 2021 8:22:40 PM(UTC)
Groups: Registered
Posts: 19
Thanks: 1 times
All,
I am looking to dynamically add text to each page in a Multi-page TIFF file and to save the text as part of the image.
I found this article, but it appears to assume I will be loading "fixed" content from a predefined file:
https://www.leadtools.co...pport/forum/posts/t6960- But for my purposes, it needs to be more dynamic.
Basically, the text will be in the format of:
"YYYY-MM-DD HH:MM:SS Page n of t <Unique ID>"
Where:
YYYY-MM-DD - is the date of the image
HH:MM:SS - is the time of the image
"n" is the current page #
"t" is the total # of pages in the multi-page TIFF
<Unique ID> is a 18-character unique Identifier
#2
Posted
:
Monday, April 26, 2021 2:45:37 PM(UTC)
Groups: Registered, Tech Support, Administrators
Posts: 163
Was thanked: 9 time(s) in 9 post(s)
I've examined the demo you cited and have updated it to the most recent version of the SDK (v21). As part of this, the dependency on the external annotation file was removed as well and it simply creates and places a single text annotation. You can use this as a starting point for your application if you'd prefer.
You can use the AnnTextObject for this purpose and assign the string you want to use to the "Text" property.
https://www.leadtools.co...dh/ac/anntextobject.htmlhttps://www.leadtools.co.../anntextobject-text.htmlWhen constructing your string, you can access the RasterImage.PageCount property to get the total number of pages, and the RasterImage.Page property to get or set the currenty page in the multipage image.
https://www.leadtools.co.../l/rasterimage-page.htmlNote file creation and modification timestamps are properties of individaul files and not specific to the SDK itself. Here's some third-party information courtesy of Microsoft on how to read this information.
https://docs.microsoft.c...reationtime?view=net-5.0Nick Crook
Developer Support Engineer
LEAD Technologies, Inc.
#3
Posted
:
Monday, April 26, 2021 3:03:18 PM(UTC)
Groups: Registered
Posts: 19
Thanks: 1 times
Thanks Nick, so it sounds like once I create the Annotation Text object, I can then use the Burn annotations into the page code to save the text to the image.
#4
Posted
:
Monday, April 26, 2021 3:45:41 PM(UTC)
Groups: Registered, Tech Support, Administrators
Posts: 163
Was thanked: 9 time(s) in 9 post(s)
#5
Posted
:
Tuesday, April 27, 2021 2:50:31 PM(UTC)
Groups: Registered
Posts: 19
Thanks: 1 times
Nick,
When I downloaded and ran the V21 code from: (https://www.leadtools.com/support/forum/posts/t6960-) NET - v21 - Load-Burn Annotations- Without RasImgVwr.zip (94kb)
I get the following error. I tried re-adding the LeadTools references for each assembly, but I get the same error. Any suggestions?
An unhandled exception of type 'System.BadImageFormatException' occurred in System.Windows.Forms.dll
Additional information: Could not load file or assembly 'Leadtools.Codecs, Version=21.0.4.0, Culture=neutral, PublicKeyToken=9cf889f53ea9b907' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Bobby
#6
Posted
:
Tuesday, April 27, 2021 3:22:00 PM(UTC)
Groups: Registered, Tech Support, Administrators
Posts: 163
Was thanked: 9 time(s) in 9 post(s)
Apologies--I had neglected to include one of the the files in the zip. It's been re-uploaded and should function as expected now. Unzip to its own folder in "C:\LEADTOOLS21\Examples\DotNet\CS" and ensure the x86/Win32 architecture is being used and not AnyCPU.
Nick Crook
Developer Support Engineer
LEAD Technologies, Inc.
#7
Posted
:
Tuesday, April 27, 2021 5:06:19 PM(UTC)
Groups: Registered
Posts: 19
Thanks: 1 times
Thanks Nick. The Demo works now.
Just one issue, when I change the source image from:
private string srcImageFileName = Application.StartupPath + @"\IMAGE1.CMP";
to a TIFF image, in my case:
private string srcImageFileName = Application.StartupPath + @"\KN7TS0M855SMQCA.tif";
I get an exception. It seems like it is coming from line:
System.Drawing.Graphics gdiPlusGraphics = Leadtools.Drawing.RasterImagePainter.CreateGraphics(srcImage).Graphics;
Any thoughts? Given my goal is to load a TIFF, add text to the top and then burn it to a new image.
Bobby
#8
Posted
:
Tuesday, April 27, 2021 9:24:49 PM(UTC)
Groups: Registered
Posts: 19
Thanks: 1 times
The sample application worked, but now I get an error when I try and load a TIFF image instead of the CMP file.
When I change:
private string srcImageFileName = Application.StartupPath + @"\IMAGE1.CMP"
To
private string targetFileName = Application.StartupPath + @"\testAnnBurn.tif"
I get an exception saying "Image is not GDI+ Compatible" on the following line:
System.Drawing.Graphics gdiPlusGraphics = Leadtools.Drawing.RasterImagePainter.CreateGraphics(srcImage).Graphics;
Keep in mind, all I am trying to do is:
1) Load a TIFF image
2) Add a text annotation to the header
3) Burn the annotation to the image
4) Save the TIFF image to disk
#9
Posted
:
Wednesday, April 28, 2021 9:13:49 AM(UTC)
Groups: Registered, Tech Support, Administrators
Posts: 163
Was thanked: 9 time(s) in 9 post(s)
#10
Posted
:
Thursday, April 29, 2021 10:14:11 AM(UTC)
Groups: Registered
Posts: 19
Thanks: 1 times
Thanks Nick, your suggestions worked. I am able to add a text annotation to each page in the multi-page TIFF.
One more question, I am looking at how to set the font color, but I didn't see any color related properties in the AnnContainer or the AnnTextObject classes.
#11
Posted
:
Thursday, April 29, 2021 11:32:24 AM(UTC)
Groups: Registered, Tech Support, Administrators
Posts: 163
Was thanked: 9 time(s) in 9 post(s)
#12
Posted
:
Thursday, April 29, 2021 1:16:43 PM(UTC)
Groups: Registered
Posts: 19
Thanks: 1 times
Thanks again Nick! I believe the only question I have left is I want to hide the border for the annotation. I see the "BorderStyle" property, but that only allows me to chose "Normal", "Cloud" or "Extra Cloud" but I was looking for a "None" or disable border if possible.
#13
Posted
:
Thursday, April 29, 2021 1:57:28 PM(UTC)
Groups: Registered
Posts: 19
Thanks: 1 times
Nick, disregard the last question. I figured out how to use the AnnStrokes class and apply it to the AnnTextObject instance. (Unless of course you know of a shorter way)
//set bordercolor to white
abBorder = new AnnSolidColorBrush();
abBorder.Color = "White";
AnnStroke annStroke = new AnnStroke();
annStroke.Stroke = abBorder;
text = new AnnTextObject();
text.Stroke = annStroke;
#14
Posted
:
Thursday, April 29, 2021 2:30:03 PM(UTC)
Groups: Registered, Tech Support, Administrators
Posts: 163
Was thanked: 9 time(s) in 9 post(s)
The outline for the AnnRectangleObject (which AnnTextObject is derived from) is handled via the Stroke property.
https://www.leadtools.co...ac/annobject-stroke.htmlYou can set the Stroke to null to not draw the outline.
Nick Crook
Developer Support Engineer
LEAD Technologies, Inc.
LEADTOOLS Support
General
General Questions
Looking to dynamically add text to each page in a Multipage TIFF
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.