PDF Output: Fix regression in previous release that caused blank pages when generating headers or footers

Needed to prepend the header/footer content stream to the page content
stream. Appending only worked with Qt >= 6.5 which is what is present on
my dev machine, so didnt catch it. Before 6.5, when drawing header
footers chromium does not occlude the body area even though nothing is
drawn there, thus prepending is required.
This commit is contained in:
Kovid Goyal 2023-05-28 09:07:57 +05:30
parent ba2ccd0e72
commit 59503c21dc
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -6,6 +6,7 @@
*/
#include "global.h"
#include <sstream>
#include <string>
using namespace pdf;
@ -16,10 +17,14 @@ impose_page(PdfMemDocument *doc, unsigned int dest_page_num, unsigned int src_pa
auto xobj = doc->CreateXObjectForm(src_page.GetMediaBox(), "HeaderFooter");
xobj->FillFromPage(src_page);
auto &dest = doc->GetPages().GetPageAt(dest_page_num);
PdfPainter painter;
painter.SetCanvas(dest);
painter.DrawXObject(*xobj, 0, 0);
painter.FinishDrawing();
dest.GetOrCreateResources().AddResource("XObject", xobj->GetIdentifier(), xobj->GetObject().GetIndirectReference());
// prepend the header footer xobject to the stream. This means header/footer is drawn first then the contents, which works
// since chromium does not draw in margin areas. The reverse, i.e. appending, does not work with older WebEngine before Qt 6.5.
PdfContents *contents = dest.GetContents();
std::ostringstream s;
s << "q\n1 0 0 1 0 0 cm\n/" << xobj->GetIdentifier().GetString() << " Do\nQ\n" << contents->GetCopy();
contents->Reset();
contents->GetStreamForAppending().SetData(s.str());
}
static PyObject*