使用 pdfmake 在 angularjs 中生成 pdf 时图像未显示

Shu*_*vro 3 javascript pdf angularjs pdfmake

我正在使用pdfmake,这是一个很好的 pdf javascript 打印库,用于在我的 angularjs SPA 中生成 pdf。当我只使用文本时,一切正常。pdf 正确显示所有文本到位。但是当我尝试显示图像时它对我不起作用。没有错误,没有空的pdf,只是没有任何反应。也没有 404。

这是我现在正在尝试的代码,

var dd = {
        content: [
            {
                image: 'picture13438908025659.jpg'
            },
            {
                text: 'Patient\'s Detail', fontSize: 18, bold: true
            },
            {
                columns: [
                    {
                        text: 'Patient\'s ID: ' + $scope.prescription.Patient[0].id, bold: false
                    },
                    {
                        text: 'Name: ' + $scope.prescription.Patient[0].name, bold: false
                    },
                    {
                        text: 'Age: ' + $scope.prescription.Patient[0].age, bold: false
                    },
                    {
                        text: 'Contact: ' + $scope.prescription.Patient[0].contact, bold: false
                    }
                ]

            },
            {
                text: 'Address: ' + $scope.prescription.Patient[0].address, bold: false
            }
        ]
    }
Run Code Online (Sandbox Code Playgroud)

Moh*_*med 5

这很简单,

1)在此处将您的图像转换为 base64

2)复制您的base64代码并替换为,

image : 'base64', // use your base64 instead image.jpg
Run Code Online (Sandbox Code Playgroud)

3)完成。这种方法是,如果您的图像不是通过链接工作的,则表示使用 base64 代替