public static void Run()
        {
            //ExStart: AddAndSearchHiddenText
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_Text();

            //Create document with hidden text
            Aspose.Pdf.Document doc = new Aspose.Pdf.Document();
            Page         page       = doc.Pages.Add();
            TextFragment frag1      = new TextFragment("This is common text.");
            TextFragment frag2      = new TextFragment("This is invisible text.");

            //Set text property - invisible
            frag2.TextState.Invisible = true;

            page.Paragraphs.Add(frag1);
            page.Paragraphs.Add(frag2);
            doc.Save(dataDir + "39400_out.pdf");
            doc.Dispose();

            //Search text in the document
            doc = new Aspose.Pdf.Document(dataDir + "39400_out.pdf");
            TextFragmentAbsorber absorber = new TextFragmentAbsorber();

            absorber.Visit(doc.Pages[1]);

            foreach (TextFragment fragment in absorber.TextFragments)
            {
                //Do something with fragments
                Console.WriteLine("Text '{0}' on pos {1} invisibility: {2} ",
                                  fragment.Text, fragment.Position.ToString(), fragment.TextState.Invisible);
            }
            doc.Dispose();
            //ExEnd: AddAndSearchHiddenText
        }
Beispiel #2
0
        private static TextFragmentAbsorber FindPageForText(Document document, string text)
        {
            var textFragmentAbsorber = new TextFragmentAbsorber("(?i)" + text, new TextSearchOptions(true));

            textFragmentAbsorber.Visit(document);

            return(textFragmentAbsorber);
        }
        public static void Run()
        {
            try
            {
                // ExStart:UpdateLinkTextColor
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir_AsposePdf_LinksActions();
                // Load the PDF file
                Document doc = new Document(dataDir + "UpdateLinks.pdf");
                foreach (Annotation annotation in doc.Pages[1].Annotations)
                {
                    if (annotation is LinkAnnotation)
                    {
                        // Search the text under the annotation
                        TextFragmentAbsorber ta = new TextFragmentAbsorber();
                        Rectangle rect = annotation.Rect;
                        rect.LLX -= 10;
                        rect.LLY -= 10;
                        rect.URX += 10;
                        rect.URY += 10;
                        ta.TextSearchOptions = new TextSearchOptions(rect);
                        ta.Visit(doc.Pages[1]);
                        // Change color of the text.
                        foreach (TextFragment tf in ta.TextFragments)
                        {
                            tf.TextState.ForegroundColor = Color.Red;
                        }
                    }

                }
                dataDir = dataDir + "UpdateLinkTextColor_out.pdf";
                // Save the document with updated link
                doc.Save(dataDir);
                // ExEnd:UpdateLinkTextColor
                Console.WriteLine("\nLinkAnnotation text color updated successfully.\nFile saved at " + dataDir);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
 public static void Run()
 {
     try
     {
         // ExStart:UpdateLinkTextColor
         // The path to the documents directory.
         string dataDir = RunExamples.GetDataDir_AsposePdf_LinksActions();
         // Load the PDF file
         Document doc = new Document(dataDir + "UpdateLinks.pdf");
         foreach (Annotation annotation in doc.Pages[1].Annotations)
         {
             if (annotation is LinkAnnotation)
             {
                 // Search the text under the annotation
                 TextFragmentAbsorber ta   = new TextFragmentAbsorber();
                 Rectangle            rect = annotation.Rect;
                 rect.LLX            -= 10;
                 rect.LLY            -= 10;
                 rect.URX            += 10;
                 rect.URY            += 10;
                 ta.TextSearchOptions = new TextSearchOptions(rect);
                 ta.Visit(doc.Pages[1]);
                 // Change color of the text.
                 foreach (TextFragment tf in ta.TextFragments)
                 {
                     tf.TextState.ForegroundColor = Color.Red;
                 }
             }
         }
         dataDir = dataDir + "UpdateLinkTextColor_out.pdf";
         // Save the document with updated link
         doc.Save(dataDir);
         // ExEnd:UpdateLinkTextColor
         Console.WriteLine("\nLinkAnnotation text color updated successfully.\nFile saved at " + dataDir);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
Beispiel #5
0
        public IHttpActionResult SearchData(SearchDataModel searchDataModel)
        {
            //'searchText': moveTo, 'pageList': Npages, 'documentId': documentId
            var fullPath         = Path.Combine(Config.Configuration.WorkingDirectory.Replace("/", "\\"), "Editor", searchDataModel.documentId);
            var documentFileName = Path.Combine(fullPath, "document.pdf");
            //string name = DateTime.Now.Millisecond.ToString();
            var documentFolderInfo = new DirectoryInfo(fullPath);

            foreach (FileInfo file in documentFolderInfo.GetFiles("image*.png"))
            {
                file.Delete();
            }

            Document             document             = new Document(documentFileName);
            TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber(searchDataModel.searchText);

            textFragmentAbsorber.Visit(document);
            foreach (var textFragment in textFragmentAbsorber.TextFragments)
            {
                textFragment.Page.Annotations.Add(
                    new Pdf.Annotations.HighlightAnnotation(textFragment.Page, textFragment.Rectangle)
                {
                    Title = searchMarker
                }
                    );
            }
            document.Save(documentFileName);
            var model = new DocStatusModel
            {
                d                = ImageConverter(documentFileName),
                Path             = searchDataModel.documentId,
                OriginalFileName = ""
            };

            return(Ok(model));
        }