Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add export to PDF. #146

Open
samussiah opened this issue May 16, 2019 · 1 comment
Open

Add export to PDF. #146

samussiah opened this issue May 16, 2019 · 1 comment

Comments

@samussiah
Copy link
Contributor

samussiah commented May 16, 2019

As an alternative to taking screenshots.

This thread explains how to export to .svg. Probably need another library to export to .pdf. Function:

function saveSvg(svgEl, name) {
    svgEl.setAttribute("xmlns", "http://www.w3.org/2000/svg");
    var svgData = svgEl.outerHTML.replace('xlink:xlink', 'xmlns:xlink');
    var preface = '<?xml version="1.0" standalone="no"?>\r\n';
    var svgBlob = new Blob([preface, svgData], {type:"image/svg+xml;charset=utf-8"});
    var svgUrl = URL.createObjectURL(svgBlob);
    var downloadLink = document.createElement("a");
    downloadLink.href = svgUrl;
    downloadLink.download = name;
    document.body.appendChild(downloadLink);
    downloadLink.click();
    document.body.removeChild(downloadLink);
}

Note one little change: .replace('xlink:xlink', 'xmlns:xlink'). Looks like the xlink namespace is deprecated, which would be a Webcharts update.

@samussiah
Copy link
Contributor Author

PDFKit should do the trick.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant