I am unable to see any elements showing color in the print preview

Currently using angular 4 and in need of a feature that allows the user to print a specific section of data. Although I have successfully implemented a bootstrap print preview, the issue arises when no colors are displayed in the preview. This problem persists across different browsers like Chrome and Safari - even after enabling background colors on Safari, the colors fail to show up.

https://i.sstatic.net/hs578.png

The left half of the screenshot displays the expected colors, while the right side shows the colorless print preview version.

A similar occurrence happens when attempting to print directly from the application itself by right-clicking. Other websites display colors perfectly fine in their print previews.

https://i.sstatic.net/fis2A.png

The current "print" function (originally sourced from a stack overflow post) is as follows:

print(): void {
    let printContents, popupWin;
    printContents = document.getElementById('print-section').innerHTML;
    popupWin = window.open('', '_blank', 'top=0,left=0,height=100%,width=auto');
    popupWin.document.open();
    popupWin.document.write(`
      <html>
        <head>
          <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
          <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
          <title>Print tab</title>
          <style>
            .lightBlue {
              background-color: lightblue !important;
            }

            @media print {
              .lightBlue {
                background-color: lightblue !important;
                -webkit-print-color-adjust: exact;
              }
            }
          </style>
        </head>
    <body onload="window.print();window.close()">${printContents}</body>
      </html>`
    );
    popupWin.document.close();
  }

The HTML content being displayed in the print window is as follows:

<div id="print-section" [hidden]="printable">
  <div class="container">
    <h1>Location Report for {{showOnly}}s</h1>
    <br/>
    <table class="table table-bordered">
      <thead class="lightBlue">
        <tr>
          <th >Dog</th>
          <th>Location</th>
        </tr>
      </thead>
      <tbody>
        <tr>

        </tr>
      </tbody>
    </table>
  </div>
</div>

Despite trying multiple solutions found on stack overflow, none seem to solve the issue at hand, leaving me stuck with no clear resolution.

Answer №1

A-ha! The mystery has been unraveled. It turns out that Bootstrap was the culprit behind the disappearing colors. Additionally, it was interfering with my global CSS file as well. Switching from Bootstrap 3 to Bootstrap 4 resolved the latter issue, but unfortunately, the printing problem persists. Looks like I'll have to refrain from using Bootstrap for any files that require printing.

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

Error: Jest + Typescript does not recognize the "describe" function

When setting up Jest with ts-jest, I encountered the error "ReferenceError: describe is not defined" during runtime. Check out this minimal example for more information: https://github.com/PFight/jest-ts-describe-not-defined-problem I'm not sure what ...

Display the elements of a div at a reduced size of 25% from its original dimensions

I'm currently developing a JavaScript-based iOS simulator that allows users to view their created content on an iPhone and iPad. This involves using AJAX to load the content/page into the simulator, but one issue is that the simulator isn't life- ...

What steps can be taken to ensure that ng-test unit testing does not utilize fdescribe() and fit()?

Picture this: an angular project being unit tested and continuously deployed. A developer completes a unit test for a component, using fdescribe() or fit() to run specific tests during the development process. However, in a moment of distraction, the deve ...

Struggling to create a complete Absolute URL

www.baxter.com source page reveals that many of the href links start with the word baxter, for example: href="/baxter/corporate.page?">About Baxter< Attempting to construct an absolute URL by combining the base url, www.baxter.com, with the relativ ...

Storing JSON data in an object constructor in TypeScript: A simple guide

REVISION OF MY INQUIRY I possess a json file titled products.json which holds a collection of products along with their id, name, quantity, description, and image URLs associated with each product. Here is an illustration of the JSON file: [ { " ...

Testing a component in Angular 2 that utilizes the router-outlet functionality

I recently set up an angular 2 project using angular-cli. As part of the setup, I created a separate AppRoutingModule that exports RouterModule and added it to the imports array in AppModule. Additionally, I have the appComponent which was generated by an ...

The JQuery loading symbol does not prevent keyboard interactions

I successfully implemented a Jquery busy indicator in my application using the following link: However, I noticed that even though it prevents users from clicking on input elements while loading, I can still navigate to these elements by pressing the tab ...

What causes TypeScript to flag spread arguments within callback wrappers?

My aim is to enhance a callback function in TypeScript by wrapping it with additional logic. In order to achieve this, I have an interface called Callbacks that outlines various callback signatures. The objective is to create a wrapper function that can lo ...

The error message "Identifier 'title' is not defined. '{}' does not contain such a member angular 8" indicates that the title variable is not recognized or defined in the

Here is the code snippet of my component: import { Router, ActivatedRoute } from '@angular/router'; import { Component, OnInit } from '@angular/core'; import { CategoriesService } from 'src/app/categories.service'; import { P ...

Connect an Observable to the template with async binding

I've been attempting to link an Observable to a template variable in Angular using the following code: [class.active]="isBookmarked$ | async" During the ngOnInit function, I initialize the Observable: var promise = this.cacheService.getItem(this.bo ...

Instructions on using $.post in jquery to sude uploaded file to a php file for processing

Is there a way to upload photos asynchronously using $.post without relying on .serializeArray()? I want to send a form, containing an upload file, to a PHP processing file. Any suggestions? HTML: <form action="upload1.php" method="post" id="usrform" ...

What type does the function in typescript return?

Could someone help me with this code snippet? export const getColor = (color: string): string => colors[color] || colors.white; I'm encountering a warning line under colors[color] || colors.white stating that it is an "Unsafe return of an any typ ...

What are the options for transferring information between HTMX and Flask using JSON or another format aside from HTML?

So I am currently working on an app using Flask and HTMX. While I understand that htmx requires data in HTML format to swap with a specific target element, I am wondering if there is a way to update the current page using different formats such as dictiona ...

Extracting Object Properties from Arrays in TypeScript

Code Snippet: interface Human { name: string; age: number; } interface Pet { name: string; type: string; } If I have an array of Human, how can I get an array of Pet's type. For instance: Is there a built-in way to achieve this in typescr ...

creating a wide div using bootstrap 4

Why is the bottom border not extending the full width within the inner div? <div class="container-fluid"> <div class="row"> <div class="col-12 col-md-2 bg-light mh-100"> <div class="d-flex jus ...

Is it possible for an image to be displayed in another div or table column when I hover my mouse over it?

I am looking to create an image gallery with thumbnails on the left side. When I hover over a thumbnail, I want the full image to be displayed in another section on the page. Can anyone provide me with the correct code or suggest a plugin to achieve this f ...

retrieving the selected date from the calendar widget

I'm utilizing jQuery's datepicker to collect date inputs from users. The form is structured as below: <form id="myform" action="/graphs/get_builds" method="post"> Start: <input type="text" id="start" /> End: <input type="t ...

Attempting to execute Gulp 4 in order to convert SCSS files into CSS

After attempting to run Gulp to convert SCSS to CSS, the process appeared to be successful without any errors. However, I encountered a problem where no CSS files were generated in the target folder. I even tried changing the output path, but the issue per ...

Creating a dropdown menu in Bootstrap 4 using JSON information

I am trying to create a dynamic drop-down menu using an input field with a drop-down button inside a form. Currently, I am attempting to populate the drop-down menu with static JSON data. However, I am encountering issues with getting it to function proper ...

What is the best way to maximize an image's height evenly outside of its full-width container?

Is it possible to extend an image beyond its parent container on both the top and bottom while maintaining responsiveness and containing remaining content within the parent? I've managed to achieve this effect on the top but struggle with the bottom. ...