We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Extend PDF Page Size From Bottom using C++

Hello, I have a PDF page that contains some tables. I am filling this table with the information from our PDM system. Most of our pages contain tables that have 10 rows but sometimes I need to add some extra rows. When I add the rows, I must also extend my page downwards. But I couldn’t achieve it. When I try to change my page size with “document->get_Pages()->idx_get(1)->SetPageSize(842.4, 1000)”, it extends upwards. I am using c++, could you help me to solve it.
image.png (106.9 KB)

@cengiz.bahar

Would you please share your sample PDF document for our reference along with complete sample code snippet to reproduce the issue? We will test the scenario in our environment and address it accordingly.

Problem1.pdf (3.8 KB)
Problem1_out.pdf (88.2 KB)

You can find the code below. If you uncomment the SetPageSize row you can see the error.
In addition that I cannot add the last column of the table.

// ConsoleApplication1.cpp : This file contains the 'main' function. Program execution begins and ends there.

//
#include “Header.h”

using namespace System;
using namespace System::Drawing;
using namespace std;
using namespace Aspose::Pdf;
using namespace Aspose::Pdf::Text;

int main()
{
String _dataDir(“C:\Temp\pdf\”);
String inputFileName(“Problem1.pdf”);
String outputFileName(“Problem1_out.pdf”);

//Load source PDF document
auto document = MakeObject<Document>(_dataDir + inputFileName);

// Initializes a new instance of the Table
auto table = MakeObject<Table>();

// Set the table border color as LightGray
table->set_Border(MakeObject<Aspose::Pdf::BorderInfo>(Aspose::Pdf::BorderSide::All, .25f, Aspose::Pdf::Color::get_Black()));
// Set the border for table cells
table->set_DefaultCellBorder(MakeObject<Aspose::Pdf::BorderInfo>(Aspose::Pdf::BorderSide::All, .25f, Aspose::Pdf::Color::get_Black()));

string ColumnWidths[] = {
	"33.5",
	"33.5",
	"33.5",
	"50.0",
	"85.0",
	"198.0",
	"33.5",
	"62",
	"62",
	"100"};

string str_ColumnWidths;
for (int ColumnWidths_count = 0; ColumnWidths_count < sizeof(ColumnWidths) / sizeof(ColumnWidths[0]); ColumnWidths_count++)
{
	str_ColumnWidths = str_ColumnWidths + ColumnWidths[ColumnWidths_count] + " ";
}
String str_ColumnWidths_(str_ColumnWidths);

table->set_ColumnWidths(str_ColumnWidths_);

// Create MarginInfo object and set its left, bottom, right and top margins
auto margin = MakeObject<MarginInfo>();
margin->set_Top(179.0f);
margin->set_Left(-38.0f);
//margin->set_Right(5.0f);
//margin->set_Bottom(5.0f);
table->set_Margin(margin);

// Create a loop to add 10 rows
for (int row_count = 0; row_count < 20; row_count++)
{
	// Add row to table
	auto row = table->get_Rows()->Add();
	row->set_FixedRowHeight(28);

	// Add table cells
	for (int column_count = 0; column_count < sizeof(ColumnWidths) / sizeof(ColumnWidths[0]); column_count++)
	{
		row->get_Cells()->Add();
	}
}

// Add table object to first page of input document
document->get_Pages()->idx_get(1)->get_Paragraphs()->Add(table);

//document->get_Pages()->idx_get(1)->SetPageSize(842.4, 1000);

// Save updated document containing table object
document->Save(_dataDir + outputFileName);

}

@cengiz.bahar

We have logged an investigation ticket as PDFCPP-1808 in our issue tracking to further analyze this case. We will look into its details and keep you posted with the status of ticket resolution. Please be patient and spare us some time.

We are sorry for the inconvenience.