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

Free Support Forum - aspose.com

FormFieldFacade.PageNumber returns 0 in certain circumstances

test.pdf (738.5 KB)
Hello!
I found weird behavior of FormFieldFacade.PageNumber property. Code below works fine and PageNumber equals 1:

using (var pdf = new Document(@“test.pdf”))
{
var pageCollection = pdf.Pages;
var page = pageCollection[1];
pdf.Save(“test_copy.pdf”);
var form = new Aspose.Pdf.Facades.Form(pdf);
foreach (var formField in pdf.Form.Fields)
{
var fieldFullName = formField.FullName;
var fieldfacade = form.GetFieldFacade(fieldFullName);
var pdfPage = pageCollection[fieldfacade.PageNumber];
}
}

But if I comment var page = pageCollection[1]; the code fails because PageNumber equals 0:

using (var pdf = new Document(@“test.pdf”))
{
var pageCollection = pdf.Pages;
//var page = pageCollection[1];
pdf.Save(“test_copy.pdf”);
var form = new Aspose.Pdf.Facades.Form(pdf);
foreach (var formField in pdf.Form.Fields)
{
var fieldFullName = formField.FullName;
var fieldfacade = form.GetFieldFacade(fieldFullName);
var pdfPage = pageCollection[fieldfacade.PageNumber];
}
}

Additionally, if I also comment pdf.Save(“test_copy.pdf”); the code works as expected:

using (var pdf = new Document(@“test.pdf”))
{
var pageCollection = pdf.Pages;
//var page = pageCollection[1];
//pdf.Save(“test_copy.pdf”);
var form = new Aspose.Pdf.Facades.Form(pdf);
foreach (var formField in pdf.Form.Fields)
{
var fieldFullName = formField.FullName;
var fieldfacade = form.GetFieldFacade(fieldFullName);
var pdfPage = pageCollection[fieldfacade.PageNumber];
}
}

Aspose.Pdf version 19.3

@Simon_Karpen

Thanks for your inquiry.

The reason of this behavior of the API is that Document.Save() method acts more likely disposing the object. Once it is called, it clears initialized resources in the memory e.g. Page, Fonts, etc. As you are saving document before using page collections, the Page does not remain valid thus returning page number as 0. We hope this information will help.

We will further share more information with you about this scenario after investigation.

Does that mean that after Save method call the underlying Document object should not be used anymore?

@Simon_Karpen

We are looking into details and will let you know when Document object is exactly disposed. Please spare us little time.