The issue of printable html not causing a new page break on Firefox has arisen

Recently, I've been working on creating an HTML report that I need to print out. In order to achieve this, I decided to make use of AngularPrint plugin (https://github.com/samwiseduzer/angularPrint).

However, I encountered a problem when trying to print the report using Firefox. The content was overflowing the page boundaries and not properly fitting in one page.

On the other hand, when testing the same report with Google Chrome, the browser automatically created new pages to prevent content overflow issues.

I attempted to address this problem by utilizing native window.print function as shown below:

$scope.printReport = function(myhtml) {
  var content = document.getElementById(myhtml).innerHTML;
  var original = document.body.innerHTML;        
  document.body.innerHTML = content;
  window.print();
  document.body.innerHTML = original;
}

This is how my HTML code looks like when using AngularPrint:

<!-- printable area -->
<div class="content" print-section>
   ...
   ...
</div>

To trigger the printing process, I added a button as follows:

<button class="btn btn-success" id="btnPrinReport" print-btn> Print Data </button>

Answer №1

Instead of manipulating the DOM, have you considered using CSS media queries? Here's an example:

@media print
{
  .content{
     position:fixed;
     top:0;
     left:0;
     min-width:100vw;
     min-height:100vh;
   }
}

You can then simply call a JavaScript function like this:

$scope.printReport = function(myhtml) {
 window.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

Using AJAX to dynamically edit and update PHP data

The information displayed on my index.php page is fetched from a database using the mysqli_fetch_array function. The data is presented in a table format with fields like Name, Age, Email, and Update. An edit button allows users to modify the data. Here is ...

AngularJS does not bind redefined variables

Having just started delving into Angular, I've encountered an issue while creating an application where a single AngularJS bind fails to update when the value of the bound object changes. This is a simplified version of the app, hence its structure. ...

Guide to triggering an event when two distinct keys are pressed simultaneously (Using HTML5 and Javascript)

I'm looking to have my character jump whenever I press any key on the keyboard. Is there a method to achieve this using "case..." functions? Thanks! Jordan ...

What is the solution for correcting the currency formatting in a text input field?

Hello everyone, I have a question about formatting numbers in my code: I want to format numbers like this: 001 -> 0,01 || 10000 -> 100,00 || 10012300 -> 100.123,00 and so on... However, the issue is that my current code only adds the ',&apo ...

searching for a refined method to tackle this challenge

I'm relatively new to Angular and I'm interested in finding a more efficient solution for this particular task. The code below functions correctly, but I am uncertain if it is the best approach to achieve the desired outcome. HTML <div ng-a ...

Web API OData failing to retrieve accurate metadata

I am currently utilizing OData v4 in conjunction with Web API to interact with my AngularJS web application. Specifically, I am attempting to showcase my data using Kendo UI Grid. The issue I'm encountering is that the metadata returned by my Web AP ...

Passing along the mouse event to the containing canvas element that utilizes chart.js

Recently, I created a custom tooltip for my chart.js chart by implementing a div that moves above the chart. While it works well, I noticed that the tooltip is capturing mouse events rather than propagating them to the parent element (the chart) for updati ...

Converting data to a JSON string using jQuery's AJAX method

When I use document.write() for JSON data, it works fine outside of the AJAX call, but not inside the .done() function. I even tried removing the dataType: 'json' parameter, but it still didn't work. $.ajax({ url: "http://api.wundergrou ...

A step-by-step guide to extracting live data using cheerio and socketio

I am currently scraping data from a website using Cheerio. Can someone provide me with guidance on how to retrieve web data and automatically update it using socket communication when there are changes on the website? I want to make this process real-tim ...

Is Optional Chaining supported by Next.js on Vercel?

While Next.js does support Optional Chaining, I have encountered an issue when trying to deploy the following code snippet: module.exports = { experimental: { outputStandalone: true, }, images: { domains: process.env.NEXT_PUBLIC_IMAGE_DOMAINS ...

I am facing errors while running npm run build in my Vue CLI project, however, npm run dev is running smoothly without

I am encountering an issue when running npm run build as it generates a series of errors, whereas npm run dev runs smoothly without any errors. I have attempted to resolve this by modifying the public path in webpack.config.js to ./dist, but unfortunately ...

Using 'cy.get' to locate elements in Cypress tutorial

Is there a way to search for one element, and if it's not found, search for another element? cy.get(@firstElement).or(@secondElement).click() Can I use a function similar to || in conditions for this scenario? ...

Objects within the Prototype in Javascript

While delving into the world of AngularJS, I stumbled upon an interesting revelation - when objects are placed in a prototype object, any instances inheriting from that prototype will alter the prototype's objects upon assignment. For example: funct ...

JS is programmed to automatically redirect the user after they have clicked on a div element and a

I'm having trouble with this code that is supposed to redirect a user after they click on the div and then the next button. It's not working for me :( Here is the code I am using: $("a.xxx").click(function() { $(this).toggleClass("yyy"). ...

Automatically focus on input when scrolling reaches a specific element using jQuery

I have been utilizing a jQuery plugin called Waypoints to handle scroll actions. My goal is to focus on the first input element of a section that is currently visible on the screen and then shift the focus to the input of the next respective sections as t ...

Arrange objects in an array based on certain criteria using JavaScript in a dynamic

I have an array containing various items that need to be sorted according to specific rules. The goal is to group all values with "rules" together, and ensure that "ELIG_DATABASE" is grouped with "ELIG_SERVICE." const items =[{"name":"ELIG_ ...

We cannot render objects as children in React (found: [object HTMLDivElement])

How can I successfully pass a value to a div with the id good in my index.html without encountering the following error message: Objects are not valid as a React child (found: [object HTMLDivElement]). If you meant to render a collection of children, use a ...

Calculate the number of characters in the input and increase a variable by one every x characters

Currently, I am incorporating AngularJS into a new project and faced with the task of counting the length of a textarea. Adding up the total number of "pages" in the messaging app every 160 characters while decreasing if text is removed. Obtaining the len ...

NodeJS executor fails to recognize Typescript's CommonJS Internal Modules

In the process of developing my NodeJS application, I am structuring it by creating internal modules to effectively manage my code logic. This allows me to reference these modules without specifying the full path every time. internal-module.ts export cla ...

Having trouble with a React child component not reacting to a click event?

The current issue I am experiencing is that the component is not triggering a click event when the button is clicked. TickerPage render() { return ( <div className="TickerPage"> <div className="TickerPage-container"> <b ...