react-component-export-image | Export component as jpeg , png or pdf | Image Editing library
kandi X-RAY | react-component-export-image Summary
kandi X-RAY | react-component-export-image Summary
Export component as jpeg, png or pdf
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of react-component-export-image
react-component-export-image Key Features
react-component-export-image Examples and Code Snippets
Community Discussions
Trending Discussions on react-component-export-image
QUESTION
In my React app I'm using material UI (material-ui.com) with SVG icons. When I try to export components including SVG icons to PDF using react-component-export-image, then all SVG icons are missing.
The SVG icons are defined such as:
...ANSWER
Answered 2022-Apr-03 at 12:35The simple solution: use html-to-image instead which works out of the box with the SVG icons but also in more complex scenarios (I was asking here only about the first of a series of html-to-image bugs I was confronted with).
Moreover, html2canvas also is buggy in what could be described as "shadow" matte overlays appearing (no idea why it creates them) and arbitrary clipping.
QUESTION
I was getting the 'window is not defined' error when importing react-component-export-image
so I used a dynamic import to get around that. I don't get that error anymore but now I get 'exportComponentAsPNG(componentRef)
is not a function'. Is there a better way to deal with the 'window is not defined' error or a way to use the function I am importing dynamically? If not, is there a different npm library that works to generate an image from a react component?
ANSWER
Answered 2021-Nov-17 at 10:57next/dynamic
is used to dynamically import React components, not regular JavaScript functions or libraries.
For that, you can use a regular dynamic import on exportComponentAsPNG
inside the onClick
callback.
QUESTION
I'm trying to export a chart to an image and I want the chart image to have a custom legend that is not being displayed on screen.
How can I do that?
For now I have tried to export using react-component-export-image but if the component is not displayed the ref is null and It cannot be exported. See component export implementation src-code.
Example of my current code: codesandbox
...ANSWER
Answered 2021-Jun-03 at 12:58The only way you can achieve that by manipulating the canvas before render. You can do that by setting the onclone
option in html2CanvasOptions
.
QUESTION
I want to export Grommet TextArea
as an image. The following code works if there is just a single line of text. But if I adjust the TextArea
component in a way to make the text fill multiple lines, this won't be exported in the output image.
This is how it looks (1 - is the page which contains the multiline TextArea
I want to export, 2 - the exported TextArea
, containing just a single line of text)
Seems like I'm just missing something about HTML canvas. Or maybe there is some property in Grommet TextArea
which helps with changing that behavior?
App.js:
...ANSWER
Answered 2021-Mar-03 at 20:50I think that the issue lay in the way the image is being exported. I created a quick test using only 'textarea' of HTML instead of the Grommet TextArea component and the issue still occurs:
I've verified that the behavior you've described is the expected behavior from react-component-export-image
package by running the HTML example on their demo app, and it seems that this is their core functionality behavior. You might want to file an enhancement request that asks to support multiline screenshots. Here is the screenshot example from running the HTML example on their demo app:
QUESTION
I'm trying to use exportComponentAsPNG
function from react-component-export-image
lib:
https://www.npmjs.com/package/react-component-export-image
exportComponentAsPNG(node, {fileName, html2CanvasOptions})
The function works great if I pass just a component. But I can't make it work with optional params
and produce an image with transparent background (maybe I'm missing something about optional parameters conversion of JS in general). So I tried to pass a backgroundColor
option, which, I think, should help me with getting a transparent background. What I've already tried:
exportComponentAsPNG(node, backgroundColor = null);
exportComponentAsPNG(node, backgroundColor: null);
exportComponentAsPNG(node, { backgroundColor: null });
I could specify backgroundColor
with the previous version of react-component-export-image
API, but now I'm getting lost with the new syntax.
ANSWER
Answered 2021-Jan-27 at 12:41As it is mentioned in the docs
How to UpgradeThe previous way of using an export looked like this:
exportComponentAsJPEG(node, fileName, type, backgroundColor, options)
- The new way: pass node & an optional object with only the fields you need.
- backgroundColor is no longer accepted in this main object, but is accepted in the "html2CanvasOptions" object, which is passed directly to html2canvas
if you say it've worked before with backgorundColor equals to null you should call it this way
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install react-component-export-image
backgroundColor is no longer accepted in this main object, but is accepted in the "html2CanvasOptions" object, which is passed directly to html2canvas
type is no longer accepted - JPG will always produce JPG, PNG => PNG, PDF => PDF
exportComponentAsPDF also accepts an additional pdfOptions object (see introduction)
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page