Printing from a lengthy React DOM using window.print only generates a single page

My React component is capable of rendering markdown and can span multiple pages. Everything looks great when the component is displayed in the browser - scrolling works perfectly.

However, whenever I try to print the page using window.print or ctrl + P, only a single page is captured. The content does not split into multiple pages and there is no scrolling available in the preview.

Could someone please provide some guidance on how to fix this issue? Thank you!

Answer №1

Sharing this in the hopes that it may benefit others.

In React, the virtual DOM only renders what is visible in the viewport, not the entire component. This caused an issue when trying to print a preview as it only showed the content of the viewport.

To resolve this issue, I resolved to render all content to an iframe and then printed the iframe for the desired result.

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

What is the source of the backgroundColor property inheritance for FilledInput in Mui?

Recently, I encountered a challenge while working on Filled Inputs within forms using TextFields and FilledInput. I am seeking a more efficient solution to change the background color of all the FilledInputs. Currently, I am utilizing makeStyle and adding ...

Tips for structuring your useState and useQuery hooks in Apollo/Graphql applications

I'm encountering an unusual issue while attempting to pass data from useState([]) to the variables used for filtering products. What I'm observing is that when I click on a category checkbox, it remains unchecked. However, the products are filte ...

What could be causing TypeScript to not locate my custom package?

I decided to create a fork of an existing package and released it with a new, distinct name: https://www.npmjs.com/package/feed-media-fork After tagging a new version, setting up a release on GitHub, and running yarn add feed-media-fork or the equivalent ...

Radio buttons are not having the :invalid pseudo class properly applied

Looking to style a radio group with a required attribute. Attempting to adjust the appearance of the radio group depending on whether an input is selected or not. However, it appears that the :invalid pseudo-class does not apply to radio buttons. ...

Something seems to be preventing Div from appearing and there are no error messages appearing

I've been attempting to create a menu, but the toggle div for the menu isn't visible Following a tutorial where an individual sets up a menu, there is a div with a menu icon in the top left corner. Despite meticulously copying the code from the ...

Ensuring Consistent HTML5 Page Layout Across Various Browsers Using CSS

Hey everyone, I recently created an HTML5 page and utilized the <section> tag. However, I'm encountering issues with the CSS file I'm using. It seems to work perfectly on Firefox, but the layout is all over the place when viewed on Chrome a ...

Creating a powerful combination: Building an Express backend integrated with a sleek React front-end

I am facing a bit of challenge in setting up the connection between my front-end and back-end logic. I'm simply trying to fetch data from Express to test if everything is working correctly, but it's proving to be quite difficult. Additionally, I ...

Original: Generic for type guard functionRewritten: Universal

I have successfully created a function that filters a list of two types into two separate lists of unique type using hardcoded types: interface TypeA { kind: 'typeA'; } interface TypeB { kind: 'typeB'; } filterMixedList(mixedList$: ...

Personalized path-finding tree iterator

I am trying to implement a custom iterator in JavaScript that can traverse a DOM tree based on specific criteria provided by a callback function. The goal is to return an array of the nodes that match the criteria as the generator iterates through the tree ...

Showing the outcome of the request from the backend on an HTML page using the MEAN stack

I am currently in the process of developing an angular application with a node.js + express backend. After successfully retrieving the necessary data from MongoDB and being able to view it through terminal, I encountered a challenge when trying to display ...

Unwinding asynchronous Dilemma

I am completely new to Recoil and I have a query regarding asynchronous operations in Recoil. Consider the code snippet below: const usersState = atom({ key: "userInfo", default: { email: "", name: "" } }) ...

Problem with applying Tailwind CSS classes in the Creative Tim Notus React template

Currently, I am utilizing the Notus react template. My goal is to adjust text size based on different screen sizes, however, it appears that this functionality is not functioning properly. Even on medium screens, the text size remains at "text-2xs." In a ...

Font malfunctioning on Microsoft Edge and Internet Explorer

Apologies if this seems like a silly question, but I recently imported a font from my computer into a CSS file. While it displays correctly in Chrome, it's not working in Microsoft Edge or Internet Explorer. Unfortunately, I don't have access to ...

The complexity of utilizing the map() function in React causes confusion

While delving into React, I stumbled upon this interesting code snippet: {this.state.sections.map(({title, imageUrl, id, size}) => ( <MenuItem key={id} title={title} imageUrl={imageUrl} size={size}/> ))} I'm intrigued by the use of destruc ...

The integration between React.js, Node.js, and Express.js is facing issues with the socket.io functionality

I am currently working on integrating socket.io with React.js, running the socket.io on a backend server using Express.js. One issue I am facing is that when an order is placed on the homepage, it should be displayed in real-time on the Orders page in Rea ...

Can TypeScript be used to generate a union type that includes all the literal values from an input string array?

Is it feasible to create a function in TypeScript that takes an array of strings and returns a string union? Consider the following example function: function myfn(strs: string[]) { return strs[0]; } If I use this function like: myfn(['a', &a ...

Enable jquery offsetParent() function

$(document).ready(function(){ $("button").click(function(){ if ($("p").offsetParent().css("background-color") === "red") { $("p").offsetParent().css("background-color", "yellow"); } else { $("p").offsetParent().c ...

The CSS formatting is not being properly applied within the innerHTML

I have a scenario where I am trying to display a Bootstrap card using innerHTML in my TS file, but the styles are not being applied to this content. I suspect that the issue might be because the styles are loaded before the component displays the card, cau ...

Converting a base64 image to an image object in Node.js: A comprehensive guide

My frontend implementation utilizes React, where the input accepts image files. ... onImageChange = event => { if (event.target.files && event.target.files[0]) { let img = event.target.files[0]; //This is the image object //The ...

Identifying smooth navigation within getServerSideProps in Next.js

In Nextjs, I understand that after the initial loading, it will function like a standard React app and server data functions such as getServerSideProps will act as regular endpoints that return the next page data as JSON and allow for navigating to the nex ...