I've an angular application
with invoicing functionality in it. I've used a bootstrap modal to design an invoice which you can see below in the image "before print"
. In this image, I've added 2 items in the invoice but when I go ahead and print the invoice modal using window.print()
I see that the print page is not taking the entire value of the input element.
Eg. For the 1st item in an invoice page you can see the value entered as "Some Item - Black Color E Series 56565" but on the print page window.print()
has taken only partial value as "Some Item - Black Color E Se" and rest is hidden.
The same thing can be noticed for a Narration input field at the bottom left corner of the page. How can we overcome this issue?
Note: I've used HTML input element for item as well as narration fields on an invoice page.
To help you more, I can provide you with a bit of the required codebase to understand this. Have a look at the code, and both the images below.
1. Angular Component Codebase
// this print method is called on click of Save & Print button
print() {
// first save the invoice and if save is successfull then give a print command
this.invoiceService.create(this.invoice)
.subscribe(
result => {
console.log(result);
if(result) window.print(); // print the invoice only if it is successfully saved
},
(error: AppError) => {
this.error = true;
this.errorMsg = 'Error occurred.';
return ;
});
}
2. Style.css Codebase
@media print {
html, body {
height:100vh;
margin: 0 !important;
padding: 0 !important;
overflow: hidden;
}
body * {
visibility:hidden;
}
#printThis, #printThis * {
visibility:visible;
}
.remove-item, .add-item, .modal-footer {
display: none;
}
.hide-discount, .hide-freight {
display: none;
}
.modal {
position: absolute;
left: 0;
top: 0;
margin: 0;
padding: 0;
overflow: visible!important;
}
}
3. HTML Markup:
<div class="row">
<div class="items-table">
<ng-container *ngFor="let item of items; let i=index;">
<div class="row invoice-items" >
<div class="col-4 input-container">
<input [(ngModel)]="item.description" name="itemDescription" id="item" type="text" placeholder="Item name" >
</div>
</div>
</ng-container>
</div>
</div>
4. CSS Styling for invoice page input elements:
.items-table input {
line-height:1.5em;
}
input:focus {
outline: 0;
}
.col-4.input-container input {
width: 100%;
}
input:hover, textarea:hover, input:focus, textarea:focus {
border: 1px solid #CCC;
}
This is a bare minimum styling I've used for input elements.
5. Image Before Print(Invoice Modal page)
6. Image After clicking on Save&Print button(Actual printing page)