New problems adding header in direct-to-file mode using v4.1.1

For some unknown reason I am able to use both versions 4.0.0 and 4.1.1 to work with much more complex documents in direct-to-file mode, but the sample code below [edit: formerly referenced this post, where problem is now avoided] which worked with Aspose.PDF for .NET v4.0.0 now fails with the following errors using v4.1.1:

Using XML + XSL:

System.NullReferenceException was unhandled
Message="Object reference not set to an instance of an object."
Source="Aspose.Pdf"
StackTrace:
at Aspose.Pdf.Xml.ᙴ.ᙵ(Pdf Ә, ߙ ߌ)
at Aspose.Pdf.Xml.ᆻ.ᆼ(؅ Հ, Pdf Ә, ߙ ߌ, Boolean ᆽ)
at Aspose.Pdf.Xml.ᆻ.ᇎ(Pdf Ә, Section ယ, ඁ ද)
at Aspose.Pdf.Xml.ᛓ.ᛖ(Pdf Ә, Section ယ, HeaderFooter ෽, Table क़, Row ཡ, Cell ෹, Paragraph ๾, ඁ ද, ඁ သ, ᆲ ရ, Boolean ဴ)
at Aspose.Pdf.Xml.ᜳ.᜵(Pdf Ә, Section ယ, HeaderFooter ෽, Table क़, Row ཡ, Cell ෹, Text ؒ, ඁ ද, ᆲ ရ, Boolean ဴ)
at Aspose.Pdf.Xml.࿟.࿣(Section ࿢, Paragraph ෶)
at Aspose.Pdf.Section.AddParagraph(Paragraph para)
at Aspose.Pdf.Xml.᭥.᭦(Pdf ၡ, XmlTextReader န)
at Aspose.Pdf.Xml.᭣.᪻(᪵ ප, XmlTextReader န)
at Aspose.Pdf.Xml.᪵.ᪿ(XmlTextReader ᫀ)
at Aspose.Pdf.Xml.᪵.᪾(XmlDocument ၡ, XslTransform ᪽)
at Aspose.Pdf.Xml.᪵.᪻(Pdf ᪼, XmlDocument ၡ, XslTransform ᪽)
at Aspose.Pdf.Pdf.BindXML(Stream xmlStream, Stream xslStream)
at HeaderIsSubsequentPagesOnly.HeaderIsSubsequentPagesOnly.Main(String[] args) line 54
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

Using the API:

System.NullReferenceException was unhandled
Message="Object reference not set to an instance of an object."
Source="Aspose.Pdf"
StackTrace:
at Aspose.Pdf.Xml.ᙴ.ᙵ(Pdf Ә, ߙ ߌ)
at Aspose.Pdf.Xml.ᆻ.ᆼ(؅ Հ, Pdf Ә, ߙ ߌ, Boolean ᆽ)
at Aspose.Pdf.Xml.ᆻ.ᇎ(Pdf Ә, Section ယ, ඁ ද)
at Aspose.Pdf.Xml.ᛓ.ᛖ(Pdf Ә, Section ယ, HeaderFooter ෽, Table क़, Row ཡ, Cell ෹, Paragraph ๾, ඁ ද, ඁ သ, ᆲ ရ, Boolean ဴ)
at Aspose.Pdf.Xml.ᜳ.᜵(Pdf Ә, Section ယ, HeaderFooter ෽, Table क़, Row ཡ, Cell ෹, Text ؒ, ඁ ද, ᆲ ရ, Boolean ဴ)
at Aspose.Pdf.Xml.࿟.࿣(Section ࿢, Paragraph ෶)
at Aspose.Pdf.Section.AddParagraph(Paragraph para)
at HeaderIsSubsequentPagesOnly.HeaderIsSubsequentPagesOnly.Main(String[] args) line 84
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

I am nervous now because I do not know if changes to the more complex documents I typically work with will lead to these same types of problems.

~JS

Hello Jed,

We're looking into the details of this problem and soon you will be updated with the status of correction. We apologize for your inconvenience.

Aspose.PDF for .NET v4.1.1 generates these NullReferenceExceptions when the “Displays page number in the current section” symbol ($Sp) is included in a header or footer.


Sample (from codewarrior here; changes bold):

//Create a file stream to create the PDF document

FileStream fs = new FileStream(@“D:/pdftest/SingleSeg-dtest4.pdf”, FileMode.Create);

//Instantiate the Pdf instance and pass the file stream object to its constructor
Pdf pdf = new Pdf(fs);
//Add a section to the PDF document
Aspose.Pdf.Section sec1 = pdf.Sections.Add();
Aspose.Pdf.HeaderFooter hf1 = new Aspose.Pdf.HeaderFooter(sec1);
sec1.OddHeader = sec1.EvenHeader = hf1;
//Enable this header for first page only
hf1.IsSubsequentPagesOnly = true;
//Instantiate a Text paragraph that will store the content to show as header
Text text = new Text(hf1, “header for page $Sp”);
//Add the text object to the Paragraphs collection of HeaderFooter object to
//display header on the pages of PDF document
hf1.Paragraphs.Add(text);
Random r = new Random();

//Add 300 text paragraphs to the section
for (int i = 0; i < 300; i++)
{
int lines = r.Next(50, 200);
Text t = new Text(hf1, String.Format(“Section #{0} ({1} lines [{2}]) Page $Sp”, i, lines, i));
sec1.AddParagraph(t);
}
//Close the Pdf. This method is used only for direct file mode
pdf.Close();

Hello Jed,

I've tested the scenario and I'm able to notice that NullReferenceExceptions is being displayed when symbol ($Sp) is included in a header or footer when using Aspose.Pdf for .NET 4.1.1, whereas it's working correctly with 4.0.0.

The issue has been communicated to the development team and they are looking into the details of this problem. Soon you will be updated with the status of correction.

We're really sorry for such inconvenience.

Hello Jed,

Thanks for your patience.

I’m pleased to inform you that the issue reported earlier has been fixed in the attached HotFix. Please try using it and in case you still face any problem or you’ve any further query, please feel free to contact.

Thanks for your cooperation.

Thank you for providing a resolution for this issue. I have verified that this problem has been resolved.


I am still blocking on PDFNET-13500.

The issues you have found earlier (filed as 13505) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.