|  | @@ -340,82 +340,89 @@ namespace InABox.DynamicGrid
 | 
	
		
			
				|  |  |                      pdfdocument = File.ReadAllBytes(cachefile);
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -                var doc = new PdfLoadedDocument(pdfdocument);
 | 
	
		
			
				|  |  | +                if (pdfdocument.Any())
 | 
	
		
			
				|  |  | +                {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -                currentAnnotations.Clear();
 | 
	
		
			
				|  |  | +                    var doc = new PdfLoadedDocument(pdfdocument);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -                var watermark = !_document.Superceded.IsEmpty() ? "SUPERCEDED" : Watermark;
 | 
	
		
			
				|  |  | -                if (!string.IsNullOrWhiteSpace(watermark))
 | 
	
		
			
				|  |  | -                    foreach (PdfPageBase page in doc.Pages)
 | 
	
		
			
				|  |  | -                    {
 | 
	
		
			
				|  |  | -                        var rect = new RectangleF(0, 0, page.Size.Width, page.Size.Height);
 | 
	
		
			
				|  |  | -                        var graphics = page.Graphics;
 | 
	
		
			
				|  |  | -                        PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, page.Size.Width / 10, PdfFontStyle.Bold);
 | 
	
		
			
				|  |  | -                        var state = graphics.Save();
 | 
	
		
			
				|  |  | -                        graphics.SetTransparency(0.2f);
 | 
	
		
			
				|  |  | -                        var format = new PdfStringFormat();
 | 
	
		
			
				|  |  | -                        format.Alignment = PdfTextAlignment.Center;
 | 
	
		
			
				|  |  | -                        format.LineAlignment = PdfVerticalAlignment.Middle;
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -                        var lineheight = (int)Math.Round(font.Height * 2.5);
 | 
	
		
			
				|  |  | -                        var lines = new List<string>();
 | 
	
		
			
				|  |  | -                        while (lines.Count * lineheight < page.Size.Height)
 | 
	
		
			
				|  |  | -                            lines.Add(watermark);
 | 
	
		
			
				|  |  | -                        graphics.DrawString(string.Join("\n\n", lines), font, PdfBrushes.Red, rect, format);
 | 
	
		
			
				|  |  | -                    }
 | 
	
		
			
				|  |  | +                    currentAnnotations.Clear();
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -                //foreach (PdfPageBase page in doc.Pages)
 | 
	
		
			
				|  |  | -                //{
 | 
	
		
			
				|  |  | -                //    RectangleF rect = new RectangleF(0, 0, page.Size.Width, page.Size.Height);
 | 
	
		
			
				|  |  | -                //    PdfGraphics graphics = page.Graphics;
 | 
	
		
			
				|  |  | -                //    PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, page.Size.Width / 10, PdfFontStyle.Bold);
 | 
	
		
			
				|  |  | -                //    PdfGraphicsState state = graphics.Save();
 | 
	
		
			
				|  |  | -                //    graphics.SetTransparency(0.2f);
 | 
	
		
			
				|  |  | -                //    PdfStringFormat format = new PdfStringFormat();
 | 
	
		
			
				|  |  | -                //    format.Alignment = PdfTextAlignment.Center;
 | 
	
		
			
				|  |  | -                //    format.LineAlignment = PdfVerticalAlignment.Middle;
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -                //    int lineheight = (int)Math.Round(font.Height * 2.5);
 | 
	
		
			
				|  |  | -                //    List<String> lines = new List<string>();
 | 
	
		
			
				|  |  | -                //    while (lines.Count * lineheight < page.Size.Height)
 | 
	
		
			
				|  |  | -                //        lines.Add("SUPERCEDED");
 | 
	
		
			
				|  |  | -                //    graphics.DrawString(String.Join("\n\n", lines), font, PdfBrushes.Red, rect, format);
 | 
	
		
			
				|  |  | -                //}
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -                var annotations = new Client<EntityDocumentAnnotation>()
 | 
	
		
			
				|  |  | -                    .Load(new Filter<EntityDocumentAnnotation>(x => x.EntityDocument).IsEqualTo(_document.ID)).ToList();
 | 
	
		
			
				|  |  | -                foreach (var annotation in annotations)
 | 
	
		
			
				|  |  | -                    try
 | 
	
		
			
				|  |  | -                    {
 | 
	
		
			
				|  |  | -                        currentAnnotations.Add(annotation.ID);
 | 
	
		
			
				|  |  | -                        if (!string.IsNullOrWhiteSpace(annotation.Data))
 | 
	
		
			
				|  |  | +                    var watermark = !_document.Superceded.IsEmpty() ? "SUPERCEDED" : Watermark;
 | 
	
		
			
				|  |  | +                    if (!string.IsNullOrWhiteSpace(watermark))
 | 
	
		
			
				|  |  | +                        foreach (PdfPageBase page in doc.Pages)
 | 
	
		
			
				|  |  |                          {
 | 
	
		
			
				|  |  | -                            if (annotation.Data.Contains("<freetext") && !annotation.Data.Contains("date=\""))
 | 
	
		
			
				|  |  | +                            var rect = new RectangleF(0, 0, page.Size.Width, page.Size.Height);
 | 
	
		
			
				|  |  | +                            var graphics = page.Graphics;
 | 
	
		
			
				|  |  | +                            PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, page.Size.Width / 10,
 | 
	
		
			
				|  |  | +                                PdfFontStyle.Bold);
 | 
	
		
			
				|  |  | +                            var state = graphics.Save();
 | 
	
		
			
				|  |  | +                            graphics.SetTransparency(0.2f);
 | 
	
		
			
				|  |  | +                            var format = new PdfStringFormat();
 | 
	
		
			
				|  |  | +                            format.Alignment = PdfTextAlignment.Center;
 | 
	
		
			
				|  |  | +                            format.LineAlignment = PdfVerticalAlignment.Middle;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                            var lineheight = (int)Math.Round(font.Height * 2.5);
 | 
	
		
			
				|  |  | +                            var lines = new List<string>();
 | 
	
		
			
				|  |  | +                            while (lines.Count * lineheight < page.Size.Height)
 | 
	
		
			
				|  |  | +                                lines.Add(watermark);
 | 
	
		
			
				|  |  | +                            graphics.DrawString(string.Join("\n\n", lines), font, PdfBrushes.Red, rect, format);
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                    //foreach (PdfPageBase page in doc.Pages)
 | 
	
		
			
				|  |  | +                    //{
 | 
	
		
			
				|  |  | +                    //    RectangleF rect = new RectangleF(0, 0, page.Size.Width, page.Size.Height);
 | 
	
		
			
				|  |  | +                    //    PdfGraphics graphics = page.Graphics;
 | 
	
		
			
				|  |  | +                    //    PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, page.Size.Width / 10, PdfFontStyle.Bold);
 | 
	
		
			
				|  |  | +                    //    PdfGraphicsState state = graphics.Save();
 | 
	
		
			
				|  |  | +                    //    graphics.SetTransparency(0.2f);
 | 
	
		
			
				|  |  | +                    //    PdfStringFormat format = new PdfStringFormat();
 | 
	
		
			
				|  |  | +                    //    format.Alignment = PdfTextAlignment.Center;
 | 
	
		
			
				|  |  | +                    //    format.LineAlignment = PdfVerticalAlignment.Middle;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                    //    int lineheight = (int)Math.Round(font.Height * 2.5);
 | 
	
		
			
				|  |  | +                    //    List<String> lines = new List<string>();
 | 
	
		
			
				|  |  | +                    //    while (lines.Count * lineheight < page.Size.Height)
 | 
	
		
			
				|  |  | +                    //        lines.Add("SUPERCEDED");
 | 
	
		
			
				|  |  | +                    //    graphics.DrawString(String.Join("\n\n", lines), font, PdfBrushes.Red, rect, format);
 | 
	
		
			
				|  |  | +                    //}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                    var annotations = new Client<EntityDocumentAnnotation>()
 | 
	
		
			
				|  |  | +                        .Load(new Filter<EntityDocumentAnnotation>(x => x.EntityDocument).IsEqualTo(_document.ID))
 | 
	
		
			
				|  |  | +                        .ToList();
 | 
	
		
			
				|  |  | +                    foreach (var annotation in annotations)
 | 
	
		
			
				|  |  | +                        try
 | 
	
		
			
				|  |  | +                        {
 | 
	
		
			
				|  |  | +                            currentAnnotations.Add(annotation.ID);
 | 
	
		
			
				|  |  | +                            if (!string.IsNullOrWhiteSpace(annotation.Data))
 | 
	
		
			
				|  |  |                              {
 | 
	
		
			
				|  |  | -                                Logger.Send(LogType.Information, ClientFactory.UserID,
 | 
	
		
			
				|  |  | -                                    string.Format("Annotation #{0} has no date - inserting now..", annotation.ID));
 | 
	
		
			
				|  |  | -                                annotation.Data = annotation.Data.Replace("<freetext",
 | 
	
		
			
				|  |  | -                                    string.Format("<freetext date=\"D:{0:yyyyMMddHHmmss}+08\'00\'\"", DateTime.Now));
 | 
	
		
			
				|  |  | -                                //annotation.Data = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<xfdf xmlns=\"http://ns.adobe.com/xfdf/\" xml:space=\"preserve\">\r\n  <annots>\r\n    <freetext page=\"0\" rect=\"635.782,231.8206,812.7407,282.311\" rotation=\"0\" color=\"#FFFFFF\" title=\"ffffffff-ffff-ffff-ffff-ffffffffffff\" subject=\"Free Text\" date=\"D:20220715001146+08'00'\" name=\"800eae13-14f4-4db9-a60e-6d5d2d2adb55\" fringe=\"0,0,0,0\" border=\"0,0,1\" q=\"0\" IT=\"FreeTextCallout\" head=\"None\">\r\n      <defaultappearance>0.2901961 0.5647059 0.8862745 rg </defaultappearance>\r\n      <defaultstyle>font:Arial 8pt;style:Regular;color:#FF0000</defaultstyle>\r\n      <contents-richtext><body xmlns=\"http://www.w3.org/1999/xhtml\"><p dir=\"ltr\">MC'd by BW\r\nTrolley H18\r\n8 July 2022\r\nNOTE: 3032 Doorleaf is also on Trolley H18</p></body></contents-richtext>\r\n      <contents>MC'd by BW\r\nTrolley H18\r\n8 July 2022\r\nNOTE: 3032 Doorleaf is also on Trolley H18</contents>\r\n    </freetext>\r\n  </annots>\r\n  <f href=\"\" />\r\n</xfdf>";
 | 
	
		
			
				|  |  | -                                //annotation.Data = "<?xml version =\"1.0\" encoding=\"utf-8\"?>\r\n<xfdf xmlns=\"http://ns.adobe.com/xfdf/\" xml:space=\"preserve\">\r\n  <annots>\r\n    <freetext page=\"0\" rect=\"768.7103,558.5799,898.9603,642.3299\" rotation=\"0\" color=\"#FFFFFF\" title=\"ffffffff-ffff-ffff-ffff-ffffffffffff\" subject=\"Free Text\" date=\"D:20220715001146+08'00'\" flags=\"print\" name=\"690a16b1-647b-45a9-80a5-17f83f63bc93\" fringe=\"18,2,20,16.5\" border=\"0,0,1.5\" justification=\"0\" IT=\"FreeTextCallout\" head=\"OpenArrow\" callout=\"786.7103,625.8299,768.7103,593.2049,786.7103,593.2049\">\r\n      <defaultappearance>0.2901961 0.5647059 0.8862745 rg </defaultappearance>\r\n      <defaultstyle>font:Arial 12pt;style:Regular;color:#FF0000</defaultstyle>\r\n      <contents-richtext><body xmlns=\"http://www.w3.org/1999/xhtml\"><p dir=\"ltr\">Hi Thjere\r\n\r\nawd.flae\r\nsdfgljsdlkfg</p></body></contents-richtext>\r\n      <contents>Hi Thjere\r\n\r\nawd.flae\r\nsdfgljsdlkfg</contents>\r\n    </freetext>\r\n  </annots>\r\n  <f href=\"\" />\r\n</xfdf>";
 | 
	
		
			
				|  |  | -                            }
 | 
	
		
			
				|  |  | +                                if (annotation.Data.Contains("<freetext") && !annotation.Data.Contains("date=\""))
 | 
	
		
			
				|  |  | +                                {
 | 
	
		
			
				|  |  | +                                    Logger.Send(LogType.Information, ClientFactory.UserID,
 | 
	
		
			
				|  |  | +                                        string.Format("Annotation #{0} has no date - inserting now..", annotation.ID));
 | 
	
		
			
				|  |  | +                                    annotation.Data = annotation.Data.Replace("<freetext",
 | 
	
		
			
				|  |  | +                                        string.Format("<freetext date=\"D:{0:yyyyMMddHHmmss}+08\'00\'\"",
 | 
	
		
			
				|  |  | +                                            DateTime.Now));
 | 
	
		
			
				|  |  | +                                    //annotation.Data = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<xfdf xmlns=\"http://ns.adobe.com/xfdf/\" xml:space=\"preserve\">\r\n  <annots>\r\n    <freetext page=\"0\" rect=\"635.782,231.8206,812.7407,282.311\" rotation=\"0\" color=\"#FFFFFF\" title=\"ffffffff-ffff-ffff-ffff-ffffffffffff\" subject=\"Free Text\" date=\"D:20220715001146+08'00'\" name=\"800eae13-14f4-4db9-a60e-6d5d2d2adb55\" fringe=\"0,0,0,0\" border=\"0,0,1\" q=\"0\" IT=\"FreeTextCallout\" head=\"None\">\r\n      <defaultappearance>0.2901961 0.5647059 0.8862745 rg </defaultappearance>\r\n      <defaultstyle>font:Arial 8pt;style:Regular;color:#FF0000</defaultstyle>\r\n      <contents-richtext><body xmlns=\"http://www.w3.org/1999/xhtml\"><p dir=\"ltr\">MC'd by BW\r\nTrolley H18\r\n8 July 2022\r\nNOTE: 3032 Doorleaf is also on Trolley H18</p></body></contents-richtext>\r\n      <contents>MC'd by BW\r\nTrolley H18\r\n8 July 2022\r\nNOTE: 3032 Doorleaf is also on Trolley H18</contents>\r\n    </freetext>\r\n  </annots>\r\n  <f href=\"\" />\r\n</xfdf>";
 | 
	
		
			
				|  |  | +                                    //annotation.Data = "<?xml version =\"1.0\" encoding=\"utf-8\"?>\r\n<xfdf xmlns=\"http://ns.adobe.com/xfdf/\" xml:space=\"preserve\">\r\n  <annots>\r\n    <freetext page=\"0\" rect=\"768.7103,558.5799,898.9603,642.3299\" rotation=\"0\" color=\"#FFFFFF\" title=\"ffffffff-ffff-ffff-ffff-ffffffffffff\" subject=\"Free Text\" date=\"D:20220715001146+08'00'\" flags=\"print\" name=\"690a16b1-647b-45a9-80a5-17f83f63bc93\" fringe=\"18,2,20,16.5\" border=\"0,0,1.5\" justification=\"0\" IT=\"FreeTextCallout\" head=\"OpenArrow\" callout=\"786.7103,625.8299,768.7103,593.2049,786.7103,593.2049\">\r\n      <defaultappearance>0.2901961 0.5647059 0.8862745 rg </defaultappearance>\r\n      <defaultstyle>font:Arial 12pt;style:Regular;color:#FF0000</defaultstyle>\r\n      <contents-richtext><body xmlns=\"http://www.w3.org/1999/xhtml\"><p dir=\"ltr\">Hi Thjere\r\n\r\nawd.flae\r\nsdfgljsdlkfg</p></body></contents-richtext>\r\n      <contents>Hi Thjere\r\n\r\nawd.flae\r\nsdfgljsdlkfg</contents>\r\n    </freetext>\r\n  </annots>\r\n  <f href=\"\" />\r\n</xfdf>";
 | 
	
		
			
				|  |  | +                                }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -                            LoadAnnotation(doc, annotation.Data.Replace("&", "+"), annotation.ID);
 | 
	
		
			
				|  |  | +                                LoadAnnotation(doc, annotation.Data.Replace("&", "+"), annotation.ID);
 | 
	
		
			
				|  |  | +                            }
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  | +                        catch (Exception e)
 | 
	
		
			
				|  |  | +                        {
 | 
	
		
			
				|  |  | +                            Logger.Send(LogType.Error, "",
 | 
	
		
			
				|  |  | +                                string.Format("*** Unknown Error: {0}\n{1}", e.Message, e.StackTrace));
 | 
	
		
			
				|  |  |                          }
 | 
	
		
			
				|  |  | -                    }
 | 
	
		
			
				|  |  | -                    catch (Exception e)
 | 
	
		
			
				|  |  | -                    {
 | 
	
		
			
				|  |  | -                        Logger.Send(LogType.Error, "", string.Format("*** Unknown Error: {0}\n{1}", e.Message, e.StackTrace));
 | 
	
		
			
				|  |  | -                    }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -                var ms = new MemoryStream();
 | 
	
		
			
				|  |  | -                doc.Save(ms);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -                PdfViewer.ZoomMode = ZoomMode.FitWidth;
 | 
	
		
			
				|  |  | -                PdfViewer.Load(ms);
 | 
	
		
			
				|  |  | +                    var ms = new MemoryStream();
 | 
	
		
			
				|  |  | +                    doc.Save(ms);
 | 
	
		
			
				|  |  | +                    PdfViewer.ZoomMode = ZoomMode.FitWidth;
 | 
	
		
			
				|  |  | +                    PdfViewer.Load(ms);
 | 
	
		
			
				|  |  | +                    CurrentAnnotations = AnnotationsToString();
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  |                  UpdateButtons(PdfNoneImage);
 | 
	
		
			
				|  |  | -                CurrentAnnotations = AnnotationsToString();
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 |