If you're looking to save time on coding, consider using the plugin known as printThis.js.
To implement it in your HTML file, include the following script:
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/printThis/1.14.0/printThis.min.js"></script>
Create a print button with an assigned id
:
<button id="print-button-id" type="button" class="btn btn-success">Print</button>
Then, utilize this script to trigger the printing function:
$('#print-button-id').on("click", function () {
$('#print-section-id').printThis({
debug: false,
importCSS: true,
importStyle: true,
printContainer: true,
loadCSS: "your-custom-style-for-printing.css",
pageTitle: "Your print title",
removeInline: false,
printDelay: 333,
header: null,
formValues: true
});
});
Be sure to replace id="print-section-id"
with the actual ID of the element containing the section you wish to print.