Placing Stamps
Stamps can be placed on a page using PostToStampRelationForAnnotation() of Page, or by using PostToAnnotationRelationForDocumentAnnotations() of Document.
Note
If Location property of StampPlacement is not specified stamp is automatically placed on the best matching empty region on the page.
Note
If the stamp has form fields, then you should specify their values in Field of StampPlacement.
Note
If the stamp is password protected you must fill the Password property of StampPlacement with the password of the current user.
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 a stamp on a page
This example shows how you can place a stamp on a page
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 void PlaceStampOnPage(Page page, string stampId, int layer, DWPoint location)
{
var placedStamp = page.PostToStampRelationForAnnotation(new StampPlacement()
{
StampId = stampId,
Layer = layer,
Location = location,
Field = new List<FormFieldValue>()
{
new FormFieldValue() {
Name = "<#1>",
TypedValue = new DocumentIndexFieldValue()
{
ItemElementName = ItemChoiceType.DateTime,
Item = DateTime.UtcNow,
},
},
new FormFieldValue() {
Name = "<#2>",
TypedValue = new DocumentIndexFieldValue()
{
ItemElementName = ItemChoiceType.Keywords,
Item = new DocumentIndexFieldKeywords()
{
Keyword = new List<string>()
{
"qwe",
"123"
}
}
},
},
new FormFieldValue() {
Name = "<#3>",
TypedValue = new DocumentIndexFieldValue()
{
ItemElementName = ItemChoiceType.String,
Item = "Some value"
}
}
},
});
}
}
}
Placing a stamp on a page from document object
This example shows how you can place a stamp 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 PlaceStampOnDocument(
this Document document,
int sectionNumber, int page,
int layer, DWPoint location, string stampId)
{
var documentStampPlacement = new DocumentAnnotationsPlacement()
{
Annotations = new List<SectionAnnotationsPlacement>()
{
new SectionAnnotationsPlacement()
{
PageNumber = page,
SectionNumber = sectionNumber,
AnnotationsPlacement = new AnnotationsPlacement()
{
Items = new List<object>()
{
GetStampPlacement(layer, location, stampId)
}
}
},
}
};
return document.PostToAnnotationRelationForDocumentAnnotations(documentStampPlacement);
}
private static StampPlacement GetStampPlacement(int layer, DWPoint location, string stampId)
{
return new StampPlacement()
{
StampId = stampId,
Layer = layer,
Location = location,
Field = new List<FormFieldValue>()
{
new FormFieldValue()
{
Name = "<#1>",
TypedValue = new DocumentIndexFieldValue()
{
ItemElementName = ItemChoiceType.DateTime,
Item = DateTime.UtcNow,
},
},
new FormFieldValue()
{
Name = "<#2>",
TypedValue = new DocumentIndexFieldValue()
{
ItemElementName = ItemChoiceType.Keywords,
Item = new DocumentIndexFieldKeywords()
{
Keyword = new List<string>()
{
"Hotel",
"Booking"
}
}
},
},
new FormFieldValue()
{
Name = "<#3>",
TypedValue = new DocumentIndexFieldValue()
{
ItemElementName = ItemChoiceType.String,
Item = "Holidays"
}
}
},
};
}
}
}
Retrieve Best Stamp Location
This example shows how you can retrieve best location for a stamp
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
{
/// <summary>
/// Gets the best location for a stamp.
/// </summary>
/// <param name="page"></param>
/// <param name="stamp"></param>
/// <returns></returns>
public static DWPoint GetBestStampLocation(Page page, Stamp stamp)
{
// get the point of the best position
var point = page.PostToStampBestPositionRelationForDWPoint(new StampFormFieldValues() { StampId = stamp.Id });
return point;
}
}
}