Beispiel #1
0
 private void button4_Click(object sender, EventArgs e)
 {
     // Here we look at specific style - fonts - that we don't want.
     // However the crucial difference between this and the other examples is
     // that we purge the unused fonts to remove all references from the document.
     using (Doc doc = new Doc()) {
         doc.Read(_src);
         FontTracker tracker = new FontTracker(doc);
         for (int i = 0; i < doc.PageNumber; i++)
         {
             doc.PageNumber = i + 1;
             using (XRect rect = doc.Rect) {
                 List <TextFragment> toKeep    = new List <TextFragment>();
                 List <TextFragment> fragments = FindFont(doc, toKeep);
                 foreach (TextFragment fragment in toKeep)
                 {
                     tracker.Keep(fragment);
                 }
                 SimpleRedaction.RedactTextOps(doc, fragments);
                 doc.Flatten();
             }
         }
         tracker.PurgeForm();
         tracker.Purge();
         string dst = Path.Combine(Directory.GetParent(_src).FullName, "_" + Path.GetRandomFileName() + ".pdf");
         doc.Save(dst);
         _src = dst;
         UpdateDoc();
     }
 }
Beispiel #2
0
        private void button1_Click(object sender, System.EventArgs e)
        {
            // Here we look at an area on the page and redact the text in it
            XRect toRedact = new XRect(textBoxRect.Text);

            using (Doc doc = new Doc()) {
                doc.Read(_src);
                TextOperation op = new TextOperation(doc);
                op.PageContents.AddPages(1);
                string text = op.GetText(toRedact, 1);
                IList <TextFragment> fragments = op.Select(0, text.Length);
                if (radioButtonCoarse.Checked)
                {
                    SimpleRedaction.RedactTextOps(doc, fragments);
                }
                else
                {
                    FineRedaction.RedactCharacters(doc, fragments);
                }
                doc.Flatten();
                string dst = Path.Combine(Directory.GetParent(_src).FullName, "_" + Path.GetRandomFileName() + ".pdf");
                doc.Save(dst);
                _src = dst;
                UpdateDoc();
            }
        }
Beispiel #3
0
 private void button2_Click(object sender, EventArgs e)
 {
     // here we search for some text on the page and then redact it
     using (Doc doc = new Doc()) {
         doc.Read(_src);
         using (XRect rect = doc.Rect) {
             List <TextFragment> fragments = FindText(doc);
             if (radioButtonCoarse.Checked)
             {
                 SimpleRedaction.RedactTextOps(doc, fragments);
             }
             else
             {
                 FineRedaction.RedactCharacters(doc, fragments);
             }
             doc.Flatten();
         }
         string dst = Path.Combine(Directory.GetParent(_src).FullName, "_" + Path.GetRandomFileName() + ".pdf");
         doc.Save(dst);
         _src = dst;
         UpdateDoc();
     }
 }