在Amcharts v4 pdf导出中包含图像

问题描述 投票:0回答:1

我想在我的Amcharts pdf导出中添加徽标和其他图像。版本:Ubuntu 16.04上的Php 7,Amcharts 4。

我跟着https://www.amcharts.com/docs/v4/tutorials/generating-multi-content-pdf-export/

我有标题,文本图表和表格。该示例不包括图像,但我在这里查看了PDFmake:https://pdfmake.github.io/docs/document-definition-object/images/

在amCharts表等中使用块,如:

doc.content.push({
  table: {

在PDFMake语法是:

var docDefinition = {
content: [
    {
      layout: 'lightHorizontalLines', // optional
      table: {

和图像:

var dd = {
    content: [
        'pdfmake (since it\'s based on pdfkit) supports JPEG and PNG format',
        'If no width/height/fit is provided, image original size will be used',
        {
            image: 'sampleImage.jpg',
        },

所以我尝试过:

doc.content.push({
      image: 'sampleImage.jpg',
    }); 

并将名为sampleImage.jpg的图像放在服务器上与php文件相同的文件夹中

我希望将图像添加到我的report.pdf下载中,但它不起作用。任何想法都赞赏。具体来说,什么是正确的语法,我应该在哪里放置图像?我想避免将图像转换为:data:image / jpeg格式的麻烦。

image pdf amcharts amcharts4
1个回答
1
投票

回答我自己的问题:

所以看起来你必须使用“data:image / jpeg; base64”格式将图像包含在脚本中。我用“https://www.base64-image.de/”转换了我的图像。结果是一段代码,如:

data:image/jpeg;base64,/9j/4A... lots of data ... QhCABCEIA//2Q==

你将它复制到一个js变量,如下所示:

smiley = 'data:image/jpeg;base64,/9j/4A... lots of data ... QhCABCEIA//2Q==';

然后输出:

    doc.content.push({
      image: smiley,
      width: 30
    });

把图像放到桌子上我做了:

doc.content.push({
  table: {
    headerRows: 1,
    widths: [ "*", "*", "*", "*","*", "*", "*","*", "*", "*" ],
    body: [
      [
        {image: low, width: 30,  colSpan: 3, alignment: 'center'},{ },{ },
        {image: ok, width: 30,  colSpan: 4, alignment: 'center'},{ },{ },{ },
        {image: high, width: 30,  colSpan: 3, alignment: 'center'},{ },{ }

      ],
      [ 
        {text: "<?php echo $final_score_show[1]; ?>",  alignment: 'center'}, 
        ...
      ]
    ]
  }
});

希望这有助于某人。请享用 !

© www.soinside.com 2019 - 2024. All rights reserved.