yWorks / svg2pdf.js

A javascript-only SVG to PDF conversion utility that runs in the browser. Brought to you by yWorks - the diagramming experts
MIT License
667 stars 104 forks source link

saveGraphicsState is not set #39

Closed shaoran closed 6 years ago

shaoran commented 6 years ago

I'm not sure if this a svg2pdf.js or a jsPDF issue.

For an application I need to export a Highcharts chart as PDF using exportChartLocal. When I call this method, this method eventually fails.

I managed to pin point the location where the error occurs:

in svg2pdf.js:

` // the actual svgToPdf function (see above) var svg2pdf = function (element, pdf, options) { _pdf = pdf;

var k = options.scale || 1.0, 
    xOffset = options.xOffset || 0.0, 
    yOffset = options.yOffset || 0.0; 

// set offsets and scale everything by k
_pdf.saveGraphicsState();
_pdf.setCurrentTransformationMatrix(new _pdf.Matrix(k, 0, 0, k, xOffset, yOffset));
...
_pdf.restoreGraphicsState();

return _pdf;

} `

The problem here is that the functions saveGraphicsState, setCurrentTransformationMatrix and restoreGraphicsState are undefined. The method which creates the pdf object in Highcharts looks like this:

pdf = new win.jsPDF( // eslint-disable-line new-cap
    'l',
    'pt', [width, height]
);
...
win.svg2pdf(svgElement, pdf,
        removeInvalid: true
});

I've looked in the jsPDF code, but there is no single place where any of this functions are defined in the source code.

The question is: is this an svg2pdf.js or an jsPDF issue? And could it be that the versions I'm running right now are not compatible with each other?

I installed them using bower (1.8.2) and these are the versions:

$ bower info jsPDF
bower jsPDF#*                   cached https://github.com/MrRio/jsPDF.git#1.3.5
bower jsPDF#*                 validate 1.3.5 against https://github.com/MrRio/jsPDF.git#*

$ bower info svg2pdf.js
bower svg2pdf.js#*              cached https://github.com/yWorks/svg2pdf.js.git#1.1.2
bower svg2pdf.js#*            validate 1.1.2 against https://github.com/yWorks/svg2pdf.js.git#*

Should I install different versions of these packages?

yGuy commented 6 years ago

To quote the README:

Dependencies jsPDF (yWorks fork version!) fontello/svgpath

HackbrettXXX commented 6 years ago

You are using the wrong jsPDF version. svg2pdf.js only works with the yWorks fork fork.

shaoran commented 6 years ago

Oh, I didn't realize that. Too bad that the Highcharts documentation doesn't point out this crucial fact. I've spent a lot of time trying to make them work together. I'll try yWorks fork now.

Thanks for the replies.