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

            Document doc = new Document(dataDir + "MultiColumnPdf.pdf");

            ParagraphAbsorber absorber = new ParagraphAbsorber();

            absorber.Visit(doc);

            PageMarkup markup = absorber.PageMarkups[0];

            Console.WriteLine("IsMulticolumnParagraphsAllowed == false\r\n");

            MarkupSection   section   = markup.Sections[2];
            MarkupParagraph paragraph = section.Paragraphs[section.Paragraphs.Count - 1];

            Console.WriteLine("Section at {0} last paragraph text:\r\n", section.Rectangle.ToString());
            Console.WriteLine(paragraph.Text);

            section   = markup.Sections[1];
            paragraph = section.Paragraphs[0];

            Console.WriteLine("\r\nSection at {0} first paragraph text:\r\n", section.Rectangle.ToString());
            Console.WriteLine(paragraph.Text);

            markup.IsMulticolumnParagraphsAllowed = true;
            Console.WriteLine("\r\nIsMulticolumnParagraphsAllowed == true\r\n");

            section   = markup.Sections[2];
            paragraph = section.Paragraphs[section.Paragraphs.Count - 1];

            Console.WriteLine("Section at {0} last paragraph text:\r\n", section.Rectangle.ToString());
            Console.WriteLine(paragraph.Text);

            section   = markup.Sections[1];
            paragraph = section.Paragraphs[0];

            Console.WriteLine("\r\nSection at {0} first paragraph text:\r\n", section.Rectangle.ToString());
            Console.WriteLine(paragraph.Text);

            // ExEnd:MulticolumnParagraphs
        }
Exemplo n.º 2
0
        public List <ParaDetails> FetchParagraph(string path, string phrase)
        {
            var paraDetails = new List <ParaDetails>();

            InjectAsposeLicemse();

            Aspose.Pdf.Document document = new Aspose.Pdf.Document(path);
            ParagraphAbsorber   absorber = new ParagraphAbsorber();

            absorber.Visit(document);
            foreach (PageMarkup markup in absorber.PageMarkups)
            {
                int i = 1;
                foreach (MarkupSection section in markup.Sections)
                {
                    int j = 1;
                    foreach (MarkupParagraph paragraph in section.Paragraphs)
                    {
                        StringBuilder paragraphText = new StringBuilder();

                        foreach (List <TextFragment> line in paragraph.Lines)
                        {
                            foreach (TextFragment fragment in line)
                            {
                                paragraphText.Append(fragment.Text);
                            }
                            paragraphText.Append("\r\n");
                        }
                        paragraphText.Append("\r\n");
                        var paratext = paragraphText.ToString();
                        if (paratext.Contains(phrase, StringComparison.InvariantCultureIgnoreCase))
                        {
                            var paraDetail = new ParaDetails();
                            paraDetail.Details = string.Format("Page {2}, Section {1}, Paragraph {0} says:", j, i, markup.Number);
                            paraDetail.Text    = paratext;
                            paraDetails.Add(paraDetail);
                        }
                        j++;
                    }
                    i++;
                }
            }
            return(paraDetails);
        }
        public static void Run()
        {
            // ExStart:1
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_Text();
            // Open an existing PDF file
            Document doc = new Document(dataDir + "input.pdf");
            // Instantiate ParagraphAbsorber
            ParagraphAbsorber absorber = new ParagraphAbsorber();

            absorber.Visit(doc);

            foreach (PageMarkup markup in absorber.PageMarkups)
            {
                int i = 1;
                foreach (MarkupSection section in markup.Sections)
                {
                    int j = 1;

                    foreach (MarkupParagraph paragraph in section.Paragraphs)
                    {
                        StringBuilder paragraphText = new StringBuilder();

                        foreach (List <TextFragment> line in paragraph.Lines)
                        {
                            foreach (TextFragment fragment in line)
                            {
                                paragraphText.Append(fragment.Text);
                            }
                            paragraphText.Append("\r\n");
                        }
                        paragraphText.Append("\r\n");

                        Console.WriteLine("Paragraph {0} of section {1} on page {2}:", j, i, markup.Number);
                        Console.WriteLine(paragraphText.ToString());

                        j++;
                    }
                    i++;
                }
            }
            // ExEnd:1
        }
Exemplo n.º 4
0
        // ExStart:1
        private static void ExtractParagraph()
        {
            // The path to the documents directory.
            string   dataDir = RunExamples.GetDataDir_AsposePdf_Text();
            Document doc     = new Document(dataDir + "input.pdf");
            Page     page    = doc.Pages[2];

            ParagraphAbsorber absorber = new ParagraphAbsorber();

            absorber.Visit(page);

            PageMarkup markup = absorber.PageMarkups[0];

            foreach (MarkupSection section in markup.Sections)
            {
                DrawRectangleOnPage(section.Rectangle, page);
                foreach (MarkupParagraph paragraph in section.Paragraphs)
                {
                    DrawPolygonOnPage(paragraph.Points, page);
                }
            }

            doc.Save(dataDir + "output_out.pdf");
        }