Placing Annotations
Annotations can be placed on a page using PostToAnnotationRelationForAnnotation() of Page, or by using PostToAnnotationRelationForDocumentAnnotations() of Document.
The Coordinate System
Annotation locations are specified in twips. That is, one inch is 1440 twips and 1 pt is 20 twips.
For example, the top left corner of a page has the coordinates (0,0). The location two inches right and one inch below the top has the coordinates (2880, 1440).
Also the size of elements and font height is specified in twips. A font size of 10 pt is specified as 200 pt.
This example shows how to convert the coordinates in page resolution.
C#
using DocuWare.Platform.ServerClient;
namespace DocuWare.PlatformClientExamples
{
static partial class Examples
{
public static DWPoint GetConvertedCoordinates(double pageResulutionX, double pageResulutionY, PageData pageData)
{
return new DWPoint()
{
X = pageResulutionX*1440/pageData.DpiX,
Y = pageResulutionY*1440/pageData.DpiY
};
}
}
}
Placing annotations on a page
This example shows how you can place annotations on a page
Warning
By design the Width
and Height
of the AnnotationRectangle
isn't used for the TextEntry
size.
That is why we set those parameters to 0.
The size of the TextEntry
depends on the font size and the length of the text.
For the location of the TextEntry
on the Page
just the Left
and Top
are taken into account.
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DocuWare.Platform.ServerClient;
namespace DocuWare.PlatformClientExamples
{
static partial class Examples
{
public static Annotation PlaceAnnotationsOnPage(Page page, int layer)
{
var annotations = new Annotation()
{
Layer = new List<Layer>()
{
new Layer()
{
Id = 1,
Items = new List<EntryBase>()
{
//Annotation that contains text
new TextEntry()
{
Location = new AnnotationRectangle()
{
Left = 100,
Top = 100,
Width = 0,
Height = 0
},
Value = "AutoTest",
Font = new Font()
{
FontSize = 10*20,
FontName = "Arial"
}
},
//Rectangle or Ellipse annotation
new RectEntry()
{
Location = new AnnotationRectangle()
{
Left = 300,
Top = 300,
Width = 200,
Height = 200
},
Filled = true,
Ellipse = true,
},
//Creates a new instance of this class
new LineEntry()
{
From = new AnnotationPoint() { X = 500, Y = 500 },
To = new AnnotationPoint() { X = 800, Y = 800 },
Arrow = true,
}
}
}
}
};
var placedAnnotations = page.PostToAnnotationRelationForAnnotation(annotations);
return placedAnnotations;
}
}
}
Placing annotations on a page from document object
This example shows how you can place annotations on a page from document object
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DocuWare.Platform.ServerClient;
namespace DocuWare.PlatformClientExamples
{
static partial class Examples
{
public static DocumentAnnotations PlaceAnnotationsOnDocument(this Document document, int layer)
{
var placement = new DocumentAnnotationsPlacement()
{
Annotations = new List<SectionAnnotationsPlacement>()
{
new SectionAnnotationsPlacement()
{
PageNumber = 0,
SectionNumber = 0,
AnnotationsPlacement = new AnnotationsPlacement()
{
Items = new List<object>() { GetAnnotations(layer) }
}
},
new SectionAnnotationsPlacement()
{
PageNumber = 1,
SectionNumber = 1,
AnnotationsPlacement = new AnnotationsPlacement()
{
Items = new List<object>() { GetAnnotations(layer) }
}
},
}
};
var annotations = document.PostToAnnotationRelationForDocumentAnnotations(placement);
return annotations;
}
private static Annotation GetAnnotations(int layer)
{
return new Annotation()
{
Layer = new List<Layer>()
{
new Layer()
{
Id = layer,
Items = new List<EntryBase>()
{
//Annotation that contains text
new TextEntry()
{
Location = new AnnotationRectangle()
{
Left = 100,
Top = 100,
Width = 0,
Height = 0
},
Value = "Holidays",
Font = new Font() { FontSize = 10*20, FontName = "Arial", }
},
//Rectangle or Ellipse annotation
new RectEntry()
{
Location = new AnnotationRectangle()
{
Left = 300,
Top = 300,
Width = 200,
Height = 200
},
Filled = true,
Ellipse = true,
},
//Creates a new instance of this class
new LineEntry()
{
From = new AnnotationPoint() { X = 500, Y = 500 },
To = new AnnotationPoint() { X = 800, Y = 800 },
Arrow = true,
}
}
}
}
};
}
}
}