PaperJs fails to import SVG xml data

38 Views Asked by At

I tried to import SVG in PaperJs project but it fails with the error below. I used nodejs, domparser from xmldom library. The codes is deloyed in a Azure Function with linux runtime.

Is someone already had this issue ?

Code:

paper.setup(new paper.Size(1200, 1200));
                    const item = paper.project.importSVG(svg);
                    item.children.forEach(child => {  
                        if (child instanceof paper.Path) {  
                            child.simplify(10);  
                        }  
                    });

                    const simplifiedSvgString = item.exportSVG({ asString: true });
var svgBuffer = Buffer.from(simplifiedSvgString, 'utf8');

Then buffer is uloapled in a blob storage as 'image/svg+xml'

I finally switch the library by paper-domxml and conversion now happen. However file exported is not yet readable but path is correct, I had been able to read it in a standalone SVG path webui interface.

The result looks like this:

<svg>
<defs>
<clipPath id="clip-1">
<rect x="0" y="0" width="1200" height="1200" fill="none" fill-rule="nonzero"/>
</clipPath>
</defs>
<g clip-path="url(#clip-1)" fill="none" fill-rule="none" stroke="none" stroke-width="1" stroke-linecap="butt" stroke-linejoin="miter" stroke-miterlimit="10" stroke-dasharray="" stroke-dashoffset="0" font-family="none" font-weight="none" font-size="none" text-anchor="none" style="mix-blend-mode: normal">
<path d="M481,404v11h9.5h9.5v-11v-11h-9.5h-9.5v11M750,413.468v20.469l-11.75,0.281l-11.75,0.282l-0.292,7.75l-0.292,7.75h12.042h12.042v49.5c0,32.333 0.347,49.5 1,49.5c0.658,0 1,25.333 1,74v74h8.5h8.5v-80c0,-52.667 -0.342,-80 -1,-80c-0.651,0 -1,-15.167 -1,-43.5v-43.5h13h13v-8v-8h-13h-13v-20.5v-20.5h-8.5h-8.5v20.468M353,434.596c-5.568,2.006 -16.289,9.524 -19.204,13.466c-1.195,1.616 -2.537,2.938 -2.984,2.938c-0.447,0 -0.812,-3.825 -0.812,-8.5v-8.5h-8.5h-8.5v57.5v57.5h8.5h8.5l0.02,-32.25c0.011,-17.738 0.468,-35.353 1.016,-39.145c2.223,-15.38 12.326,-25.769 27.787,-28.573c14.401,-2.611 28.089,3.938 34.418,16.468c3.207,6.348 3.759,13.477 3.759,48.549v34.951h8.5h8.5v-37.79c0,-30.271 -0.297,-38.929 -1.492,-43.517c-3.555,-13.648 -12.134,-24.422 -24.194,-30.383c-7.167,-3.541 -8.025,-3.722 -19.158,-4.021c-8.859,-0.239 -12.736,0.075 -16.156,1.307M482,514v80h8.5h8.5v-80v-80h-8.5h-8.5v80M567.017,470.211c0.014,28.161 0.349,37.853 1.497,43.272c4.158,19.628 18.082,33.445 36.9,36.615c17.125,2.884 30.624,-1.893 42.321,-14.979l3.235,-3.619l0.015,8.75l0.015,8.75h8.5h8.5v-57.5v-57.5h-8.445h-8.445l-0.305,37.774l-0.305,37.774l-3.271,6.641c-3.746,7.607 -8.27,11.998 -16.183,15.71c-4.687,2.198 -6.941,2.601 -14.546,2.601c-7.825,0 -9.742,-0.364 -14.682,-2.79c-6.437,-3.161 -11.134,-8.006 -14.212,-14.659c-1.996,-4.314 -2.132,-6.581 -2.606,-43.551l-0.5,-39l-8.75,-0.289l-8.75,-0.289l0.017,36.289M119,552v11h9.5h9.5v-11v-11h-9.5h-9.5v11M239.112,582.581c-18.424,4.954 -34.063,21.384 -38.575,40.522c-1.999,8.484 -1.962,24.543 0.078,32.833c3.915,15.916 14.754,29.621 29.109,36.806c10.023,5.017 19.345,6.75 31.88,5.928c20.186,-1.324 35.342,-10.968 44.463,-28.292l3.095,-5.878l-9.331,-0.297c-8.762,-0.279 -9.422,-0.158 -10.831,1.977c-7.999,12.122 -19.119,17.479 -34.409,16.577c-4.94,-0.292 -10.36,-1.35 -13.919,-2.718c-10.804,-4.154 -21.417,-17.336 -23.265,-28.898l-0.659,-4.121l47.876,-0.26l47.876,-0.26l-0.31,-9c-0.6,-17.454 -5.466,-29.729 -16.045,-40.48c-7.195,-7.312 -15.276,-12.038 -24.848,-14.531c-7.276,-1.895 -24.985,-1.845 -32.185,0.092M617.5,582.887c-28.818,8.377 -44.964,38.667 -38.036,71.359c4.568,21.554 21.699,38.77 43.036,43.25c20.613,4.327 40.022,-0.753 52.989,-13.869c4.96,-5.019 12.511,-16.495 12.511,-19.017c0,-0.335 -4.263,-0.61 -9.474,-0.61c-9.421,0 -9.483,0.016 -10.959,2.87c-0.816,1.578 -3.796,4.949 -6.622,7.49c-14.975,13.463 -43.134,10.815 -55.86,-5.253c-3.705,-4.678 -7.681,-13.138 -8.628,-18.357l-0.68,-3.75h48.112h48.111l-0.035,-6.25c-0.101,-18.154 -5.834,-32.866 -17.223,-44.198c-7.596,-7.557 -14.406,-11.58 -23.873,-14.099c-7.586,-2.019 -25.743,-1.783 -33.369,0.434M881.892,583.354c-3.084,1.269 -7.182,3.28 -9.106,4.469c-5.014,3.099 -12.582,11.506 -14.804,16.445l-1.903,4.232l-0.29,-13l-0.289,-13h-8.5h-8.5l-0.258,57.25l-0.258,57.25h9.008h9.008v-28.951c0,-17.567 0.441,-31.034 1.121,-34.25c2.576,-12.175 10.708,-24.476 20.129,-30.448c4.205,-2.664 13.472,-5.351 18.46,-5.351h3.29v-8.5v-8.5l-5.75,0.024c-3.671,0.015 -7.778,0.858 -11.358,2.33M119.667,582.667c-0.367,0.366 -0.667,36.366 -0.667,80v79.333h9h9v-80v-80h-8.333c-4.584,0 -8.634,0.3 -9,0.667M360.542,584.25c0.319,1.237 8.361,27 17.872,57.25l17.293,55l10.096,0.284l10.095,0.285l2.093,-6.785c9.257,-30.012 25.379,-81.027 25.934,-82.062c0.377,-0.702 6.996,18.873 14.709,43.5l14.023,44.778l10.082,0.284l10.083,0.284l1.046,-3.284c13.008,-40.877 34.132,-109.113 34.132,-110.258c0,-1.253 -1.587,-1.526 -8.883,-1.526c-7.611,0 -8.953,0.251 -9.365,1.75c-3.944,14.342 -26.187,88.952 -26.685,89.506c-0.549,0.611 -10.395,-30 -27.353,-85.041l-1.937,-6.285l-9.507,0.285l-9.508,0.285l-13.981,45c-7.69,24.75 -14.281,45.322 -14.648,45.717c-0.366,0.394 -6.452,-18.956 -13.523,-43c-7.072,-24.045 -13.241,-44.73 -13.709,-45.967c-0.797,-2.105 -1.435,-2.25 -9.895,-2.25c-8.884,0 -9.034,0.04 -8.464,2.25M986,585.922c-7.107,1.404 -8.146,2.866 -23.913,33.638c-8.298,16.195 -15.087,30.321 -15.087,31.392c0,1.072 0.718,2.351 1.596,2.842c1.413,0.791 1.282,1.513 -1.144,6.3c-11.77,23.22 -13.233,35.979 -5.389,46.995c3.714,5.215 9.275,7.385 18.958,7.399c7.654,0.011 9.212,-0.328 15.311,-3.331c12.418,-6.113 26.87,-22.997 43.361,-50.655c3.727,-6.251 6.898,-11.244 7.046,-11.096c0.149,0.148 -2.464,8.532 -5.806,18.632c-7.357,22.235 -16.646,45.973 -21.703,55.462l-3.73,7l-27.504,7.055c-41.627,10.679 -59.656,16.881 -74.407,25.597c-18.365,10.852 -30.589,29.767 -30.589,47.334c0,5.014 0.516,6.936 2.851,10.619c6.164,9.718 19.52,14.583 37.149,13.531c39.656,-2.367 72.72,-30.504 108.44,-92.283l4.71,-8.147l7.675,-2.692c13.09,-4.592 29.47,-13.058 37.293,-19.274c13.823,-10.985 26.039,-27.787 39.007,-53.654c7.252,-14.463 8.314,-19.086 4.385,-19.086c-1.499,0 -3.303,2.467 -7.314,10c-20.891,39.239 -31.834,52.325 -52.931,63.302c-8.33,4.333 -21.265,9.603 -21.265,8.663c0,-1.592 27.259,-79.548 32.642,-93.349c8.591,-22.027 12.572,-29.335 20.085,-36.866l6.236,-6.25l-10.232,0.024c-12.062,0.029 -18.349,1.278 -21.585,4.287c-1.295,1.204 -5.064,7.589 -8.376,14.189c-22.844,45.518 -45.173,80.204 -61.617,95.717c-5.033,4.748 -8.124,6.875 -10.693,7.356c-11.599,2.176 -15.455,-11.083 -8.601,-29.573c3.533,-9.529 26.088,-55.762 34.628,-70.976c4.133,-7.365 7.156,-11.33 11.786,-15.46l6.227,-5.555l-12,0.11c-6.6,0.061 -13.575,0.422 -15.5,0.803M246.166,597.489c-3.484,0.781 -8.235,2.534 -10.558,3.895c-8.372,4.906 -16.114,15.759 -18.096,25.366l-0.671,3.25h38.705h38.704l-0.632,-3.25c-2.139,-10.995 -12.749,-23.785 -22.876,-27.574c-7.361,-2.754 -16.897,-3.409 -24.576,-1.687M627.12,597.093c-7.004,1.208 -16.23,6.18 -20.75,11.183c-3.566,3.947 -8.595,13.697 -9.787,18.974l-0.621,2.75h38.519c37.783,0 38.519,-0.038 38.519,-1.989c0,-3.435 -3.64,-11.752 -7.362,-16.824c-8.186,-11.151 -23.367,-16.706 -38.518,-14.094M978.5,745.643c-66.846,17.732 -83.703,25.095 -96.431,42.117c-6.914,9.247 -9.483,15.737 -9.529,24.07c-0.038,7.003 0.102,7.457 3.157,10.188c9.762,8.73 28.585,5.858 48.578,-7.413c11.145,-7.397 34.778,-30.959 49.135,-48.987c6.881,-8.641 15.223,-21.37 14.448,-22.049c-0.197,-0.172 -4.408,0.761 -9.358,2.074" fill="#000000" fill-rule="evenodd"/>
</g>
</svg>
0

There are 0 best solutions below