Lou Franco did a nice write-up on how to burn annotations to an image without the usage of a "viewer" (http://www.atalasoft.com/cs/forums/thread/18380.aspx
). But, I am unable to get the annotations I want to load into a LayerCollection object. Mostly because I am having a problem figuring out how to use the AnnoationDataImporters (I'm not even sure I'm supposed to use them).
I have replaced this section of Lou Franco's code:
// create annotations
LayerCollection coll = new LayerCollection();
LayerAnnotation l = new LayerAnnotation();
TextAnnotation t = new TextAnnotation("hello");
t.Data.Location = new PointF(10f, 10f);
t.Data.Size = new SizeF(50f, 50f);
((TextData)t.Data).Fill = new AnnotationBrush(Color.Yellow);
With some code which loads Xmp data from an in memory object. The Xmp data is saved from a AnnotationViewer and is stored to a database as xml. The in memory Xmp/xml data, annotations.Data, is from the database. The code is:
var layerCollection = new LayerCollection();
using( var annoStream = new MemoryStream( annotations.Data ) )
var importer = new XmpAnnotationDataImporter( annoStream );
importer.Load(); // forcing the error to occur
for( int i = 0; i < importer.PageCount; i++ )
layerCollection.Add( new LayerAnnotation( importer.Import( i ) ) );
I am getting an error of "Xmp data stream is neither JPEG nor TIFF." Which makes me think that I don't have the appropriate decoder loaded??
I do have a PdfDecoder registered. And, if I try to use PdfAnnotationDataImporter in place of XmpAnnotationDataImporter, then I get the error message "Invalid character in hex string: ? at offset 2 – please contact Atalasoft Support". (I'm pretty sure that error occurs because it's Xmp data.)
As a side note, I can load "annotations.Data" into a WebAnnotationViewer with LoadAnnotationData( Stream ). But, I'm trying to burn the image without the usage of an AnnotationViewer. So, I'm looking for a way to correctly load the annotations into a LayerCollection or AnnotationDataCollection.