There are many different ways to save annotation data for a multi page file. One of the best ways to do this is by saving the annotation data as metadata into a tiff tag. With the help of the class TiffFile, this is acctualy really simply to do.
When saving the annotation data, once you have the data into byte array form('data' in this case), this is all you need to do:
- FileStream tiffStream = new FileStream(@"..\..\image.tif", FileMode.Open, FileAccess.ReadWrite);
- TiffFile tf = new TiffFile();
- TiffTagCollection tagCol = new TiffTagCollection();
- tagCol = tf.Images[i].Tags;
- TiffTag tag = tagCol.LookupTag(TiffTagID.WangAnnotationData);
- if (tag != null)
- tag = new TiffTag(TiffTagID.WangAnnotationData, data, TiffTagDataType.Byte);
- // save the tifffile
string tempPath = System.IO.Path.GetTempFileName();
- File.Copy(tempPath, @"..\..\image.tif", true);
When loading the data into the annotate viewer, this requires a few more steps. Remember to set the MultipageAnnotateMode property to true, so that the viewer knows to switch the annotation layers with the images. The coralation between the layer index number and the image index number is what the viewer follows.
for(int i=0; i< 3; i++)
// load the image first
this.annotateViewer1.Images.Insert(i, new AtalaImage(@"..\..\image.tif",i,null));
// load the data
FileStream fs = new FileStream(@"..\..\image.tif", FileMode.Open, FileAccess.Read);
TiffFile tf = new TiffFile();
byte wngData = (byte)tf.Images[i].Tags.LookupTag(TiffTagID.WangAnnotationData).Data;
Layer l = new Layer("Layer for page "+i.ToString(),false);
this.annotateViewer1.Annotations.CurrentLayer = l;
There is a sample project attached, with a VB.NET version as well, that demonstrates how to save and load annotation data from a tiff file. The data is saved as Wang format embeded into a tiff tag. The "Save annotation data" button simply loads the data from the 3 .wng files and saves it into the tiff tag for wang annotation data. The idea here is that you could get this annotation data from anywhere, its just easy for this demo to grab it from a file.
When you click "load image", the program will load the 3 page image and its multipage annotation data. After you click this button, no image will appear in the control, but if you hit "next" the image will be shown as expected.