//// This code is part of Document Solutions for PDF .NET demos.// Copyright (c) MESCIUS inc. All rights reserved.//usingSystem.IO;usingSystem.Drawing;usingGrapeCity.Documents.Pdf;usingGrapeCity.Documents.Pdf.TextMap; namespaceDsPdfWeb.Demos{// Finds all occurrences of a regular expression (specifically,// the regex searches for strings that look like dates or times)// and changes the text rendering attributes of all those occurrences.// The following attributes can be changed:// - Text rendering mode (fill/stroke/clip);// - Text fill color and alpha;// - Text stroke color and alpha.// For reference, the original PDF without changes is appended to the result. // The original PDF and the search regex are the same as used in DeleteText.publicclassChangeTextAttrs {publicintCreatePDF(Stream stream) {var doc = newGcPdfDocument();usingvar fs = File.OpenRead(Path.Combine("Resources", "PDFs", "TimeSheet.pdf")); doc.Load(fs);var pageCount = doc.Pages.Count;// Duplicate the PDF: doc.MergeWithDocument(doc);// Modify text on the first copy:for (int i = 0; i < pageCount; ++i) {var ftps = newFindTextParams(@"\d+/\d+/\d+|\d+:\d+| am| pm", false, false, 72, 72, false, true);// TextRenderingAttrs allows you to specify the following text rendering attributes:// - RenderingMode// - FillAlpha// - FillColor// - StrokeAlpha// - StrokePen doc.Pages[i].SetTextRenderingAttrs(ftps, newTextRenderingAttrs() {RenderingMode = TextRenderingMode.FillStroke,FillColor = Color.Red,FillAlpha = 0.5f,StrokeAlpha = 1.0f,StrokePen = newGrapeCity.Documents.Drawing.Pen(Color.Blue, 1)}); }// Done: doc.Save(stream);return doc.Pages.Count; } }}