SetPageSize() ignored if any Text added to the page

Background

We are currently evaluating Aspose.Pdf for .Net as a replacement for iTextSharp. I am using the new Aspose.Pdf API (i.e., not the Generator)

Problem
When I call SetPageSize() to change the dimensions of a page, it works, but as soon as I add any TextFragment, it is as if the SetPageSize() is ignored.

To illustrate, in the code below, I am creating a two-page document. For both pages, I am changing the page size via SetPageSize(). However, in the output, only the blank page (page 2) is produced with the desired dimensions:

var doc = new Document();
//add a new page with text and change its page size
var page1 = doc.Pages.Add();
page1.SetPageSize(600, 400);
var para = new TextFragment(“both pages should be 600w x 400h”);
page1.Paragraphs.Add(para);
//add a new page without text and change its page size
var page2 = doc.Pages.Add();
page2.SetPageSize(600, 400);
//save and done
doc.Save(“d:\output.pdf”);

When I inspect the output, only page 2 reflects the dimensions. What am I doing wrong?

Thanks,
R. Ernst

Hi RIchard,

We are sorry for the inconvenience caused. While testing the scenario with the latest version of Aspose.Pdf for .NET 9.4.0, we have managed to reproduce the reported issue and logged it in our bug tracking system as PDFNEWNET-37215 for further investigation and resolution. We will notify you via this thread as soon as it is resolved.

Please feel free to contact us for any further assistance.

Best Regards,

The issues you have found earlier (filed as PDFNEWNET-37215) have been fixed in Aspose.Pdf for .NET 9.5.0.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

OK, I installed version 9.5.0, and I’m not seeing any difference. It is still ignoring the SetPageSize() setting. (I double-checked my bin\debug folder after compilation to ensure the right versioned .dll is there.)


For now, I have a workaround, because it appears that setting the Page.PageInfo.Height & .Width DO work as expected. But I thought you should know that SetPageSize() still isn’t working correctly.

Some additional feedback: SetPageSize() is apparently ignored if there are any paragraphs on ANY page in the document, not just on the one whose size is being changed. Here is some code that reproduces the issue, with comments regarding the results for of each page.

//ISSUE: SetPageSize() doesn’t work if paragraphs are added to ANY page
//in the document
//Note: using Page.PageInfo.Height/Width works OK)
var doc = new Document();
Page page;

//SUCCESS: Setting Width/Height dimensions works,
page = doc.Pages.Add();
page.Paragraphs.Add(new TextFragment(“page 1”));
page.PageInfo.Height = 200;
page.PageInfo.Width = 600;

//FAIL: SetPageSize() is ignored because there are paragraphs
page = doc.Pages.Add();
page.Paragraphs.Add(new TextFragment(“page 2”));
page.SetPageSize(600, 200); //this is ignored

//FAIL: SetPageSize() is ignored because there are paragraphs
page = doc.Pages.Add();
var box = new FloatingBox(200, 100);
box.Paragraphs.Add(new TextFragment(“page 3”));
page.Paragraphs.Add(box);
page.SetPageSize(600, 200);

//FAIL: SetPageSize() is ignored, even with no paragraphs on the page,
// apparently because there are paragraphs on OTHER pages
// comment out the creation of pages 1 - 3
page = doc.Pages.Add();
page.SetPageSize(600, 200);

//save and done
doc.Save(“c:\test2.pdf”);
Process.Start(“c:\test2.pdf”);

Sincerely,
R. Ernst

Hi Richard,


Thanks for your feedback. In reference to above fix, please note SetPageSize() method is used to set dimensions of page in existing PDF document and to PageInfo is used to set dimension at the time of document generation. As you already noticed it will help you to accomplish the task, so please use PageInfo method as following for the purpose.

var doc = new Document();<o:p></o:p>

//add a new page with text and change its page size-ignored

var page1 = doc.Pages.Add();

//page1.SetPageSize(600, 400);

page1.PageInfo.Width = 600;

page1.PageInfo.Height = 400;

var para = new TextFragment("both pages should be 600w x 400h");

page1.Paragraphs.Add(para);

//add a new page without text and change its page size-works

var page2 = doc.Pages.Add();

//page2.SetPageSize(600, 400);

page2.PageInfo.Width = 600;

page2.PageInfo.Height = 400;

//save and done

doc.Save(myDir + "Pagesize_output2.pdf");


Please feel free to contact us for any further assistance.


Best Regards,