Problems with pages added by repeating table

Hello,
When I add a table to the last page of an existing pdf document, the rows on the existing page are just fine. However, the new page added by the repeating table has problems.

  1. Added page changes to portrait instead of landscape like the existing page.
  2. Added page no longer has the footer.
  3. Table on the added page is vertically centered, instead of top-aligned.
  4. Scrolling to the last page in Adobe Acrobat shows an error.
    (“An error exists on this page. Acrobat may not display this page correctly. Please contact the person who created the PDF document to correct the problem.”)

Here is the process I use:

  1. I open an existing pdf document.
  2. I create a new table, then add rows and cells to the table.
  3. I add the table to the last existing page of the document.
    LastPage.Paragraphs.Add(table);

Can anyone help with any of the 4 problems? (I am new to pdf programming, so I am probably missing basic concepts.)

Thanks
-Greg

@Greg_Peters

Thank you for contacting support.

Would you please share narrowed down code snippet along with source and generated file so that we may try to reproduce and investigate it in our environment. Before sharing requested data, please ensure using Aspose.PDF for .NET 18.11.

Hello,

// This function dynamically adds a table that spans 2 pages to an existing pdf document.
static private void AddTable(Aspose.Pdf.Document pdf, Aspose.Pdf.Text.TextFragment textFragment)
{
// local function to create cell stles for header row and data rows
Aspose.Pdf.Text.TextState GetStyle(bool bHeader, string sName, int nSize, Aspose.Pdf.HorizontalAlignment eAlign)
{
Aspose.Pdf.Text.TextState rc = new Aspose.Pdf.Text.TextState(sName, nSize);
rc.HorizontalAlignment = eAlign;
if (bHeader)
{
rc.FontStyle = Aspose.Pdf.Text.FontStyles.Bold;
}
return rc;
}
try
{
// Create the styles
Aspose.Pdf.Text.TextState tsLH = GetStyle(true, “Tahoma”, 8, Aspose.Pdf.HorizontalAlignment.Left);
Aspose.Pdf.Text.TextState tsCH = GetStyle(true, “Tahoma”, 8, Aspose.Pdf.HorizontalAlignment.Center);
Aspose.Pdf.Text.TextState tsRH = GetStyle(true, “Tahoma”, 8, Aspose.Pdf.HorizontalAlignment.Right);

	Aspose.Pdf.Text.TextState tsL = GetStyle(false, "Tahoma", 9, Aspose.Pdf.HorizontalAlignment.Left);
	Aspose.Pdf.Text.TextState tsC = GetStyle(false, "Tahoma", 9, Aspose.Pdf.HorizontalAlignment.Center);
	Aspose.Pdf.Text.TextState tsR = GetStyle(false, "Tahoma", 9, Aspose.Pdf.HorizontalAlignment.Right);

	// Create new table
	Aspose.Pdf.Table table = new Aspose.Pdf.Table();
			
	// Set column widths of the table
	table.ColumnWidths = "40 220 40 40 40 60 60 45";
	table.RepeatingRowsCount = 1;
	table.DefaultCellPadding = new Aspose.Pdf.MarginInfo(2, 2, 2, 2);

	// Set the border for table cells
	table.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.Bottom, 1.0f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.DarkGray));

	// Add the header row
	Aspose.Pdf.Row oRow = table.Rows.Add();
	oRow.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.Bottom | Aspose.Pdf.BorderSide.Top, 1.0f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.DarkGray));
	oRow.BackgroundColor = Aspose.Pdf.Color.FromArgb(231, 231, 231);

	// Stuff the header cells
	oRow.Cells.Add("SIC", tsCH);
	oRow.Cells.Add("Business Description", tsLH);
	oRow.Cells.Add("Sales", tsRH);
	oRow.Cells.Add("DE", tsRH);
	oRow.Cells.Add("Price", tsRH);
	oRow.Cells.Add("Price/Sales", tsRH);
	oRow.Cells.Add("Price/DE", tsRH);
	oRow.Cells.Add("State(s)", tsRH);

	// Add enough rows to the table to need 2 pages
	int iRow;
	string strRow = "";
	for (iRow = 0; iRow <= 50; iRow++)
	{
		strRow = iRow.ToString();
		oRow = table.Rows.Add();
		oRow.Cells.Add("SIC " + strRow, tsC); // H_SIC
		oRow.Cells.Add("Text description " + strRow, tsL); // H_Business_Description
		oRow.Cells.Add("$" + strRow, tsR); // I1_Gross_Sales
		oRow.Cells.Add("$" + strRow, tsR); // I1_EBT
		oRow.Cells.Add("$" + strRow, tsR); // T_Selling_Price
		oRow.Cells.Add(strRow + ".23", tsR); // PriceToSales
		oRow.Cells.Add(strRow + ".54", tsR); // PriceToEBT
		oRow.Cells.Add("CO", tsR); // H_StateCode
	}
	// Remove the table anchor text
	textFragment.Text = "";

	// Add the table
	textFragment.Page.Paragraphs.Add(table);

	// When the resulting file is opened in Acrobat
	// 1. Last page is portrait instead of landscape
	// 2. Table is not at the top of the last page
	// 3. Footer on last page is missing
	// 4. Acrobat says last page has an error
}
catch (Exception ex)
{
}

}

// This function just
// 1. Opens the source file (pdfSource.pdf)
// 2. Finds where to add the table
// 3. Calls AddTable to add the table
// 4. Save the modified doc into the result file (pdfResult.pdf)
private void btnTest_Click(object sender, EventArgs e)
{
try
{
string sSource = Path.Combine(Application.StartupPath, “pdfSource.pdf”);
string sResult = Path.Combine(Application.StartupPath, “pdfResult.pdf”);

	Aspose.Pdf.Document pdf = new Aspose.Pdf.Document(sSource);
	Aspose.Pdf.Text.TextFragmentAbsorber textFragmentAbsorber = new Aspose.Pdf.Text.TextFragmentAbsorber("SAMPLE_COMPS_TABLE");

	Aspose.Pdf.Text.TextSearchOptions textSearchOptions = new Aspose.Pdf.Text.TextSearchOptions(true);
	textFragmentAbsorber.TextSearchOptions = textSearchOptions;
	pdf.Pages.Accept(textFragmentAbsorber);
	Aspose.Pdf.Text.TextFragmentCollection textFragmentCollection = textFragmentAbsorber.TextFragments;

	// Finds just 1 fragments
	foreach (Aspose.Pdf.Text.TextFragment textFragment in textFragmentCollection)
	{
		AddTable(pdf, textFragment);
	}

	pdf.Save(sResult);
	pdf = null;
}
catch (Exception ex)
{
	MessageBox.Show(ex.ToString());
}

}

I forgot to mention: I am using 18.11.

I do not see how to upload the 2 pdf files…
-Greg

@Greg_Peters

Thank you for sharing the code snippet.

You can upload any file or a zipped archive by using the upload button in header of the post editor. Please see this screenshot for your kind reference HowToUpload.png. You can also upload a file to any free file sharing server like Dropbox, Google Drive etc and then share its download URL here.

Thanks. Here are those 2 files.pdfResult.pdf (173.5 KB)
pdfSource.pdf (115.4 KB)

@Greg_Peters

Thank you for sharing requested data.

We have been able to reproduce the problem in our environment. A ticket with ID PDFNET-45784 has been logged in our issue management system for further investigation and resolution. The ticket ID has been linked with this thread so that you will receive notification as soon as the ticket is resolved.

We are sorry for the inconvenience.

Hello,
I’m using PDF 19.11, any news with this issue ?

Thanks,

Louis

@mschubert

We are afraid PDFNET-45784 is still unresolved. We have recorded your concerns and will let you know once any update is available.