private string CleanBoilerPlate(string report) { var clean = Redaction.TestCleanBoilerPlate(report); _output?.WriteLine("CLEANED TEXT:\n---\n{0}\n---", clean); return(clean); }
private string Redact(string report) { var redacted = Redaction.Redact(report, ""); _output?.WriteLine("REDACTED TEXT:\n---\n{0}\n---", redacted); return(redacted); }
public void TestRedaction() { Assert.Equal("Hello my name is [REDACTED] [REDACTED]. [REDACTED]", Redaction.Redact("Hello my name is John Smith. 77 Broadway Ave., Oxford, OX12 9GE", "John,Smith")); Assert.Equal("Hello my name is [REDACTED] [REDACTED]. I have an appointment with a doctor. [REDACTED]", Redaction.Redact("Hello my name is John Smith. I have an appointment with a doctor. 77 Broadway Ave., Oxford, OX12 9GE", "John,Smith")); }
private string WipeoutReports(string report) { var clean = Redaction.TestWipeoutReportsMatchingRemovalMarkers(report); if (clean != null) { _output?.WriteLine("FAILED TEXT:\n---\n{0}\n---", clean); } return(clean); }
public JsonResult GetNewRedaction(Rectangle Rectangle = null) { ExceptionsML bizEx = null; var redaction = new Redaction(); if (Rectangle != null) { redaction = new Redaction(Rectangle); } return(Result(redaction, bizEx, JsonRequestBehavior.AllowGet)); }
/// <summary> /// Returns RedactionsXML string and object collection for redactions. /// Somewhere herein, real values are rounded to integers as necessary. /// </summary> /// <param name="jsRedactions">stringified redaction objects</param> private object SetRedactions(string jsRedactions, ref ExceptionsML bizEx) { string redactionsXML = null; List <Redaction> redactions = new List <Redaction>(); if (!string.IsNullOrEmpty(jsRedactions)) { try { redactions = Redaction.JsonDeserializeList(jsRedactions); redactionsXML = XmlSerializerExtension.XmlSerialize <List <Redaction> >(redactions); } catch (Exception ex) { bizEx = ExceptionsML.GetExceptionML(ex); } } var result = new { redactionsXML, redactions }; return(result); }
public void TestNhsNumberRedaction() { Assert.Equal("[REDACTED] [REDACTED] [REDACTED]", Redaction.Redact("1234567891 123 456 7891 123-456-7891", "")); }
private static string Wipeout(string report) { return(Redaction.TestWipeoutReportsMatchingRemovalMarkers(report)); }
static void Main(string[] args) { Console.WriteLine("Redactions Sample:"); // ReSharper disable once UnusedVariable using (Library lib = new Library()) { Console.WriteLine("Initialized the library."); String sInput = Library.ResourceDirectory + "Sample_Input/sample.pdf"; String sOutput1 = "Redactions-out.pdf"; String sOutput2 = "Redactions-out-applied.pdf"; if (args.Length > 0) { sInput = args[0]; } Console.WriteLine("Input file: " + sInput); Document doc = new Document(sInput); Page docpage = doc.GetPage(0); // // Redact occurrences of the word "rain" on the page. // Redact occurrences of the word "cloudy" on the page, changing the display details. // // For a more in-depth example of using the WordFinder, see the TextExtract sample. // // The TextExtract sample is described here. // http://dev.datalogics.com/adobe-pdf-library/sample-program-descriptions/net-sample-programs/extracting-text-from-pdf-files // List <Quad> cloudyQuads = new List <Quad>(); List <Quad> rainQuads = new List <Quad>(); WordFinderConfig wordConfig = new WordFinderConfig(); WordFinder wf = new WordFinder(doc, WordFinderVersion.Latest, wordConfig); IList <Word> words = wf.GetWordList(docpage.PageNumber); foreach (Word w in words) { Console.WriteLine(" " + w.Text.ToLower()); // Store the Quads of all "Cloudy" words in a list for later use in // creating the redaction object. if (w.Text.ToLower().Equals("cloudy") || ((w.Attributes & WordAttributeFlags.HasTrailingPunctuation) == WordAttributeFlags.HasTrailingPunctuation && w.Text.ToLower().StartsWith("cloudy"))) { cloudyQuads.AddRange(w.Quads); } // Store the Quads of all "Rain" words if (w.Text.ToLower().Equals("rain") || ((w.Attributes & WordAttributeFlags.HasTrailingPunctuation) == WordAttributeFlags.HasTrailingPunctuation && w.Text.ToLower().StartsWith("rain"))) { rainQuads.AddRange(w.Quads); } } Console.WriteLine("Found Cloudy instances: " + cloudyQuads.Count); Color red = new Color(1.0, 0.0, 0.0); Color white = new Color(1.0); Redaction not_cloudy = new Redaction(docpage, cloudyQuads, red); /* fill the "normal" appearance with 20% red */ not_cloudy.FillNormal = true; not_cloudy.SetFillColor(red, 0.25); Console.WriteLine("Found rain instances: " + rainQuads.Count); Redaction no_rain = new Redaction(docpage, rainQuads); no_rain.InternalColor = new Color(0.0, 1.0, 0.0); /* Fill the redaction with the word "rain", drawn in white */ no_rain.OverlayText = "rain"; no_rain.Repeat = true; no_rain.ScaleToFit = true; no_rain.TextColor = white; no_rain.FontFace = "CourierStd"; no_rain.FontSize = 8.0; doc.Save(SaveFlags.Full, sOutput1); Console.WriteLine("Wrote a pdf doc with unapplied redactions."); // actually all the redactions in the document doc.ApplyRedactions(); doc.Save(SaveFlags.Full, sOutput2); Console.WriteLine("Wrote a redacted pdf doc."); } }
static void Main(string[] args) { Console.WriteLine("AddRegexRedaction Sample:"); using (Library lib = new Library()) { Console.WriteLine("Initialized the library."); String sInput = Library.ResourceDirectory + "Sample_Input/AddRegexRedaction.pdf"; String sOutput1 = "AddRegexRedaction-out.pdf"; String sOutput2 = "AddRegexRedaction-out-applied.pdf"; // Highlight and redact occurrences of the phrases that match this regular expression. // Uncomment only the one you are interested in seeing displayed redacted. // Phone numbers String sRegex = "((1-)?(\\()?\\d{3}(\\))?(\\s)?(-)?\\d{3}-\\d{4})"; // Email addresses //String sRegex = "(\\b[\\w.!#$%&'*+\\/=?^`{|}~-]+@[\\w-]+(?:\\.[\\w-]+)*\\b)"; // URLs //String sRegex = "((https?:\\/\\/(?:www\\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\\.[^\\s]{2,}|www\\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\\.[^\\s]{2,}|https?:\\/\\/(?:www\\.|(?!www))[a-zA-Z0-9]+\\.[^\\s]{2,}|www\\.[a-zA-Z0-9]+\\.[^\\s]{2,}))"; if (args.Length > 0) { sInput = args[0]; } using (Document doc = new Document(sInput)) { int nPages = doc.NumPages; Console.WriteLine("Input file: " + sInput); // Create a WordFinder configuration WordFinderConfig wordConfig = new WordFinderConfig(); // Need to set this to true so phrases will be concatenated properly wordConfig.NoHyphenDetection = true; // Create a DocTextFinder with the default wordfinder parameters using (DocTextFinder docTextFinder = new DocTextFinder(doc, wordConfig)) { // Retrieve the phrases and words matching a regular expression IList <DocTextFinderMatch> docMatches = docTextFinder.GetMatchList(0, nPages - 1, sRegex); // Redaction color will be red Color red = new Color(1.0, 0.0, 0.0); foreach (DocTextFinderMatch wInfo in docMatches) { // Show the matching phrase Console.WriteLine(wInfo.MatchString); // Get the quads IList <DocTextFinderQuadInfo> QuadInfo = wInfo.QuadInfo; // Iterate through the quad info and create highlights foreach (DocTextFinderQuadInfo qInfo in QuadInfo) { Page docpage = doc.GetPage(qInfo.PageNum); Redaction red_fill = new Redaction(docpage, qInfo.Quads, red); /* fill the "normal" appearance with 25% red */ red_fill.FillNormal = true; red_fill.SetFillColor(red, 0.25); } } } // Save the document with the highlighted matched strings doc.Save(SaveFlags.Full, sOutput1); Console.WriteLine("Wrote a PDF document with unapplied redactions."); // Apply all the redactions in the document doc.ApplyRedactions(); // Save the document with the redacted matched strings doc.Save(SaveFlags.Full, sOutput2); Console.WriteLine("Wrote a redacted PDF document."); } } }
private static string GeneratePDF(UserDataJsonModel model, bool applyRedaction) { Library.Initialize(serialNo, key); try { // Create a new PDF with a blank page. using PDFDoc doc = new PDFDoc(); using Form form = new Form(doc); using PDFPage page = doc.InsertPage(0, PDFPage.Size.e_SizeLetter); // Create a text field for each property of the user data json model. int iteration = 0; foreach (var prop in model.GetType().GetProperties()) { int offset = iteration * 60; using Control control = form.AddControl(page, prop.Name, Field.Type.e_TypeTextField, new RectF(50f, 600f - offset, 400f, 640f - offset)); using Field field = control.GetField(); var propValue = prop.GetValue(model); field.SetValue($"{prop.Name}: {propValue}"); iteration++; } // Convert fillable form fields into readonly text labels. page.Flatten(true, (int)PDFPage.FlattenOptions.e_FlattenAll); if (applyRedaction) { // Configure our text search to look at the first (and only) page in our PDF. using var redaction = new Redaction(doc); page.StartParse((int)foxit.pdf.PDFPage.ParseFlags.e_ParsePageNormal, null, false); using TextPage textPage = new TextPage(page, (int)foxit.pdf.TextPage.TextParseFlags.e_ParseTextUseStreamOrder); using TextSearch search = new TextSearch(textPage); RectFArray rectArray = new RectFArray(); // Mark text starting with the pattern "SIN:" to be redacted. search.SetPattern("SIN:"); while (search.FindNext()) { using var searchSentence = new TextSearch(textPage); var sentence = search.GetMatchSentence(); searchSentence.SetPattern(sentence.Substring(sentence.IndexOf("SIN:"))); while (searchSentence.FindNext()) { RectFArray itemArray = searchSentence.GetMatchRects(); rectArray.InsertAt(rectArray.GetSize(), itemArray); } } // If we had matches to redact, then apply the redaction. if (rectArray.GetSize() > 0) { using Redact redact = redaction.MarkRedactAnnot(page, rectArray); redact.SetFillColor(0xFF0000); redact.ResetAppearanceStream(); redaction.Apply(); } } // Save the file locally and return the file's location to the caller. string fileOutput = "./Output.pdf"; doc.SaveAs(fileOutput, (int)PDFDoc.SaveFlags.e_SaveFlagNoOriginal); return(fileOutput); } finally { Library.Release(); } }