Thanks again for a quick reply,
Here are the metods that I use to draw the shape and add it to multiple locations.
private static void AddStamp( string documentFile, string saveAsFile, string stampText )
{
// Open document.
Aspose.Words.Document document = new Aspose.Words.Document( documentFile );
// Stamp the first page.
//document.StampOnlyFirstPage( ParagraphAlignment.Center, MyStampText );
document.StampOnlyFirstPageUsingTextBox( ParagraphAlignment.Center, MyStampText );
document.StampOnlyLastPageUsingTextBox( ParagraphAlignment.Center, MyStampText );
// Save the file.
document.Save( saveAsFile );
}
private static void StampOnlyFirstPageUsingTextBox( this Aspose.Words.Document document, ParagraphAlignment alignment, string stamp )
{
// Create textbox
Aspose.Words.Drawing.Shape textboxShape = CreateStampTextBox( document, alignment, stamp );
// Add textbox to the document.
document.FirstSection.Body.FirstParagraph.AppendChild( textboxShape );
}
private static void StampOnlyLastPageUsingTextBox(this Aspose.Words.Document document, ParagraphAlignment alignment, string stamp)
{
// Create textbox.
Aspose.Words.Drawing.Shape textboxShape = CreateStampTextBox( document, alignment, stamp + " LastSection.FirstParagraph" );
// Add textbox to the document.
document.LastSection.Body.FirstParagraph.AppendChild( textboxShape );
Aspose.Words.Drawing.Shape textboxShape2 = CreateStampTextBox(document, alignment, stamp + " LastSection.LastParagraph");
document.LastSection.Body.LastParagraph.AppendChild( textboxShape2 );
}
private static Aspose.Words.Drawing.Shape CreateStampTextBox( Aspose.Words.Document document, ParagraphAlignment alignment, string stamp )
{
// Create textbox shape.
Aspose.Words.Drawing.Shape textboxShape = new Aspose.Words.Drawing.Shape( document, Aspose.Words.Drawing.ShapeType.TextBox );
// Set size.
textboxShape.HorizontalAlignment = Aspose.Words.Drawing.HorizontalAlignment.Center;
textboxShape.VerticalAlignment = Aspose.Words.Drawing.VerticalAlignment.Center;
//textboxShape.Width = 610.4;
textboxShape.Width = 604;
textboxShape.Height = 24;
//textboxShape.Top = 694;
textboxShape.Top = 690;
textboxShape.Fill.Opacity = 0;
textboxShape.Stroke.On = false;
// Create stamp as paragraph of content.
Aspose.Words.Paragraph paragraph = new Aspose.Words.Paragraph( document );
// Set the alignment for the paragraph text.
paragraph.ParagraphFormat.Alignment = alignment;
// Add the content.
paragraph.AppendChild( new Aspose.Words.Run( document, stamp ) );
// Insert paragraph into the textbox.
textboxShape.AppendChild( paragraph );
return textboxShape;
}
///
/// Stamps the first page only.
///
///
///
///
private static void StampOnlyFirstPage( this Aspose.Words.Document document, ParagraphAlignment alignment, string stamp )
{
Aspose.Words.Layout.LayoutCollector layoutCollector = new Aspose.Words.Layout.LayoutCollector(document);
// Get the list of header footers, method will generate footers if needed, and will copy the content from any
// existing one to the new ones.
List< Aspose.Words.HeaderFooter > headerFooters = document.FirstSection.GetFooters( StampFrequency.FirstPageOnly );
int count = 0;
foreach (Aspose.Words.HeaderFooter headerFooter in headerFooters)
{
count++;
headerFooter.StampFooter( alignment, $"{stamp} STAMP #{count}" );
}
}