Display the modal content while maintaining its current styling

When attempting to print a modal with specific data exactly as it appears, I encountered an issue where the Bootstrap classes were not being recognized during the printing process. This resulted in a change to the layout of the content printed.

function printDiv() {
  var winPrint = window.open();
  /*var header = '@include("report/header")';*/
  /*var body = '@include("memberpayment/monthlybill")';*/
  var body = document.getElementById('printarea').innerHTML;
  winPrint.document.write(body);
  winPrint.document.close();
  winPrint.focus();
  winPrint.print();
  winPrint.close();
}

The modal can be viewed here.

A preview of the print view can be seen here.

Researching online, it was suggested that including the bootstrap library before writing the print content could resolve this issue (source).

Attempts using the jQuery plugin printThis and customizable multiple elements printing plugin with jQuery did not provide a suitable solution for my case.

In another reference thread(source), introducing media="print" to the link appeared promising but did not yield the expected results.

The Modal code:

<div class="container-fluid" id="printarea" style="padding: 2rem 4rem;">
<!-- Code omitted for brevity -->
</div>

Answer №1

It's important to keep in mind that when crafting HTML for printing purposes, the element CSS floating may not function as expected across different browsers.

To address this issue quickly, consider adding the following CSS code within the modal HTML (at the beginning) -

<style>
     /* This stylesheet is specifically tailored for generating a PDF */
        /* Define page properties */
        @page {
         size: auto;  /* OR 6.5in 8.5in; A4 */
         margin-top: 0.5cm;
         margin-left: 0.5cm;
         margin-right: 0.5cm;
        } 
     @media print {

          [class*="col-md-"] {
            float: none;
            display:table-cell;
          }

          [class*="col-lg-"] {
            float: none;
            display:table-cell;
          }

         }
</style>

Furthermore, there are opportunities in your HTML to refine it and enhance compatibility for printing purposes.

I trust this information will be beneficial to you.

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 in inferring argument types for a generic interface function in Typescript

Unique interface export interface DataService { getByTypeId<T extends number | string>(id: T): Promise<SomeType>; } Additionally, the implementation export class BService implements DataService { async getByTypeId(id: number): Promise&l ...

Set the position of bootstrap column content to be fixed

I have a bootstrap row with two columns and some offset. I am trying to make the last column have a fixed position so that it remains visible even while scrolling. This last column contains image content. Although I tried using the affix class provided by ...

Adjusting the background opacity of three.js to .5

I'm currently experimenting with changing the background of the canvas in three.js to have an opacity of 0.5. I know that I can achieve a completely transparent background using new THREE.WebGLRenderer( { alpha: true } );. However, this is not the eff ...

What is the best way to access external value in an Angular directive?

check out this plunker link. HTML: <body ng-app="app"> <h1>selectable</h1> <selectable text="link1" status="true"></selectable> <selectable text="link2" status="false"></selectable> <p> ...

Preventing links from functioning on dynamically generated web pages

I have implemented the following code to deactivate all links on a preview page: var disableLink = function(){ return false;}; $('a').bind('click', disableLink); While this successfully disables all static links, any anchor tags loade ...

Is it possible to customize the color of the placeholder text in jQuery Datepicker?

Is it possible to customize the color of the placeholder in JQuery UI's Datepicker? Here is the Datepicker for reference: http://jqueryui.com/datepicker/ Link to JSFiddle example: https://jsfiddle.net/guez0tb9/ <input type="text" id="datepicker" ...

Restricting user access to a route based on its type to enhance security and control

Currently, I have a React, Redux, and Next.js app up and running. Within my redux store, there is a user object that contains an attribute called "type". Each type of user has its own set of "routes" they are allowed to access. I am looking for the most e ...

Issue: A file that has been uploaded completely ignores the req.on() method in NodeJS

I am currently using MEAN.IO to create a web application. Right now, I am working on implementing an image uploader feature. I have decided to use angular-file-upload for this purpose, and it seems to be functioning well. However, I am facing an issue on ...

Error message indicating that Element <> cannot be scrolled into view persisting despite attempting common troubleshooting methods

Currently, I am utilizing Selenium to create a web scraper for downloading multiple podcast episodes from Spreaker. # https://www.spreaker.com/show/alabamas-morning-news-with-jt for i in range(3): print("Click number: {}".format(str(i))) see_mor ...

Navigating tables with Selenium WebDriver

I am struggling to locate and interact with a specific element in a table using Selenium WebDriver. The issue is that the table IDs are constantly changing, making it difficult for me to click on the desired element. For instance, consider the following t ...

Issue with modal window not displaying upon click

I am currently navigating my way through Bootstrap and jQuery as a newbie, attempting to incorporate a modal window into my sales website. To visualize how it would appear in my project, I took the modal code from https://getbootstrap.com/docs/4.3/componen ...

unable to display preview images using the youtubev3 API

Currently in the process of creating a YouTube clone using the YouTube V3 API import React from 'react' import { Link } from 'react-router-dom'; import { Typography, Card, CardContent, CardMedia } from '@mui/material'; import{ ...

Elements stacking up in succession

I am having issues with the alignment of my div elements, as they are either stacking behind or on top of each other. td { width: 14.28%; height: 16.6%; position: relative; } .details { position: absolute; display: none; ba ...

What is the best way to implement a dynamic dropdown menu using react-bootstrap?

The react-bootstrap site provides an example code for forms, but I am struggling to find examples that utilize arrays to drive the options. <Input type="select" label="Multiple Select" multiple> <option value="select">select (multiple)< ...

Add to the current values of the REACT Form template property

I am new to working with REACT and I have been exploring whether it is possible to append a REACT Form control property value in order to enhance its functionality. To streamline the validation process, I have created a validation template that leverages ...

String arrays in Javascript with arithmetic operators

I am working with an array that contains mathematical signs. var signs = ['+', '-', '*', '/']; In addition, I have two variables representing digits to combine with each sign from the array. var right_digit = 1; v ...

The dynamic list of iframes is being loaded and encountered an error stating "Safe ResourceURL is required"

Having difficulty loading dynamic list of URLs that contain iframe videos from YouTube. This is the HTML code: <div fxLayout="column"> <div *ngFor="let v of videos"> <div fxLayout="row"> <div> Type: {{v.type}} ...

Applying CSS link dynamically in NextJS based on the window width

Is it feasible to adjust NextJS link stylesheets depending on media queries in the context of using css modules? Here is an example: CSS module file: @media(max-width: 800px) { .myClass{ /* ...mobile styles */ } } @media(min-width: 800px) { .myC ...

Coverage report not generated when running jest

I need to include some functions (sum, mul, sub, div) in the test file as shown below, import {describe, expect} from "@jest/globals"; function sum(a,b) { return a+b; } const div = (a,b) => { return a/b; } const mul = (a,b) => { ...

Align all columns to the same height

I'm facing an issue with setting the heights of col2 and col3 to 70% relative to col1 which is at 100%, and col4 and col5 to 30%. I've tried applying some styles to achieve this but haven't been successful so far. Any suggestions or recomme ...