public static void overlayText(TextMatchEnumerator enumerator, string dsTag) { foreach (TextMatch match in enumerator) { GlyphCollection glyphs = match.Glyphs; Glyph firstGlyph = glyphs[0]; Glyph lastGlyph = glyphs[glyphs.Count - 1]; MultilineTextShape textShape = new MultilineTextShape(); TranslateTransform translate = new TranslateTransform(firstGlyph.BottomLeft.X, firstGlyph.BottomLeft.Y); textShape.Transform = translate; textShape.Width = lastGlyph.TopRight.X - firstGlyph.BottomLeft.X; textShape.Height = lastGlyph.TopRight.Y - firstGlyph.BottomLeft.Y; translate.Y += textShape.Height; textShape.HorizontalAlignment = HorizontalAlignment.Center; textShape.Opacity = 200; Fragment fragment = new Fragment(dsTag, 12); fragment.TextColor = TallComponents.PDF.Colors.RgbColor.Blue; textShape.Fragments.Add(fragment); match.Page.Overlay.Add(textShape); } }
public static void convertPDFDoc(string fileDir, string fileName, string fileExtension) { var Readengine = new FileHelperAsyncEngine <Record>(); //read document goes line by line Readengine.BeginReadFile(DSConfig.CsvTags); using (Readengine) { using (FileStream fileIn = new FileStream(fileDir + "\\" + fileName, FileMode.Open, FileAccess.Read)) { TallComponents.PDF.Document document = new TallComponents.PDF.Document(fileIn); foreach (Record r in Readengine) { //create document TextFindCriteria criteria = new TextFindCriteria(r.CompetitorTag, false, false); TextMatchEnumerator enumerator = document.Find(criteria); overlayText(enumerator, r.DocusignTag); } using (FileStream fileOut = new FileStream(DSConfig.DropoffDir + "\\" + fileName.Substring(0, fileName.Length - fileExtension.Length) + "_converted" + fileExtension, FileMode.Create, FileAccess.Write)) { document.Write(fileOut); } } } }