Неверное изображение, словарь изображений должен содержать записи dataURL (pdfMake) - PullRequest
0 голосов
/ 07 мая 2019

Я преобразую изображение .svg в base64 с помощью API "svg-to-dataurl", но когда я помещаю его в код, оно не работает.

Мой код:

const chartSvg = STRINGSVG
const svgToDataURL = require('svg-to-dataurl')
const chartHex = svgToDataURL(chartSvg)

var docDefinition = {
   content: [
      {
         image: chartHex,
         width: 595
      }
   ]
}

Ошибка: (узел: 8200) UnhandledPromiseRejectionWarning: неверное изображение, словарь изображений должен содержать записи dataURL (или локальные пути к файлам в файле node.js)

Генерируемые данныеURL:

data:image/svg+xml,<svg%20xmlns%3D"http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg"%20width%3D"500"%20height%3D"300"%20transform%3D"translate(20%2C20)"><g><g%20transform%3D"translate(41%2C0)"><rect%20x%3D"2"%20y%3D"226"%20width%3D"15"%20height%3D"54"%20fill%3D"%2398abc5"%2F><rect%20x%3D"18"%20y%3D"64"%20width%3D"15"%20height%3D"216"%20fill%3D"%238a89a6"%2F><rect%20x%3D"34"%20width%3D"15"%20height%3D"NaN"%20fill%3D"%237b6888"%2F><rect%20x%3D"50"%20width%3D"15"%20height%3D"NaN"%20fill%3D"%236b486b"%2F><%2Fg><g%20transform%3D"translate(117%2C0)"><rect%20x%3D"2"%20width%3D"15"%20height%3D"NaN"%20fill%3D"%2398abc5"%2F><rect%20x%3D"18"%20width%3D"15"%20height%3D"NaN"%20fill%3D"%238a89a6"%2F><rect%20x%3D"34"%20y%3D"10"%20width%3D"15"%20height%3D"270"%20fill%3D"%237b6888"%2F><rect%20x%3D"50"%20y%3D"226"%20width%3D"15"%20height%3D"54"%20fill%3D"%236b486b"%2F><%2Fg><g%20transform%3D"translate(193%2C0)"><rect%20x%3D"2"%20width%3D"15"%20height%3D"NaN"%20fill%3D"%2398abc5"%2F><rect%20x%3D"18"%20width%3D"15"%20height%3D"NaN"%20fill%3D"%238a89a6"%2F><rect%20x%3D"34"%20width%3D"15"%20height%3D"NaN"%20fill%3D"%237b6888"%2F><rect%20x%3D"50"%20y%3D"226"%20width%3D"15"%20height%3D"54"%20fill%3D"%236b486b"%2F><%2Fg><g%20transform%3D"translate(269%2C0)"><rect%20x%3D"2"%20y%3D"172"%20width%3D"15"%20height%3D"108"%20fill%3D"%2398abc5"%2F><rect%20x%3D"18"%20y%3D"118"%20width%3D"15"%20height%3D"162"%20fill%3D"%238a89a6"%2F><rect%20x%3D"34"%20width%3D"15"%20height%3D"NaN"%20fill%3D"%237b6888"%2F><rect%20x%3D"50"%20width%3D"15"%20height%3D"NaN"%20fill%3D"%236b486b"%2F><%2Fg><g%20transform%3D"translate(345%2C0)"><rect%20x%3D"2"%20width%3D"15"%20height%3D"NaN"%20fill%3D"%2398abc5"%2F><rect%20x%3D"18"%20width%3D"15"%20height%3D"NaN"%20fill%3D"%238a89a6"%2F><rect%20x%3D"34"%20width%3D"15"%20height%3D"NaN"%20fill%3D"%237b6888"%2F><rect%20x%3D"50"%20y%3D"226"%20width%3D"15"%20height%3D"54"%20fill%3D"%236b486b"%2F><%2Fg><g%20transform%3D"translate(421%2C0)"><rect%20x%3D"2"%20width%3D"15"%20height%3D"NaN"%20fill%3D"%2398abc5"%2F><rect%20x%3D"18"%20width%3D"15"%20height%3D"NaN"%20fill%3D"%238a89a6"%2F><rect%20x%3D"34"%20y%3D"118"%20width%3D"15"%20height%3D"162"%20fill%3D"%237b6888"%2F><rect%20x%3D"50"%20width%3D"15"%20height%3D"NaN"%20fill%3D"%236b486b"%2F><%2Fg><%2Fg><g%20transform%3D"translate(0%2C280)"%20fill%3D"none"%20font-size%3D"10"%20font-family%3D"sans-serif"%20text-anchor%3D"middle"><g%20class%3D"tick"%20opacity%3D"1"%20transform%3D"translate(75.5%2C0)"><line%20stroke%3D"currentColor"%20y2%3D"6"%2F><text%20fill%3D"currentColor"%20y%3D"9"%20dy%3D"0.71em">a<%2Ftext><%2Fg><g%20class%3D"tick"%20opacity%3D"1"%20transform%3D"translate(151.5%2C0)"><line%20stroke%3D"currentColor"%20y2%3D"6"%2F><text%20fill%3D"currentColor"%20y%3D"9"%20dy%3D"0.71em">b<%2Ftext><%2Fg><g%20class%3D"tick"%20opacity%3D"1"%20transform%3D"translate(227.5%2C0)"><line%20stroke%3D"currentColor"%20y2%3D"6"%2F><text%20fill%3D"currentColor"%20y%3D"9"%20dy%3D"0.71em">c<%2Ftext><%2Fg><g%20class%3D"tick"%20opacity%3D"1"%20transform%3D"translate(303.5%2C0)"><line%20stroke%3D"currentColor"%20y2%3D"6"%2F><text%20fill%3D"currentColor"%20y%3D"9"%20dy%3D"0.71em">d<%2Ftext><%2Fg><g%20class%3D"tick"%20opacity%3D"1"%20transform%3D"translate(379.5%2C0)"><line%20stroke%3D"currentColor"%20y2%3D"6"%2F><text%20fill%3D"currentColor"%20y%3D"9"%20dy%3D"0.71em">e<%2Ftext><%2Fg><g%20class%3D"tick"%20opacity%3D"1"%20transform%3D"translate(455.5%2C0)"><line%20stroke%3D"currentColor"%20y2%3D"6"%2F><text%20fill%3D"currentColor"%20y%3D"9"%20dy%3D"0.71em">f<%2Ftext><%2Fg><%2Fg><g%20transform%3D"translate(40%2C0)"%20fill%3D"none"%20font-size%3D"10"%20font-family%3D"sans-serif"%20text-anchor%3D"end"><g%20class%3D"tick"%20opacity%3D"1"%20transform%3D"translate(0%2C280.5)"><line%20stroke%3D"currentColor"%20x2%3D"-6"%2F><text%20fill%3D"currentColor"%20x%3D"-9"%20dy%3D"0.32em">0.0<%2Ftext><%2Fg><g%20class%3D"tick"%20opacity%3D"1"%20transform%3D"translate(0%2C253.5)"><line%20stroke%3D"currentColor"%20x2%3D"-6"%2F><text%20fill%3D"currentColor"%20x%3D"-9"%20dy%3D"0.32em">0.5<%2Ftext><%2Fg><g%20class%3D"tick"%20opacity%3D"1"%20transform%3D"translate(0%2C226.5)"><line%20stroke%3D"currentColor"%20x2%3D"-6"%2F><text%20fill%3D"currentColor"%20x%3D"-9"%20dy%3D"0.32em">1.0<%2Ftext><%2Fg><g%20class%3D"tick"%20opacity%3D"1"%20transform%3D"translate(0%2C199.5)"><line%20stroke%3D"currentColor"%20x2%3D"-6"%2F><text%20fill%3D"currentColor"%20x%3D"-9"%20dy%3D"0.32em">1.5<%2Ftext><%2Fg><g%20class%3D"tick"%20opacity%3D"1"%20transform%3D"translate(0%2C172.5)"><line%20stroke%3D"currentColor"%20x2%3D"-6"%2F><text%20fill%3D"currentColor"%20x%3D"-9"%20dy%3D"0.32em">2.0<%2Ftext><%2Fg><g%20class%3D"tick"%20opacity%3D"1"%20transform%3D"translate(0%2C145.5)"><line%20stroke%3D"currentColor"%20x2%3D"-6"%2F><text%20fill%3D"currentColor"%20x%3D"-9"%20dy%3D"0.32em">2.5<%2Ftext><%2Fg><g%20class%3D"tick"%20opacity%3D"1"%20transform%3D"translate(0%2C118.5)"><line%20stroke%3D"currentColor"%20x2%3D"-6"%2F><text%20fill%3D"currentColor"%20x%3D"-9"%20dy%3D"0.32em">3.0<%2Ftext><%2Fg><g%20class%3D"tick"%20opacity%3D"1"%20transform%3D"translate(0%2C91.5)"><line%20stroke%3D"currentColor"%20x2%3D"-6"%2F><text%20fill%3D"currentColor"%20x%3D"-9"%20dy%3D"0.32em">3.5<%2Ftext><%2Fg><g%20class%3D"tick"%20opacity%3D"1"%20transform%3D"translate(0%2C64.5)"><line%20stroke%3D"currentColor"%20x2%3D"-6"%2F><text%20fill%3D"currentColor"%20x%3D"-9"%20dy%3D"0.32em">4.0<%2Ftext><%2Fg><g%20class%3D"tick"%20opacity%3D"1"%20transform%3D"translate(0%2C37.5)"><line%20stroke%3D"currentColor"%20x2%3D"-6"%2F><text%20fill%3D"currentColor"%20x%3D"-9"%20dy%3D"0.32em">4.5<%2Ftext><%2Fg><g%20class%3D"tick"%20opacity%3D"1"%20transform%3D"translate(0%2C10.5)"><line%20stroke%3D"currentColor"%20x2%3D"-6"%2F><text%20fill%3D"currentColor"%20x%3D"-9"%20dy%3D"0.32em">5.0<%2Ftext><text%20fill%3D"currentColor"%20x%3D"3"%20dy%3D"0.32em"%20text-anchor%3D"start"%20font-weight%3D"bold"%2F><%2Fg><%2Fg><g%20transform%3D"translate(500%2C0)"%20text-anchor%3D"end"%20font-family%3D"sans-serif"%20font-size%3D"10"><g%20transform%3D"translate(0%2C0)"><rect%20x%3D"19"%20width%3D"19"%20height%3D"19"%20fill%3D"%236b486b"%2F><text%20x%3D"0"%20y%3D"9.5"%20dy%3D"0.35em">paul<%2Ftext><%2Fg><g%20transform%3D"translate(0%2C20)"><rect%20x%3D"19"%20width%3D"19"%20height%3D"19"%20fill%3D"%237b6888"%2F><text%20x%3D"0"%20y%3D"9.5"%20dy%3D"0.35em">mary<%2Ftext><%2Fg><g%20transform%3D"translate(0%2C40)"><rect%20x%3D"19"%20width%3D"19"%20height%3D"19"%20fill%3D"%238a89a6"%2F><text%20x%3D"0"%20y%3D"9.5"%20dy%3D"0.35em">carl<%2Ftext><%2Fg><g%20transform%3D"translate(0%2C60)"><rect%20x%3D"19"%20width%3D"19"%20height%3D"19"%20fill%3D"%2398abc5"%2F><text%20x%3D"0"%20y%3D"9.5"%20dy%3D"0.35em">john<%2Ftext><%2Fg><%2Fg><%2Fsvg>
...