Monday, December 4, 2023
 Popular · Latest · Hot · Upcoming
112
rated 0 times [  114] [ 2]  / answers: 1 / hits: 5113  / 3 Years ago, sat, july 25, 2020, 12:00:00

I have a bootstrap modal which contains table, and table consist of multiple pages, when i print the modal it only prints the part of modal that is unscrolled, means it looks like on printing the page JS take the screenshot of modal window.
Code i tried:


@media print {
.modal-body {
width: auto;
height: auto;
overflow: visible !important;
}

body.modal-open {
visibility: hidden;
}

body.modal-open .modal .modal-header,
body.modal-open .modal .modal-body {
visibility: visible;
}
.modal-footer{
visibility:hidden;
}
.modal-header{
visibility:hidden;
}
}

enter This is the image i obtained after using jquery printThis library


More From » html

 Answers
21

Print Bootstrap Modal Body with jQuery


Make a print function that removes everything. Then append the modal body to the main content after printing your data and append everything back where it belongs. It may not be a perfect solution if you have a more significant site, although this should be enough to figure out how to implement this in your situation.


$(document).on("click", ".print", function () {
const section = $("section");
const modalBody = $(".modal-body").detach();

const content = $(".content").detach();
section.append(modalBody);
window.print();
section.empty();
section.append(content);
$(".modal-body-wrapper").append(modalBody);
});

.modal-body-wrapper {  // Make sure that you have a wrapper.
overflow-y: scroll; // It allows scrolling, but the body is printed
height: 60vh; // in full.
}


See Demo : https://jsfiddle.net/hexzero/5Lzocqpn/


[#3075] Thursday, July 23, 2020, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
saiget

Total Points: 64
Total Questions: 105
Total Answers: 105

Location: Belarus
Member since Tue, Mar 14, 2023
9 Months ago
saiget questions
Thu, Aug 12, 21, 00:00, 2 Years ago
Sat, Jun 26, 21, 00:00, 2 Years ago
Fri, Jun 26, 20, 00:00, 4 Years ago
Thu, May 14, 20, 00:00, 4 Years ago
Wed, Apr 1, 20, 00:00, 4 Years ago
;