//// This code is part of Document Solutions for Word demos.// Copyright (c) MESCIUS inc. All rights reserved.//usingSystem.IO;usingSystem.Drawing;usingGrapeCity.Documents.Word;usingGrapeCity.Documents.Word.Layout;usingGrapeCity.Documents.Pdf.Annotations; namespaceDsWordWeb.Demos{// This sample demonstrates the DsWord Layout API that allows developers during export// to PDF to locate in the exported document the Data Template tags and to highlight// them or process in some other way. Note that this sample does not bind the template// to data (i.e. it does not call the GcWordDocument.DataTemplate.Process() method),// it only highlights the tags when the template document is exported to PDF.// This functionality can be used for example to review the templates prior to further processing.// To use the API when exporting the DOCX:// - Set MarkTemplateTagAreas to true in WordLayoutSettings, and// - Specify your custom MarkupTemplateTags method in PdfOutputSettings.// // See also: XingTemplateTags for an example of using this API to modify the tags in the original DOCX.publicclassMarkTagsInPDF {publicGcWordDocumentCreateDocx() {var doc = newGcWordDocument(); doc.Load(Path.Combine("Resources", "WordDocs", "House_Rental_Template.docx"));return doc; } // Custom Word Layout settings set the MarkTemplateTagAreas property set to true,// this makes the layout engine mark locations of Report/Data Template tags// in the layout result, so that the tags can be for example highlighted// for custom processing.publicstaticWordLayoutSettingsGetWordLayoutSettings() {returnnewWordLayoutSettings() {MarkTemplateTagAreas = true }; } // Custom PDF output settings include a MarkupTemplateTags method// that adds markup annotations over Report/Data Template tags// present in the original DOCX. For this to work, the WordLayoutSettings// (see above) must have the MarkTemplateTagAreas property set to true// (it is false by default).publicstaticPdfOutputSettingsGetPdfOutputSettings() {var settings = newPdfOutputSettings() {MarkupTemplateTags = (page, tags) => {foreach (var tag in tags) {foreach (var rect in tag.Areas) {var hilight = newTextMarkupAnnotation {Area = [rect],Color = Color.YellowGreen,MarkupType = TextMarkupType.Highlight,Opacity = 0.4f,RichText = $"Tag Info:<br>Name: <b>{tag?.Info?.Name}</b><br>Text: <b>{tag?.Info?.Text}</b>", }; page.Annotations.Add(hilight); } } } };return settings; } }}