LEADTOOLS Support
Document
Document SDK Questions
Web Annotation XML is having different Height/Width compared to programmatically generated XML
#1
Posted
:
Tuesday, June 30, 2020 11:14:33 AM(UTC)
Groups: Registered
Posts: 60
I'm having a TIFF document of height 600 and width 800. If this document is loaded in Web Viewer and If I add annotation in Web Viewer, the resulting XML Annotation container has height as 4500 and width as 6000 value. If I add load the same document using Raster Codecs and If I programmatically generate annotation XML then the resulting XML has height value as 600 and width value as 800. This is same as document height and width.
Here is the code that I have used.
Code:
using RasterCodecs codecs = new RasterCodecs();
codecs.Options.Load.AllPages = true;
codecs.Options.Load.SuperCompressed = true;
codecs.Options.Load.Name = $"anything.{documentExtension}";
var image = codecs.Load(documentPath);
var pages = image.PageCount;
var height = image.ImageHeight;
var width = image.ImageWidth;
var pageNumbers = Enumerable.Range(1, pages);
var containers = new AnnContainer[pages];
foreach (var page in pageNumbers)
{
if (page == 1)
{
var container = new AnnContainer();
container.Size = new LeadSizeD(width, height);
container.Resize(new LeadSizeD(width, height), AnnResizeContainerFlags.AutoCalibrate, AnnResizeMode.Stretch);
var textAnnotation = new AnnTextObject();
textAnnotation.Font.FontSize = 11;
textAnnotation.Text = timeStampText;
textAnnotation.HorizontalAlignment = AnnHorizontalAlignment.Left;
textAnnotation.VerticalAlignment = AnnVerticalAlignment.Center;
textAnnotation.Font.FontFamilyName = "TimesNewRoman";
textAnnotation.Guid = Guid.NewGuid().ToString();
textAnnotation.Font.FontStyle = AnnFontStyle.Italic;
textAnnotation.Font.FontWeight = AnnFontWeight.Bold;
textAnnotation.IsVisible = true;
textAnnotation.UserId = "TimeStamp";
textAnnotation.TextForeground = AnnSolidColorBrush.Create("Blue");
textAnnotation.Lock("test");
textAnnotation.Points.Add(LeadPointD.Create(0, height - 200));
textAnnotation.Points.Add(LeadPointD.Create(width, height - 200));
textAnnotation.Points.Add(LeadPointD.Create(width, height));
textAnnotation.Points.Add(LeadPointD.Create(0, height));
textAnnotation.Stroke = AnnStroke.Create(AnnSolidColorBrush.Create("White"), new LeadLengthD(2));
container.Mapper.MapResolutions(image.XResolution, image.YResolution, image.XResolution, image.YResolution);
container.Children.Add(textAnnotation);
containers[page - 1] = container;
}
else
{
var nextcontainer = new AnnContainer();
nextcontainer.Size = new LeadSizeD(width, height);
nextcontainer.PageNumber = page;
containers[page - 1] = nextcontainer;
}
}
AnnCodecs annCodecs = new AnnCodecs();
finalXml = annCodecs.SaveAllToString(containers, AnnFormat.Annotations);
Please can you assist on how to match the annotation container height and width to the value same as the one generated by web viewer xml
Thanks.
Abdul
#2
Posted
:
Wednesday, July 1, 2020 4:01:01 PM(UTC)
Groups: Registered, Tech Support, Administrators
Posts: 105
Was thanked: 3 time(s) in 3 post(s)
Hello Abdul,
The reason the AnnContainer size is changing to the size of the image is due to these two lines:
Code:
container.Size = new LeadSizeD(width, height);
container.Resize(new LeadSizeD(width, height), AnnResizeContainerFlags.AutoCalibrate, AnnResizeMode.Stretch);
The AnnContainer will keep the size it holds in the XML if you do not set the size of the AnnContainer.
Let me know if you have any questions on the above information.
Thanks
Matt Bresson
Developer Support Engineer
LEAD Technologies, Inc.
#3
Posted
:
Wednesday, July 1, 2020 7:05:36 PM(UTC)
Groups: Registered
Posts: 60
I removed the below code
Code:
container.Resize(new LeadSizeD(width, height), AnnResizeContainerFlags.AutoCalibrate, AnnResizeMode.Stretch);
When I calculate height and width as shown below it is working fine,
Code:
var height = image.ImageHeight * (720/(double)image.XResolution);
var width = image.ImageWidth * (720/(double)image.YResolution);
container.Size = new LeadSizeD(width, height);
Am I correct?
Thanks,
Abdul
#4
Posted
:
Thursday, July 2, 2020 8:34:18 AM(UTC)
Groups: Registered, Tech Support, Administrators
Posts: 105
Was thanked: 3 time(s) in 3 post(s)
Hello Abdul,
Yes you are correct, the size of the AnnContainer in the XML file is in annotations points, not control or image pixels. When you load the AnnContainer using AnnCodecs, the size of the container should load in as the same size it hold in the XML file. Only when using the AnnContainerMapper, or Resize or Size properties will you change the size of the AnnContainer. The reason your equation outputs the correct height and width, is because that equation is used to calculate annotation points.
If you have any further questions please feel free to reach back out to us.
Thanks
Matt Bresson
Developer Support Engineer
LEAD Technologies, Inc.
LEADTOOLS Support
Document
Document SDK Questions
Web Annotation XML is having different Height/Width compared to programmatically generated XML
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.