Comments (6)
your "svgElement" is not an SvgElement, but rather a document.
Read the whole answer in the linked stackoverflow question and add .documentElement
to your parser call.
Regarding the react stuff - svgElement2 also isn't an SVGElement, but an object that only makes sense to React.
Please use the Discussions to discuss issues in your code. If you find a bug in the library, create a test-case and open a new issue. Thanks.
from svg2pdf.js.
Why?
This lib needs to work on the SVG DOM. Why should it also deal with parsing and loading? What's the use-case?
from svg2pdf.js.
my use case is to convert a layout/designer made with fabric.js to PDF in the browser, it would make it much easier if this lib already handles this
from svg2pdf.js.
Much easier?
Much easier than this: https://stackoverflow.com/a/24109000 ?
from svg2pdf.js.
I'm also against adding this to the library. We could add it as a code snippet to the readme.
from svg2pdf.js.
I'm trying to add an SVG to a new PDF using this method. Basically when the user clicks a link it is supposed to pop up a modal with the newly created pdf in the modal. I am getting this error: Uncaught (in promise) TypeError: e2.tagName is undefined
.
Here is the relevant code in my modal component:
...
const svgLogoData = `<svg xmlns="http://www.w3.org/2000/svg" width="400" height="89.474"><g fill-rule="evenodd"><path fill...</svg>`;
...
const PriceListPdf = (props: PriceListPDFProps) => {
...
useEffect(() => {
console.log({priceListToExport});
if (priceListToExport) {
displayPDF();
}
}, [priceListToExport]);
const displayPDF = () => {
const doc = new jsPDF(
{
orientation: 'p',
unit: 'in',
format: 'letter',
putOnlyUsedFonts: true,
floatPrecision: 16 // or "smart", default is 16
});
const left = doc.internal.pageSize.width / 2;
// const top = doc.internal.pageSize.height / 2;
const imgWidth = 4;
const imgLeft = left - (imgWidth / 2);
const parser = new DOMParser();
const svgElement = parser.parseFromString(svgLogoData, "image/svg+xml");
console.log({svgElement});
doc.svg(svgElement, {x: imgLeft, y: 0.1, width: imgWidth, height: .889}).then(() => {
doc.setDisplayMode('fullheight');
const objectURL = doc.output('datauristring');
setPDFSrc(objectURL)
});
};
...
Also tried this:
import logo from '../../assets/logo.svg';
...
const svgElement2 = <img src={logo} alt="Logo"/>;
doc.svg(svgElement2, {x: imgLeft, y: 0.1, width: imgWidth, height: .889}).then(() => {
doc.setDisplayMode('fullheight');
const objectURL = doc.output('datauristring');
setPDFSrc(objectURL)
});
That second method throws this in the console: Uncaught (in promise) TypeError: this.rootSvg.querySelectorAll is not a function
from svg2pdf.js.
Related Issues (20)
- Accept spaces in data urls in image urls
- adding support for the CMYK color space HOT 5
- greek letters in text HOT 1
- tspan dx makes incorrect offset HOT 1
- Incorrect Gradient rendering in svg2pdf HOT 1
- Empty path def crashes jspdf HOT 1
- Chinese garbled characters HOT 1
- RadialGradient is not shown correctly HOT 1
- Implement preserveAspectRatio for <image> tags HOT 5
- Embed images with SVG HOT 5
- Support for letter-spacing Attribute in <text> Element HOT 4
- marker-start not rotating HOT 1
- Pattern is not applied correctly
- Gradient filled rectangles, why is the border thinner HOT 2
- Textpath does not show in PDF HOT 1
- `svgTextMeasure` doesn't consider font-family HOT 2
- Font is not preserved in output HOT 1
- Support fill-rule="evenodd" on group elements HOT 2
- Generation in a Node backend HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from svg2pdf.js.