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

Fix issue #4290 (--copies not working with --collate). #4301

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
13 changes: 10 additions & 3 deletions src/lib/pdfconverter.cc
Expand Up @@ -963,9 +963,6 @@ void PdfConverterPrivate::endPrintObject(PageObject & obj) {
pageFormElements.clear();

if (obj.web_printer != 0) {
delete obj.web_printer;
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure about this, what happens in the call from line 887? I don't want to cause one more breakage due to a code path not being considered.

Copy link
Author

Choose a reason for hiding this comment

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

As far as I understand the code (I have looked at it for just a few hours so I might be wrong) the loop at printDocument() deletes the web_printer after each object is used. The call from 887 (at beginPrintObject) deletes the web_printer of previous object when the loop advances, and finally the call from line 1012 clears the web_printer of the last object.

The problem is that when the "copies" loop (at 995) advances to print the next page, web_printers were already deleted so the next copy has nothing to print, and thus --copies always produces a single copy.

My solutions was to defer the web_printer deletion until all pages were processed, but of course it might be not the best solution (I might even be completely wrong!).

Be free to reject the PR if you have doubts about its correctness, as I said I have only looked at the code for a few hours. In any case, we have this solution working on a system that produces more than 50.000 PDFs per day (could not wait for official release because of the importance of the --copies feature to us), and it is working ok so far.

Copy link
Member

Choose a reason for hiding this comment

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

That's good to know. I'll review it in more detail this weekend and merge it 👍

Copy link
Member

Choose a reason for hiding this comment

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

Sorry about the delay, I've been a bit busy but I'll look at it this week.

obj.web_printer = 0;

painter->restore();
}

Expand Down Expand Up @@ -1011,6 +1008,16 @@ void PdfConverterPrivate::printDocument() {
}
endPrintObject(objects[objects.size()-1]);
}

// delete web_printer after processing all copies
for (int d=0; d < objects.size(); ++d) {
PageObject & obj = objects[d];
if (obj.web_printer != 0) {
delete obj.web_printer;
obj.web_printer = 0;
}
}

outline->printOutline(printer);

if (!settings.dumpOutline.isEmpty()) {
Expand Down