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 best way to get rid of the blue color border around the input fields on Micromax A110 and Sony Ericsson phones?

I am currently experiencing an issue with my application where a blue outline color is appearing on the input field for Micromax A110 and Sony Ericsson mobile devices, while all other Android devices do not have this problem. I am unsure of the exact reaso ...

Horizontal alignment of Bootstrap columns is not working as expected

While attempting to integrate Bootstrap elements into my portfolio, I encountered issues with aligning columns. Currently, the only columns I have added are in the "welcome-section" (Lines 40-52), but they refuse to align horizontally. I've tried tro ...

When a fixed element is present at the top of the screen, dragging an element using React-DnD does not cause the page to scroll up to accommodate the movement

I recently discovered a peculiar issue on my dashboard. When trying to drag elements to the top of the page, where a fixed AppBar is situated, the page does not scroll upwards as expected. Upon further investigation, I realized that this behavior is due ...

SOLVED: NextJS restricts plugins from modifying HTML to avoid unnecessary re-rendering

My current scenario is as follows: I am in the process of developing a website using NextJS (SSR) I have a requirement to load a script that will locate a div element and insert some HTML content (scripts and iframes) within it. The issue at hand: It se ...

The state of a ReactJS component is failing to update whenever a value within the state array is altered

In my React component, I'm facing an issue where I want the state to update automatically without refreshing the page. I've tried using lodash's isEqual method to compare state changes, but it's not updating the state as expected. Here ...

A div element featuring a border with transparent edges on the top right and bottom left corners

Does anyone know how to code the border for the upper right corner and lower left corner of the box (as shown in the image below)? I would really appreciate some help. Thank you in advance! This is the HTML <div class="carouselle"> <div clas ...

Arranging an array of objects by their alphanumeric string property values

Currently, I am facing an issue with sorting an array of objects in TypeScript. The structure of my array is as follows: [ { "title": "Picture3.jpg", "targetRange": "B2", "type": ...

Discover the highest value within an array of objects, along with any numerical object attributes that have a value greater than zero

Considering an array of objects structured as follows: [{ "202201": { "WO": 900, "WS": 0, "SY": 0.915, "LY": 0.98, "CT": 75 }, "202202" ...

Utilizing jQuery and CSS to make an entire div clickable, and activate an 'a' tag hover state upon hovering

Looking to create a clickable link for the .wrapper div that directs users to the location of a.icon. Want the .wrapper div to activate the a.icon:hover state when hovered over, not just when hovering over the icon itself. Any assistance would be highly a ...

Shifting HTML table in Javascript by toggling checkboxes

When I click the checkbox, the table elements are not displaying inline. I am simply hiding the class "box". Do I need to write a special format? By default, the elements are displayed inline but when I check the checkbox, they shift. The column 'Stat ...

Is it possible to utilize a redux store as the source for translation resources in next-i18next?

My website features contentEditable text, allowing users to edit the text. I am now looking to implement translations so that any user edits are reflected in the translations.json file. I have set up a redux store with actions mirroring the structure of th ...

What could be causing my display: table-cell element to not take up the entire available space?

After consideration, I have decided to avoid using a JavaScript solution for my problem. The only way it seems to work consistently is by using setInterval() at regular intervals, which I prefer not to do. I am aware that achieving the same effect with CSS ...

Complete multiple React forms and have a single button located separately from the components handling those forms

In the midst of my work on a ReactJS project, I have encountered a challenge that has been perplexing me for quite some time. I find myself dealing with multiple forms, each controlled by its own component (Class), and I am looking to submit all these form ...

It seems like there is an issue with your network connection. Please try again

Recently, I made the switch to EndeavourOS, which is based on Archlinux. I completed all my installations without any issues and attempted to create a new NestJs project after installing NVM, Node's latest version, and the NestJs/cli. However, when I ...

React submission alert has been sent successfully

How can I display a "Successfully Submitted" alert in React? Hello, I am new to React and I have created a Contact Us page. When the user clicks the submit button, I would like to show a message saying "Submitted Successfully". However, I am struggling to ...

Menu Tabs with Rounded Edges

Seeking help to round the corners of a tabbed dynamic menu using Drupal and the dynamic-persistent-menu module. The code provided below is almost perfect, with 99% accuracy. View the current state of the menu here: . Can anyone assist in achieving the rema ...

Tips for including multiple directives in a component

Apologies in advance for my lack of clarity in expressing this question, which is why I am seeking assistance rather than finding the solution on my own. My query pertains to loading a component within another one and specifying it in the directive. Below ...

After filling a Set with asynchronous callbacks, attempting to iterate over it with a for-of loop does not accept using .entries() as an Array

Encountering issues with utilizing a Set populated asynchronously: const MaterialType_Requests_FromESI$ = SDE_REACTIONDATA.map(data => this.ESI.ReturnsType_AtId(data.materialTypeID)); let MaterialCollectionSet: Set<string> = new Set<s ...

Obtain SVG icons seamlessly in Next.js

My goal was to dynamically retrieve SVG icons, and I discovered a method to achieve this. However, it seems like I have made some errors along the way. Can you point out where I am going wrong? Icon.js import React from "react"; import { ReactCo ...

Switch the secondary menu to be the main menu on all pages excluding the homepage in WordPress

I am looking to customize my menu display by showing the primary menu only on my home page (front-page.php) and displaying the secondary menu on all other pages except for the home page. In my functions.php file, I have registered both the primary and sec ...