xaviou wrote:I would just have a confirmation before filling a bug report : it seems there is a problem when using the "WriteXml" method in the "Footer" method of a wxPdfDocument derived class.
The problem is related to the autopagebreak feature of wxPdfDocument. As soon as content is printed at a position below the bottom margin of a page a page break is performed. If this happens within the Footer method you get an endless loop causing a stack overflow.
Method WriteXML and especially the table tag handling code doesn't check whether the method was called within the footer. You might call this a bug, but on the other hand it's your responsibility that the footer content fits on the page.
If you want to use the bottom margin space for your footer you must temporarily disable autopagebreak within your own footer method:
Code: Select all
double breakMargin = GetBreakMargin();
// ... (your footer content)
This still doesn't solve the problem if the margin space is not big enough to hold the complete footer content.
So the code of wxPdfDocument should certainly be fixed in such a way that the application doesn't crash. I'll try to address this issue for the next release of wxPdfDocument.
But even with such a fix you would get garbled results if your footer content doesn't fit on the page.
xaviou wrote:And this crash does not append if there is less than one page of text to be printed (replacing the number of lines printed from 40 to 23 works; if more than 23, it crash).
Am I doing something wrong ?
At least it's partially your own responsibility. In the shown code of your footer method the y position is not set. So the footer is printed at that position where the last normal line was printed. If you print more lines as fit on the page (i.e. more than 23) the autopagebreak feature comes into action. Your footer method then causes page breaks itself and you get a crash due to a stack overflow.
If you take a look at the footer method in tutorial 2 you see that the y position is manipulated by a negative offset to the bottom margin. And therefore the footer in this sample is guaranteed to fit on the page without causing a page break.
It is good practice to explicitly set the y position within the footer method so that the content which is printed within the footer is known to fit on the page (taking the margins into account, too, of course).