Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/388.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jsPDF SVG无效的base64字符串_Javascript_Reactjs_Svg_Base64_Jspdf - Fatal编程技术网

Javascript jsPDF SVG无效的base64字符串

Javascript jsPDF SVG无效的base64字符串,javascript,reactjs,svg,base64,jspdf,Javascript,Reactjs,Svg,Base64,Jspdf,我正在尝试将SVG添加到PDF文档中。我正在使用jsPDF库。SVG从网页上呈现的D3图表中检索。我使用window.btoa()函数将SVG转换为base64字符串。为了使它成为一个有效的图像,我添加了数据:image/svg+xml;base64,到字符串的开头 const unit = "pt"; const size = "A4"; // Use A1, A2, A3 or A4 const orientation = "landscape"; // portrait or landsc

我正在尝试将SVG添加到PDF文档中。我正在使用jsPDF库。SVG从网页上呈现的D3图表中检索。我使用
window.btoa()
函数将SVG转换为base64字符串。为了使它成为一个有效的图像,我添加了
数据:image/svg+xml;base64,
到字符串的开头

const unit = "pt";
const size = "A4"; // Use A1, A2, A3 or A4
const orientation = "landscape"; // portrait or landscape

...

const doc = new jsPDF(orientation, unit, size);
var svg = document.getElementById("svg");
var s = new XMLSerializer().serializeToString(svg);
var img = "data:image/svg+xml;" + window.btoa(s);
doc.addImage(img, 0, 0, 100);
这将导致一个错误:

Uncaught Error: Supplied Data is not a valid base64-String
我尝试过通过一个有效的
来简单地显示内容。我还尝试使用外部工具将SVG转换为base64,并使用特定字符串。这会导致相同的错误


我知道也有类似的问题,但似乎没有任何问题与拒绝base64字符串有关。

jsPDF中可能存在错误。检查此addImage函数文件,该文件具有验证功能。jsPDF中可能有一个bug。检查此addImage函数文件,该文件具有验证功能。