Having trouble applying CSS while printing using the ngx-print library in Angular 14. Can anyone help me out with this issue

The table shown in the image is experiencing issues with applying CSS properties when printing. While the background graphics feature has been enabled, the preview section still does not reflect the CSS styling. What could be causing this discrepancy?

Click here to view the image

Below is my HTML code:

<div class="container-fuild ml-3 mr-3">
    <mat-card>
      <mat-card-content *ngIf="reportingDataModel?.searchList.length>0 && reportingDataModel?.calculationList.length>0 ">
         <div class="row">
        <div class="col-md-12">
          <div class="table-responsive">
            <div class="tableFixHead">
              <div class="table text-center">
                <table class="table table-bordered border border-secondary" id="save-stage48">
                  <thead id="tableHeadRow" role="row"> 
                    <tr>
                      <th>#</th>
                      <th>{{ 'MeasurementPoints' | translate }}</th>
                        <th   *ngFor="let searchList of reportingDataModel?.searchList; let i = index">
                          <div>{{ searchList.worOrderName }}</div>
                          <div>{{ searchList.measurementTypeName }}</div>
                          <div>{{ searchList.widthAndShrink }}</div>
                          <div *ngIf="searchList.reportType === 1">{{ searchList.sizeId }} {{ "Size" | translate }}</div>
                        </th>
                      <th>{{ 'averagetolerance' | translate }}</th>
                      <th   >
                        {{averageWidth}}
                        <br>
                        {{'decidetolerance' | translate}}
                      </th>
                      <th>{{ 'Description' | translate }}</th>
                    </tr>
                  </thead>
                  <tbody >
                    <ng-container *ngFor="let calculation of reportingDataModel?.calculationList[0]; let i = index">
                      <tr >
                        <td style=""> {{i+1}} {{incomingName}} </td>
                        <td style="" [id]="calculation?.id">{{calculation?.measurementPointName}}</td>
                        <ng-container *ngFor="let calculations of reportingDataModel?.calculationList; let j = index">
                          <td>{{reportingDataModel?.calculationList[j][i].appliedPullTolerance}}</td>
                        </ng-container>
                        <td >{{calculaterAverageTolerance(i)}}</td>
                        <td></td>
                        <td rowspan="3"> <textarea name="" id="" cols="15" rows="3"></textarea></td>
                      </tr>
  
                      <ng-container *ngIf="i <= reportingDataModel?.calculationList[0].length">
                          <tr >
                            <td style="white-space:nowrap">{{i+1}} {{incomingNameTwo}}</td>
                            <td style="text-align:start">{{calculation?.measurementPointName}}</td>
                            <ng-container *ngFor="let calculations of reportingDataModel?.calculationList; let j = index">
                              <td>{{reportingDataModel?.calculationList[j][i].actualPullTolerance}}</td>
                            </ng-container>
                            <td>{{calculaterActualPullTolerance(i)}}</td>
                            <td><input type='number' style="width:50%"  step="0.1" [value]="total"/></td>
                          </tr>
  
                          <tr>
                            <td style="white-space:nowrap">{{i+1}} {{"Avg."}}</td>
                            <td style="text-align:start">{{calculation?.measurementPointName}}</td>
                            <ng-container *ngFor="let calculations of reportingDataModel?.calculationList; let j = index">
                              <td>{{reportingDataModel?.calculationList[j][i].averageValue}}</td>
                            </ng-container>
                            <td >{{calculaterAverageValue(i)}}</td>
                            <td></td>
                          </tr>
                      </ng-container>
                    </ng-container>
                  </tbody>
                </table>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>

My CSS code:

.table.text-center th,
.table.text-center td {
text-align: center;
}

#save-stage48 tbody tr td {
padding: 0 0.313rem;
height: 1.563rem;
vertical-align: middle;
text-align: center;
}

#save-stage48, #save-stage48 td, #save-stage48 tr {
border: 0.031rem solid black;
}

#save-stage48 th {
border: 0.063rem dashed black;
}

#save-stage48 th {
white-space: nowrap;
text-align: center;
}

#save-stage48 td {
padding: 0.5rem 0;
}

#save-stage48 {
border-collapse: collapse;
}

.tableFixHead {
overflow-y: auto;
overflow-x: auto;
height: 80%;
width: 100%;
}

.tableFixHead th {
background-color: rgba(245, 245, 245, 1) !important;
color: #666 !important;
}

.tableFixHead thead tr th {
position: sticky;
top: 0;
}

#save-stage48 tbody tr:nth-child(3n+1) {
background-color: rgba(112, 128, 144, 1) !important;
color: white !important;
}

#save-stage48 tbody tr:nth-child(3n+2) {
background-color: rgba(148, 164, 179, 1) !important;
color: white !important;
}

#save-stage48 tbody tr:nth-child(3n+3) {
background-color: rgba(171, 186, 199, 1) !important;
color: white !important;
}

.dataTables_wrapper {
padding: 0 !important;
font-size: 0.688rem !important;
font-weight: bold;
}

#save-stage48 tbody tr:nth-of-type(3n) td {
border-bottom: 0.375rem solid white;
}

#save-stage48 tbody tr td:first-child {
border-left: 0.375rem solid white;
}

#save-stage48 tbody tr:nth-of-type(3n+1) td:last-child, tr:first-child td:last-child {
border-right: 0.375rem solid white;
border-bottom: 0.375rem solid white;
}

Answer №1

<button
  [implementExistingStyles]="true"
    sectionId="print-section"
    ngxPrint>click to print</button>    

Give it a shot using

[useExistingCss]="true"
source: https://www.npmjs.com/package/ngx-print

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Retrieve the value from an input field when the value is returned from JavaScript

Scenario: I'm currently working on creating a QR reader to retrieve a specific value. You can check out the progress here: What's functioning: scanning. When I scan a QR code, a value is displayed in the text box. Here's the code snippet b ...

What causes two identical pages to display fonts in different ways?

Two identical pages, hosted on the same server with the exact same Apache configuration and home directory. Each page contains only one sentence of text, unstyled. The strange thing is, when viewed in Chrome and Safari, the fonts render differently, while ...

JavaScript for controlling first-person movement with a mouse

Currently, I am working on implementing a first person movement feature using the mouse. While I have successfully implemented it using the keyboard, I am facing challenges with the mouse input. The issue arises from the ambiguity in movement directions ca ...

Is it possible to align divs so that they touch when they wrap to a new line, creating a grid-like appearance?

My React board component consists of an array of divs that I want to arrange in a grid-like map. The issue is, when the div wraps to a new line, there is significant space between each row. I aim to have the divs close together with no gaps. GameMap state ...

refers to the spacing between elements

I currently have 4 nested divs. My goal is to ensure that the margins between each div are equal, maintaining the same distance from the left edge of the parent div to the first nested div, between each pair of nested div, and from the last nested div to t ...

Looking for tips on resolving issues with the bootstrap navigation bar?

Check out this code snippet: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport ...

Struggling to link an external JavaScript file to your HTML document?

While attempting to run a firebase app locally, I encountered an error in the chrome console: GET http://localhost:5000/behaviors/signup.js net::ERR_ABORTED 404 (Not Found) Do I need to set firebase.json source and destination under rewrites or add a rout ...

Displaying every nth image in a new row of a CSS grid

I have a react component and I want to arrange 3 photos inline in a row with their names below each photo, and then continue in new rows for the next set of 3 elements and so on... I attempted to use :nth-child(3n+1) but encountered some issues... const P ...

Angular drag and drop feature for interacting with intersecting elements like rows and columns within a table

I am currently working on implementing two intersecting drag and drop functionalities using cdkDragDrop. Although I generally try to avoid using tables, I have created one in this case for the sake of easier explanation. Here is the link to StackBlitz: ht ...

Using whitespace to format a document.write in JavaScript

I'm in the process of creating a dynamic table using JavaScript and a set of objects. I've managed to structure it, but now I require some extra white space between them, almost like tabbing them out. How can I achieve this efficiently with my cu ...

Can someone help me troubleshoot this issue with my code so that my website can open in a blank page using about:blank?

I'm currently facing an issue while trying to make one of the pages on my website open with an about:blank URL upon loading. Despite embedding the code in my index.html file, it doesn't seem to be functioning properly. Here's the code I&apos ...

"Receiving HTML response from an HTTP GET request in Angular 2

Attempting to transmit test data from my node.js server to the front end. router.get('/abc', (req, res) => { return res.json({ test: "success!" }); }); In my service component: private url = "http://localhost:4200/auth/abc"; getTitl ...

Upon clicking, the input texts revert to their original default values

I have a form below that is working as intended, except for one issue. When I click the 'Add' link, the texts in all the textboxes revert to their default values, as shown in the images. How can I resolve this problem? Thank you. before click: ...

Execute a zoom out action by pressing the (Ctrl) and (-) keys simultaneously in Javascript

I'm trying to figure out how to simulate a Ctrl - zoom out using Javascript. I've noticed that using the style zoom property or the transform property gives different results with white space in the corners, rather than the smooth zoom out effect ...

Tips for preserving dynamically generated HTML through Javascript during page reload

I have a straightforward question, but I haven't been able to find a suitable answer. Here's my situation: On my HTML page, I have a form. Using jQuery and AJAX, I submit the form and then use some JavaScript code to change the content of a spec ...

Utilizing unique symbols to dynamically add form elements to an HTML page with jQuery's append method

I am facing an issue with creating forms on my HTML page. Here is an example of how I am trying to do it: <form action="/tasks/<%= allTasks.e[0].id %>/delete" method="POST"> <button class="deleteTask">Delete</button> </f ...

Error: global not declared in the context of web3

I've been attempting to integrate Web3 into my Ionic v4 project for some time now. However, I keep encountering errors when I try to serve the project. Specifically, I receive an error message stating that Reference Error: global is not defined. Cre ...

What does Angular 5 offer in terms of functionality that is equivalent to?

I am working on my AngularJS 1.5 application where I have controllers directly calling service functions. What is the recommended approach to achieve this in Angular? $scope.permissions = ClockingMenuService.permissions; $scope.data = ClockingMenuService ...

ng-required is ineffective when used with number inputs that have a minimum value requirement

In my form, I have implemented a checkbox that, when checked, toggles the visibility of a div using AngularJS's ng-show. Within this div, there is an input field of type "number" with a validation setting of min="10000". I am trying to prevent the f ...

Transitioning from angular version 5.2 to the latest angular 6.1 version

Currently, I find myself on node 8.11 and utilizing VS code. The project was originally built in version 5.2.5 but has been inactive for some time now. Within my project, the following modules are present: import { BrowserModule } from '@angular/plat ...