Reputation: 31
My team has been searching for a fix for this problem. We have an application that dynamically creates a diagram (graphics) with flows. It also displays the shapes in a "swinlane" which is basically the object surrounded by a div with a border and a background color. Everything thing look great. The problem we are having is when try to print this view.
We are just using the existing html (variable name printContent). We open a separate window and call the print:
var pw = window.open('', 'View', 'width=900,height=600');
pw.document.open();
pw.document.write('<html><head></head><body>' + printContent + '</body></html>');
pw.document.close();
pw.focus();
pw.print();
pw.close();
The content actually looks correct in the new window. It is when it is printed by the printer that the top "swinlane" does not show the border or background. The rest are normal.
We have tried to check the 'Print Background Colors and Images' in File->Page Setup, but has no effect.
Upvotes: 1
Views: 104
Reputation: 31
I have circled back to this problem. I not sure this is the exact answer to this problem, but it solved my problem.
I was tasked with making the online version of our viewer to work offline. This is where I stumbled onto a possible solution. I (think) part of the problem turns out to be a timing issue between the new window being rendered and the print function opening automatically. When the print function opens, it seems to grab what is rendered to new window.
I decided I had to options:
I added the following code to use setTimeout:
var fnTimeout = function () {
setTimeout(function () {
if (window.document.readyState == "complete") {
window.focus();
window.print();
}
else {
fnTimeout();
}
}, 500);
};
fnTimeout();
Upvotes: 1