Skip to content
This repository has been archived by the owner on Jan 2, 2023. It is now read-only.

Commit

Permalink
set page margins correctly via header/footer heights for multiple URLs
Browse files Browse the repository at this point in the history
In 80cbcc5, the ability for
auto-calculation of the header/footer height was implemented.
However, in case of multiple page objects (i.e. URLs) being present
for conversion, the calculated height for only the FIRST page object
was used -- the heights for the second and further page objects were
being ignored. In case a cover page was specified first (which has
no header/footer by design) without an explicit margin, then the
top/bottom margins would be set to zero -- which would hide the
header/footer content.

The solution is to use the maximum value across all the page objects,
so that there is enough space for the header content across all page
objects. Fixes #1676
  • Loading branch information
ashkulz committed Jul 4, 2014
1 parent affb35c commit 6a13a51
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
v0.12.2 (unreleased)
--------------------
* **#1676**: do not allow overriding the header/footer settings for cover pages
* **#1676**: set page margins correctly via computed header/footer heights for multiple URLs
* **#1758**: fix corrupt image when output is specified as "-" in wkhtmltoimage on Windows
* **#1772**: added variable 'isodate' for substitution in headers/footers
* **#1808**: fix [sitepage] and [sitepages] not working without HTML headers/footers
Expand Down
19 changes: 14 additions & 5 deletions src/lib/pdfconverter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,11 @@ void PdfConverterPrivate::beginConvert() {
settings.margin.bottom.first = 10;
}

// set static header/footer reserve heights
objects[0].headerReserveHeight = settings.margin.top.first;
objects[0].footerReserveHeight = settings.margin.bottom.first;
for (QList<PageObject>::iterator i=objects.begin(); i != objects.end(); ++i) {
PageObject & o=*i;
o.headerReserveHeight = settings.margin.top.first;
o.footerReserveHeight = settings.margin.bottom.first;
}

pageLoader.load();
}
Expand Down Expand Up @@ -359,8 +361,15 @@ void PdfConverterPrivate::pagesLoaded(bool ok) {

//Setup margins and papersize
#ifdef __EXTENSIVE_WKHTMLTOPDF_QT_HACK__
printer->setPageMargins(settings.margin.left.first, objects[0].headerReserveHeight,
settings.margin.right.first, objects[0].footerReserveHeight,
double maxHeaderHeight = objects[0].headerReserveHeight;
double maxFooterHeight = objects[0].footerReserveHeight;
for (QList<PageObject>::iterator i=objects.begin(); i != objects.end(); ++i) {
PageObject & o=*i;
maxHeaderHeight = std::max(maxHeaderHeight, o.headerReserveHeight);
maxFooterHeight = std::max(maxFooterHeight, o.footerReserveHeight);
}
printer->setPageMargins(settings.margin.left.first, maxHeaderHeight,
settings.margin.right.first, maxFooterHeight,
settings.margin.left.second);
#else
printer->setPageMargins(settings.margin.left.first, settings.margin.top.first,
Expand Down

2 comments on commit 6a13a51

@alexagrf
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this patch enforce a header and footer-sized margins on the cover page?

@ashkulz
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexagrf: Yep, I think it does. But I don't think that can be avoided as the margins are defined at the printer level.

Please sign in to comment.