Aspose code is inserting Viewmaster(vertical) with default date to select as a text inside. I want to replace with some text as shown in the image.
Followed the code mentioned in
CodePudding user response:
Date is set in structured document tag. You can use code like this to get and modify value of this SDT:
// Get structured document tags from footer. NodeCollection tags = doc.FirstSection.HeadersFooters[HeaderFooterType.FooterPrimary].GetChildNodes(NodeType.StructuredDocumentTag, true); foreach (StructuredDocumentTag tag in tags) { if (tag.Title.Equals("Date") && tag.SdtType == SdtType.Date) { tag.IsShowingPlaceholderText = false; tag.FullDate = DateTime.Now; // By default SDT is minded to XML. We can simply remove mapping to use value set in FullDate property. tag.XmlMapping.Delete(); } }
If you do not need date, but need to insert some custom text, you can remove the tag and insert a simple paragraph with text instead. For example:
// Get structured document tags from footer. NodeCollection tags = doc.FirstSection.HeadersFooters[HeaderFooterType.FooterPrimary].GetChildNodes(NodeType.StructuredDocumentTag, true); foreach (StructuredDocumentTag tag in tags) { if (tag.Title.Equals("Date") && tag.SdtType == SdtType.Date) { // Put an empty paragraph ater the structured document tag Paragraph p = new Paragraph(doc); tag.ParentNode.InsertAfter(p, tag); // Remove tag tag.Remove(); // move DocumentBuilder to the newly inserted paragraph and insert some text. builder.MoveTo(p); builder.Write("This is my custom vertical text"); } }