This is a beta release. Please report any issues in the issue below, thank you!
- FIX 764 Ensure
onAfterPrint
is called, and print iframe is removed, after the print preview dialog has closed. Previously these would happen when theafterprint
event was received which, as noted in the README, may occur immediately in some browsers, rather than when the print preview dialog closes. Thanks sensasi-delight
- FIX 751 Ensure selected
<select>
option printed. Currently the first option is printed regardless of selection state - FIX 753 Fix incorrect ESLint config reference to tsconfig file
- FIX 743 Allow passing the function returned from
useReactToPrint
directly to event handlers (this is primarily geared at non-typescript users who are not aware of the new v3 API that prefers the function be wrapped, by changingonClick={printFn}
toonClick={() => printFn()}
)
v3.0.0 brings API modernization, React 19 support, a smaller package size, Shadow DOM support, and improved error handling.
content
renamed tocontentRef
and type changed from() => React.ReactInstance
toRefObject<Element | Text>
. The core impact here is that Class components now need to have the ref forwarded via props internally to a DOM node- React >= 16.8.0 required (dropped support for React versions that don't support hooks)
onBeforeGetContent
removed. UseonBeforePrint
, which similar toonBeforeGetContent
, now runs before the print iframe is loadedremoveAfterPrint
renamed topreserveAfterPrint
which defaults tofalse
ReactToPrint
removed. UseuseReactToPrint
PrintContextConsumer
removed. UseuseReactToPrint
trigger
removed, use the function returned byuseReactToPrint
IReactToPrintProps
renamed toUseReactToPrintOptions
- Default package export removed, use named
useReactToPrint
export - Removed
event?: unknown
type fromuseReactToPrint
callback.optionalContent
is now the only (optional) argument - Build is now ES6 code. Previously it was ES5
- No longer supporting IE11
- FEATURE 717: React 19 support + API modernization
- FEATURE 707: Improved error handling when
canvas
elements have not properly loaded - FEATURE 723: Add new option,
copyShadowRoots
, to support copyingShadowRoot
s. Thanks boehlke - CHORE: package size reduced by 18.7kb (34%)
- CHORE: dev dependencies updated
3.0.0-beta-3
(19 Aug 2024)3.0.0-beta-2
(19 Aug 2024)3.0.0-beta-1
(15 Jul 2024)
- FEATURE 652: When using the
useReactToPrint
hook it is now possible to pass the returned callback thecontent
ref at call time, rather than needing to pass it to the hook directly. This allows for generating the content to be printed closer to when the print occurs. Thanks isocroft - DEPENDENCIES: Upgraded all
devDependencies
to their latest versions - CHORE: broke up the single file in the repo, started organizing things a bit
This is a republish of 2.14.14 since that version got screwed up by some downtime at npm and seems to be in an unrecoverable state.
- FIX 635: Ensure proper handling of
<link>
nodes that have multiple valuerel
attributes set such asrel="prefetch stylesheet"
, and, ensure proper handling of<link>
nodes usingrel="preload" + as="style"
- DOCS 637: Added README section regarding having proper a
media
attribute set on<link>
nodes - DOCS 633 Added README section regarding proper printing of scrolled containers. Thanks siaikin!
- DEPENDENCIES: Upgrade all
devDependencies
to their latest versions
- FIX 616: When passing a custom
print
function we were not waiting for that function to resolve its promise before removing the printing iframe ifremoveAfterPrint={true}
was set. Further, we were not callingonAfterPrint
at all when a custom printing function was passed. While not strictly needed since the caller knows when the printing has completed by resolving the promise, we now callonAfterPrint
when that promise has resolved and before removing the print iframe - DEPENDENCIES: Removed our long unused single prod dependency,
prop-types
. The package now has zerodependencies
🪓 - CHORE: Updated all
devDependencies
to their latest versions - CHORE: Removed a bunch of old unused files including
require.d.ts
,.babelrc
, and an unused example
- FIX 565: Support font-weight and font-style for custom fonts (and add more font examples). Thanks gauthierrodaro
- CHORE: Updated all
devDependencies
Happy new year! We can't wait to see what 2023 brings
- FIX: Ensure we wait for
fonts
to print if they are given - FIX: Ensure we continue trying to print when
fonts
are passed by the browser doesn't support theFontFace
API - FIX: Improved chances of FireFox printing backgrounds by default in the Print Preview window
- FIX: Ensure we only process resources once
- CHORE: Simplified loading logic, including improved error messages when a resource fails to load
- CHORE: Removed unused TravisCI config
- CHORE: Updated all
devDependencies
- CHORE: License year updated for 2023 :)
- DOCS: A bunch of examples and gotchas were added to the README, improved example
- FIX 556 In 2.14.9 we changed the print
iframe
size to be dynamic but didn't take into account the fixed offset we were giving to hide it on the page. This resulted in the printiframe
being partially visible when printing on wide screens. This has been corrected
- FIX 553 Ensures that the
iframe
used for printing has the same viewport size as the parent window of the node being printed. Prior to this the browser set the default 300px/150px size on theiframe
, causing code that changes styles based on viewport sizes (such as many grid systems) to sometimes change the display of the elements being printed, requiring CSS hacks to avoid. Thanks dantecarlo for reviving this issue
- FIX 537/545
<link>
nodes marked with thedisabled
attribute were causing printing to hang. Thanks luckrnx09 - FIX/CHORE 545 Updated examples to use React 18. This also exposed a minor typing bug (
ReactToPrint
needed to specify achildren
prop to fully support React 18) which was corrected. Other dependencies were also updated, mostly dropping Node 12 support - CHORE 538 The examples had some minor Webpack related refactors
- FIX 484: Previously
onAfterPrint
was not being called if a customprint
function was passed. Now it will always be called - CHORE: a couple
devDependency
updates to makenpm audit
happy
- FIX 485:
react-to-print
assumed that thetagName
of<style>
nodes was always'STYLE'
, however, sometimes it can be'style'
or possibly other case combinations. Added resiliency to the check so now any casing of'style'
will pass the check
- FIX 459:
react-to-print
now ensures that aDOCTYPE
is set on the print iframe. Without this some browsers could render the print iframe in quirks mode, possibly changing the output - CHORE: Removed some debugging statements that made it into a previous production build
- CHORE: Updated all dependencies
- DOCS: Added a section with a link to a fully-working Electron example
- FIX 439:
react-to-print
now waits forvideo
elements to load before printing. While this should work in most cases, we highly recommend setting theposter
attribute of thevideo
, which allows specifying an image to be a placeholder for the video until the video loads. - CHORE: cleaned up the examples code a bit, including adding tests for
video
elements - CHORE: all
devDependencies
have been upgraded to their latest and greatest
Happy new years!
- FIX: As seen in 441 when using the
useReactToPrint
hook along with TypeScript and strict checking the user is currently required to ensure that the return ofuseReactToPrint
isn'tundefined
, since that is what is returned if the user is using a version of React that does not support hooks. To remove the need for this checkuseReactToPrint
will now return a function that throws an error if the version of React does not support hooks.
- FIX 429: Attempting to access the contents of a cross-origin stylesheet is forbidden by scripts, and attempting to do so would cause
react-to-print
to crash. Upstream work in the browsers is required to find a proper solution to this, read more in the issue. Atry/catch
has been added around the offending code, along with a warning message with tips on how to resolve. Thanks @JoshuaKGoldberg for lots of debugging help - FIX 432: TypeScript 4.4 shipped with
FontFace
support in its lib definitions which causedreact-to-print
to fail to build locally on versions of TypeScript >= 4.4 since ourFontFace
definitions clashed with those now in TypeScript. This has been resolved, thanks @oxygen-xx - DOCS 422: The README was updated to properly reflect that functional components can be used so long as they are wrapped with
React.forwardRef
- DOCS 430: A typo was fixed, thanks @hsusanoo
- FIX 391: Setting
documentTitle
will now properly set the filename when printing as a PDF in Chrome, Firefox, and Safari - FIX: a rare (no reported events) edge case could cause printing to hang if an image failed to load and error logging was not enabled. This has been fixed
- FEATURE: the UI for running the examples has been massively improved. Try them out! We will be porting this to our official CodeSandbox example soon.
- CHORE: changed an error message saying only class based components are allowed to be printed to clarify that functional components wrapped in
React.forwardRef
can be printed as well - CHORE: refactored logging code to be DRYer and simpler to use
- CHORE: all
devDependencies
have been upgraded to their latest and greatest - DOCS: major improvements to the README, including making some examples more concise, adding information about using functional components to print, adding some new pitfalls, and adding information about known issues when printing in mobile WebViews (see #384 for more)
- FEATURE 402: support passing a
nonce
property to be used with CSP. Thanks @Arcturus5404 and @nenonja
- FIX 379:
img
tags missing asrc
attribute should not prevent printing
- CHORE: Upgraded
devDependencies
- CHORE: Upgraded all
devDependencies
- DOCS: Added a section to the README about workarounds for functional components as the
ComponentToPrint
- FIX 344: Remove the single use of
ParentNode.append
in favor ofNode.appendChild
.append
is not supported by IE11, and polyfilling it within the context of an iframe can be difficult - FIX 344: While testing the above I realized that trying to print out a bare string didn't work. This has been fixed
- CHORE: Upgraded all
devDependencies
Happy new years!
- FIX 196: For a long time various inputs/select did not properly copy their value over into the print window. This has been corrected!
- FIX 292: Removed usage of
document.write
- FIX: Edge case where passing a function to the
pageStyle
prop that did not return a string could cause problems - CHORE: Upgraded all
devDependencies
- CHORE: Minor README updates
- FIX 329: v2.12.0 upgraded Webpack from 4 -> 5 which broke the package for environments that didn't support ES6 as Webpack now requires finer grained controls to output pure ES5 code. These changes have been made.
- CHORE: upgraded all devDependencies
- CHORE: added React/ReactDOM ^17 to allowed peerDependencies. Library still supports React >= 15, though expect a major release in the near-future that drops React 15 support, which will clear the way to removing the restriction that the top-level component being printed must be a class component
- CHORE: upgraded all devDependencies. Big changes here include updating Typescript from 3 -> 4 and Webpack from 4 -> 5. While upgrading Webpack the minifier was changed from UglifyJS to Terser, resulting in a 5.7% reduced file size (14.1kb -> 13.3kb)
- CHORE: Use Node ^14 for CLI tests
- DOCUMENTATION: small improvements to the examples, including renaming them from
example
->examples
- DOCUMENTATION: added a note about finding the
examples
folder - DOCUMENTATION 311: small type fix, thanks nealeu
- DOCUMENTATION: added a "Common Pitfalls" section to the README, starting with a note on using the library with a component wrapped in
connect
fromreact-redux
- FIX/FEATURE 285: Adds a new
fonts
prop which allows the passing of custom fonts. Previously custom fonts were not loaded into the print window - CHORE: update patch and minor
devDependencies
,dedupe
, andaudit fix
- FIX 301: Ensures the library works with modules that have a
null
prototype such as ES modules and SystemJS modules. Thanks joeldenning
- FIX 298: Fixes a long-standing issue of checkbox state not always copying properly into the print window. Thanks aviklai
- CHORE: update patch and minor
devDependencies
,dedupe
, andaudit fix
- FIX 296: Ensure
bodyClass
can handle multiple class names instead of just a single class name. Thanks seanblonien - CHORE: update patch and minor
devDependencies
,dedupe
, andaudit fix
- FEATURE 272: a new prop
print
has been added. This can be used to override the default browserWindow.print
. This can be useful if you want to print in an alternative environment such as Electron. As part of this change,onPrintError
will now report if an error occurs in a passed inprint
method. Thanks to Ririshi for this idea - DOCS 269: added guidelines for how to achieve nice page breaks. Thanks hbrannan
- CHORE 273: updated
devDependencies
,npm dedupe
,npm audit fix
- FEATURE 255: updated local development examples so that every use case is covered
- FIX 255:
onload
event listener is now cleared after being called - FIX 255:
useReactToPrint
now properly setsdefaultProps
- CHORE 256: updated
devDependencies
to latest. This clears a high severitynpm audit
issue
-
FEATURE 245:
documentTitle
prop can now be passed to set a default filename when the user is saving as a PDF. Thanks zb2oby -
FEATURE 244:
trigger
is now an optional prop. To print without it we now offer two new options.PrintContextConsumer
with a render-props pattern:import { PrintContextConsumer } from 'react-to-print'; <ReactToPrint content={() => this.componentRef}> <PrintContextConsumer> {({ handlePrint }) => <button onClick={handlePrint}>Print this out!</button>} </PrintContextConsumer> </ReactToPrint>
useReactToPrint
for hook-based printingimport { useReactToPrint } from 'react-to-print'; const Example = () => { const componentRef = useRef(); const handlePrint = useReactToPrint({ content: () => componentRef.current }); return ( <div> <ComponentToPrint ref={componentRef} /> <button onClick={handlePrint}>Print this out!</button> </div> ); };
Huge thanks to vtsybulin for these fantastic additions.
-
CHORE: upgrade
devDependencies
to latest
- FEATURE 198:
pageStyle
prop can now be passed as a function. Thanks sergeyshmakov - FIX 218: Image duplication in Edge and IE. This should also fix 211 (slow performance with many images on the page). Thank you dioscarey for helping to get this pushed through
- Fix 93: Check for existence of
target.contentWindow.print
- CHORE: updated an error message (see 96)
- CHORE: updated all
devDependencies
to latest - CHORE: slightly decreased size of the build by better using UglifyJS
- CHORE: enabled TypeScript strict mode
- CHORE: added a "Compatibility" section to the README. Also moved some sections around and shortened the example
- CHORE: improved browser built targets based on
browserslist
best practices
- FIX 224 Handle the
content
prop returningnull
. This is required for proper usage in TypeScript strict mode. Thanks a-sync
- CHORE 220 Added
suppressErrors
documentation to the README
- FEATURE 220 Adds a
suppressErrors
prop. When passed, console logging of errors is disabled. Thanks invious
-
CHORE 208 Minor improvements to code comments, linting, and README
-
CHORE 207 Updated
devDependencies
-
FIX 204: Ensure images are fully loaded before printing. Previously long-loading images might not be included in the print. This ensures that we wait for them to load, similar to how we wait for style sheets to load. Thanks nhanhuynh-agilityio
-
FEATURE 172: Allow the
trigger
component to be a functional component. Previously, only class based components were allowed here. Thanks idanhaviv -
FEATURE 172: Enable CSS HMR when running the local example build. Thanks idanhaviv
-
FEATURE 161: add a new callback method
onPrintError
. This method is called whenreact-to-print
catches a Promise rejection in eitheronBeforeGetContent
oronBeforePrint
. The API docs were also cleaned up to better explain which method to use when. -
FEATURE 158/160: add new callback method
onBeforeGetContent
. Currently,onBeforePrint
is called before the print window is opened but afterreact-to-print
has gathered the content of the page. This new method is fired beforereact-to-print
gathers the content of the page, meaning it can be used to change the content of the page before printing. It can optionally return aPromise
. Thanks @andfs
-
CHORE 156: dependency upgrades. All listed dependencies were manually upgraded to their latest versions.
npm audit fix
was then run to give us a clean audit. Finally,npm dedupe
was run to reduce package bloat. -
FIX 156: a stylesheet that no longer exists but that was being required by the local example has been removed
NOTE: To build the library locally, Node ^8.6 is now required
-
FIX 154: TSLint was not working properly for the project. A configuration was added, and linting errors were fixed. While fixing linting errors, a bug was discovered whereby if a stylesheet was found that did not have tag type
STYLE
it was possible thatreact-to-print
would not include all stylesheets from the page into the print window -
FIX: 154 (meant to be a different PR, was included by mistake in 154): When passing
removeAfterPrint
some users were getting the errorTypeError: Object doesn't support property or method 'remove'
. This was due to using an incorrect way to remove the iframe
- FEATURE 152: Previously, this library used a window rather than an
iframe
to handle printing. That was changed some time ago, however, thecloseAfterPrint
prop was never removed from the documentation (though it was removed from the code). This release restores similar functionality, in a newremoveAfterPrint
prop. Passing this prop will ensure thatreact-to-print
removes theiframe
it uses to print from the DOM after printing (something that it currently does not do). NOTE: theiframe
is removed after the call toonAfterPrint
(if provided) has completed. We will likely make this the default functionality in version 3, but are keeping it like this for now to ensure anyone relying on theiframe
does not face issues. Thanks aviklai
- FEATURE 140:
onBeforePrint
can now optionally return a Promise. If a Promise is returned,react-to-print
will wait for it to resolve before continuing with the print. NOTE:react-to-print
does not handle if the Promise rejects, so this must be accounted for when using this option. Thanks aviklai
- FIX 134: Solve print window issues in Safari (especially Mobile Safari), thanks Ellenergic
- CHORE: Updated the README to contain a link to a fully updated demo
- FIX: Ensure we build the package as UMD instead of CommonJS (#116, thanks @aviklai)
- CHORE: Added a CHANGELOG
- CHORE: Convert the package to TypeScript (#111, thanks @sergeyshmakov)