gpt4 book ai didi

pdfmake - 如何将图像与 pdfmake 对齐?

转载 作者:行者123 更新时间:2023-12-04 22:58:18 25 4
gpt4 key购买 nike

我正在使用 pdfmake 创建 PDF 并成功使用数据 URI 嵌入图像。这是一个小图像,大约 200 像素宽,我想让它右对齐。有没有办法将图像推送到 PDF 的右侧?

最佳答案

您可以使用文档定义中的预定义样式右对齐图像。 pdfmake playground 有一个很好的图像示例,我对其进行了编辑以添加下面的“右对齐”样式(称为“rightme”)。我尝试直接在文档定义中添加 'alignment: right',但这不起作用。
由于长度问题,我删除了图像数据 - 访问 pdfmake playground图像以查看此工作:

  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',
},
'If you specify width, image will scale proportionally',
{
image: 'sampleImage.jpg',
width: 150
},
'If you specify both width and height - image will be stretched',
{
image: 'sampleImage.jpg',
width: 150,
height: 150,
},
'You can also fit the image inside a rectangle',
{
image: 'sampleImage.jpg',
fit: [100, 100],
pageBreak: 'after'
},

// Warning! Make sure to copy this definition and paste it to an
// external text editor, as the online AceEditor has some troubles
// with long dataUrl lines and the following image values look like
// they're empty.
'Images can be also provided in dataURL format...',
{
image: **'IMAGE TRUNCATED FOR BREVITY'**,
width: 200,
style: 'rightme'
},
'or be declared in an "images" dictionary and referenced by name',
{
image: 'building',
width: 200
},
],
images: {
building: **'IMAGE DATA TRUNCATED FOR BREVITY'**
},
styles:{
rightme:
{
alignment: 'right'
}

}

}

关于pdfmake - 如何将图像与 pdfmake 对齐?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34936514/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com