Quantcast
Channel: Aspose.Pdf Product Family
Viewing all articles
Browse latest Browse all 3131

Updating paragraph not working

$
0
0
Hi, 

I am trying two things here,

1 - Get number of pages after adding some tables to document dynamically, table may have dynamic cells that take more then 1 page.

2 - Update cell text after counting page numbers.

This is what I am doing,

            Document document = new Document();
            Page page = document.Pages.Add();

            Dictionary<int, Cell> dic = new Dictionary<int, Cell>();
            for (int i = 0; i <= 500; i++)
            {
                var table = new Table();
                table.ColumnWidths = "200 200";
                
                Row row = table.Rows.Add();
                Cell c = row.Cells.Add("Row Number: " + i);
                dic.Add(i, c);

                page.Paragraphs.Add(table);
            }

            document.Save(@"C:\beforeUpdatingCell.pdf");
            Console.WriteLine(document.Pages.Count); 
            foreach (var key in dic.Values)
            {
                Cell cc = key;
                cc.Paragraphs.RemoveRange(0, 1);
                cc.Paragraphs.Add(new TextFragment("Updated Text"));
            }

            document.Save(@"C:\updatedCell.pdf");


Above code shows right number of Page counts, but above code doesn't updates the texts


Document document = new Document();
            Page page = document.Pages.Add();

            Dictionary<int, Cell> dic = new Dictionary<int, Cell>();
            for (int i = 0; i <= 500; i++)
            {
                var table = new Table();
                table.ColumnWidths = "200 200";
                
                Row row = table.Rows.Add();
                Cell c = row.Cells.Add("Row Number: " + i);
                dic.Add(i, c);

                page.Paragraphs.Add(table);
            }

            document.Save();
            Console.WriteLine(document.Pages.Count); 
            foreach (var key in dic.Values)
            {
                Cell cc = key;
                cc.Paragraphs.RemoveRange(0, 1);
                cc.Paragraphs.Add(new TextFragment("Updated Text"));
            }

            document.Save(@"C:\updatedCell.pdf");

Above code updates cell text but page count is wrong......

**********************************************************************

I need right number of page count and I also need to update cell's text too

**********************************************************************



This message was posted using Email2Forum by Babar Raza.

Viewing all articles
Browse latest Browse all 3131

Trending Articles