Cannot find Table in Aspose.Pdf

Hi There,



I’m trying to create a table and set it as watermark to an existing pdf file. Is there any example for this? I looked at stamp, don’t think that will apply to Table.

Also, I was looking at this example
http://www.aspose.com/docs/display/pdfnet/Add+Table+in+Existing+PDF+Document

Here are some sample code from my project.
            var pdfDocument = new Aspose.Pdf.Document(“test1.pdf”);

        <span style="color:blue;">var</span> table = <span style="color:blue;">new</span> Aspose.Pdf.<span style="color:red;">Table</span>();

        pdfDocument.Pages[1].<span style="color:red;">Paragraphs</span>.Add(table);</pre></div><div>1) it seems like Table doesn't exist in Aspose.Pdf</div><div>2) Paragraphs doesn not exist in pdf page</div><div><br></div><div>I'm using Aspose 7.0.0.0.</div><div><br></div><div>regards</div><div>Thank you</div>

Hi James,


Thanks for using our products.

In order to display the table in PDF file, you need to at least add one row and once column to table object and set its border information.

Now concerning to missing Paragraphs collection in page object, I am not certain about the exact release version in which this class was added but when using the latest release of Aspose.Pdf for .NET 8.5.0, table is properly being added to PDF file. We are sorry for your inconvenience.

Please take a look over following code snippet which loads an existing PDF file and adds a table inside it.

[C#]

Document doc = new Document(“c:/pdftest/input.pdf”);

// add text fragment as heading<o:p></o:p>

Aspose.Pdf.Text.TextFragment top_heading = new TextFragment(“TOP SECRET DOCUMENT HEADER”);<o:p></o:p>

top_heading.TextState.BackgroundColor = Aspose.Pdf.Color.Yellow;<o:p></o:p>

top_heading.Margin.Bottom = 30;<o:p></o:p>

// add text fragment to document<o:p></o:p>

doc.Pages[1].Paragraphs.Add(top_heading);<o:p></o:p>

// add text fragment as heading<o:p></o:p>

Aspose.Pdf.Text.TextFragment test_heading = new TextFragment(“This document contains top secret information about something.”);<o:p></o:p>

test_heading.Margin.Bottom = 30;<o:p></o:p>

// add text fragment to document<o:p></o:p>

doc.Pages[1].Paragraphs.Add(test_heading);<o:p></o:p>

// add text fragment as heading<o:p></o:p>

Aspose.Pdf.Text.TextFragment table_heading = new TextFragment(“Table”);<o:p></o:p>

table_heading.TextState.ForegroundColor = Aspose.Pdf.Color.Yellow;<o:p></o:p>

table_heading.TextState.BackgroundColor = Aspose.Pdf.Color.Green;<o:p></o:p>

table_heading.Margin.Bottom = 30;<o:p></o:p>

// add text fragment to document<o:p></o:p>

doc.Pages[1].Paragraphs.Add(table_heading);<o:p></o:p>

Aspose.Pdf.Table table = new Aspose.Pdf.Table();<o:p></o:p>

table.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 0.5f, Aspose.Pdf.Color.Black);<o:p></o:p>

table.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 0.5f, Aspose.Pdf.Color.Black);<o:p></o:p>

Aspose.Pdf.Row HeaderRow = new Aspose.Pdf.Row();<o:p></o:p>

HeaderRow.FixedRowHeight = 15;<o:p></o:p>

// default padding information for header row contents<o:p></o:p>

HeaderRow.DefaultCellPadding = new Aspose.Pdf.MarginInfo(5, 0, 0, 0);<o:p></o:p>

// add row to table object<o:p></o:p>

table.Rows.Add(HeaderRow);<o:p></o:p>

// add a blank cell in header row<o:p></o:p>

HeaderRow.Cells.Add(new Aspose.Pdf.Cell());<o:p></o:p>

// add a new cell to HeaderRow and set background color to red<o:p></o:p>

HeaderRow.Cells.Add(new Aspose.Pdf.Cell() { BackgroundColor = Aspose.Pdf.Color.Red });<o:p></o:p>

// contents of second cell in header row<o:p></o:p>

HeaderRow.Cells[1].Paragraphs.Add(new Aspose.Pdf.Text.TextFragment(“Header1”));<o:p></o:p>

// add a new cell to HeaderRow and set background color to Blue<o:p></o:p>

HeaderRow.Cells.Add(new Aspose.Pdf.Cell() { BackgroundColor = Aspose.Pdf.Color.DodgerBlue });<o:p></o:p>

// contents of second cell in header row<o:p></o:p>

HeaderRow.Cells[2].Paragraphs.Add(new Aspose.Pdf.Text.TextFragment(“Header2”));<o:p></o:p>

// add a new cell to HeaderRow and set background color to red<o:p></o:p>

HeaderRow.Cells.Add(new Aspose.Pdf.Cell() { BackgroundColor = Aspose.Pdf.Color.Yellow });<o:p></o:p>

// contents of second cell in header row<o:p></o:p>

HeaderRow.Cells[3].Paragraphs.Add(new Aspose.Pdf.Text.TextFragment(“Header3”));<o:p></o:p>

// add few row to table object<o:p></o:p>

for(int row_counter =1; row_counter<=6;row_counter++)<o:p></o:p>

{<o:p></o:p>

Aspose.Pdf.Row sample_row = new Aspose.Pdf.Row();<o:p></o:p>

sample_row.FixedRowHeight = 15;<o:p></o:p>

sample_row.DefaultCellPadding = new Aspose.Pdf.MarginInfo(5, 0,0,0);<o:p></o:p>

sample_row.Cells.Add(“Row” + row_counter);<o:p></o:p>

sample_row.Cells.Add(“” + row_counter + “,” + row_counter * 2);<o:p></o:p>

sample_row.Cells.Add(“” + row_counter + “,” + row_counter * 3);<o:p></o:p>

sample_row.Cells.Add(“” + row_counter + “,” + row_counter * 4);<o:p></o:p>

table.Rows.Add(sample_row);<o:p></o:p>

}<o:p></o:p>

// add table to PDF file<o:p></o:p>

doc.Pages[1].Paragraphs.Add(table);<o:p></o:p>

//save the PDF file<o:p></o:p>

doc.Save(“c:/pdftest/TextBackGround.pdf”);

Hi Nayyer,



Could you please confirm when did Paragraphs collection in page object and Aspose.Pdf.Table got added?

As I have mentioned earlier, I’m using 7.0.0.0 and I couldn’t find these two.


Thank you

regards

Hi James,


I am afraid currently I am not certain about the exact release version in which Aspose.Pdf.Table and Paragraphs collection was added in Page object but I would still recommend you to please try using the latest release. The version of Aspose.Pdf for .NET 7.0.0 is around one year old and I am afraid we might not be able to fix the issue in older release version.

We apologize for your inconvenience.