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

Remove margins for cover page to fix #3635 #5193

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/lib/pdfconverter.cc
Expand Up @@ -1002,10 +1002,31 @@ void PdfConverterPrivate::printDocument() {
progressString = "Preparing";
emit out.progressChanged(0);

qreal leftMargin, topMargin, rightMargin, bottomMargin;
printer->getPageMargins(&leftMargin, &topMargin, &rightMargin, &bottomMargin, settings.margin.left.second);

for (int cc_=0; cc_ < cc; ++cc_) {
pageNumber=1;
for (int d=0; d < objects.size(); ++d) {
if (objects[d].settings.isCover) {
painter->save();
painter->translate(-leftMargin * printer->width() / printer->widthMM(), -topMargin * printer->height() / printer->heightMM());
printer->setPageMargins(0, 0, 0, 0, settings.margin.left.second);
if (objects[d].web_printer != 0) {
/*
* delete objects[d].web_printer here, then in beginPrintObject(objects[d]) will re-create
* a new web_printer to use printer as we changed page margins for cover page.
* otherwise, the change setPageMargins to 0 will not works.
*/
delete objects[d].web_printer;
objects[d].web_printer = 0;
}
}
beginPrintObject(objects[d]);
if (objects[d].settings.isCover) {
printer->setPageMargins(leftMargin, topMargin, rightMargin, bottomMargin, settings.margin.left.second);
painter->restore();
}
// XXX: In some cases nothing gets loaded at all,
// so we would get no webPrinter instance.
int pageCount = objects[d].web_printer != 0 ? objects[d].web_printer->pageCount() : 0;
Expand Down
2 changes: 2 additions & 0 deletions src/lib/pdfsettings.cc
Expand Up @@ -162,6 +162,7 @@ struct DLL_LOCAL ReflectImpl<PdfObject>: public ReflectClass {
WKHTMLTOPDF_REFLECT(includeInOutline);
WKHTMLTOPDF_REFLECT(pagesCount);
WKHTMLTOPDF_REFLECT(isTableOfContent);
WKHTMLTOPDF_REFLECT(isCover);
WKHTMLTOPDF_REFLECT(tocXsl);
}
};
Expand Down Expand Up @@ -405,6 +406,7 @@ PdfObject::PdfObject():
includeInOutline(true),
pagesCount(true),
isTableOfContent(false),
isCover(false),
tocXsl("") {};

QString PdfGlobal::get(const char * name) {
Expand Down
2 changes: 2 additions & 0 deletions src/lib/pdfsettings.hh
Expand Up @@ -202,6 +202,8 @@ struct DLL_PUBLIC PdfObject {

bool isTableOfContent;

bool isCover;

QString tocXsl;

QString get(const char * name);
Expand Down
1 change: 1 addition & 0 deletions src/pdf/pdfcommandlineparser.cc
Expand Up @@ -178,6 +178,7 @@ void PdfCommandLineParser::parseArguments(int argc, const char ** argv, bool fro
ps.header.line = ps.footer.line = false;
ps.header.htmlUrl = ps.footer.htmlUrl = "";
ps.includeInOutline = false;
ps.isCover = true;

continue;
} else if (!strcmp(argv[arg],"toc")) {
Expand Down