JSPDF自动图像灰色并在多个图像
当我使用JSPDF自动化时,可以在PDF上创建一个表格,其中一些图像呈灰色并被洗净。看来有些图像出现了,其中一些图像在自己身上重叠。
我正在使用存储在Firebase存储中的文件。我下载它们,然后将它们变成Base64文件,然后尝试将它们添加到我的PDF中。第一个加上罚款,然后其中一些总是最终被洗净。请感谢任何帮助!
componentDidMount() {
window.scrollTo(0, 0)
function toDataURL(url, callback) {
var xhr = new XMLHttpRequest();
xhr.onload = function () {
var reader = new FileReader();
reader.onloadend = function () {
callback(reader.result);
}
reader.readAsDataURL(xhr.response);
};
xhr.open('GET', url);
xhr.responseType = 'blob';
xhr.send();
}
const { item } = this.state;
console.log(item.files)
const images = []
item.files.map((l) => { images.push({ key: l.key, type: 'photo', url: l.fileLink, b64: '' }) });
item.lineItems.map((l) => { images.push({ key: l.key, type: 'photo', url: l.imageThumb.fileLink, b64: '' }) });
images.map(async (l, i) => {
const url = l.url;
toDataURL(url, (dataUrl) => {
l.b64 = dataUrl;
})
if (i + 1 === images.length) {
this.setState({ creating: false })
}
})
this.setState({ images })
}
createPDF = async () => {
d.autoTable({
startY: 3.9, margin: 1, pageBreak: 'auto', showHead: false,
body: images.map((l, i) => {
const index = i + 1;
const even = index % 2 == 0;
const color = even === true ? [200, 200, 200] : [255, 255, 255];
const title = [{ content: `${l.url}`, meta: { key: l.key, img: l.b64 } }]
return ([...title])
})
,
columns: [
{ header: 'Test', },
{ header: 'Test', },
],
didDrawCell: async (data) => {
if (data.cell.raw !== undefined) {
console.log(data);
if (data.section === 'body') {
console.log("ADD IMAGE")
data.row.height = 2
const ww = d.getImageProperties(data.cell.raw.meta.img).width;
const wh = d.getImageProperties(data.cell.raw.meta.img).height;
const ratio = ww / wh;
d.addImage(data.cell.raw.meta.img, 'PNG', data.cell.x + .2, data.cell.y, 1.75 * ratio, 1.75, `${data.cell.raw.meta.key}`, 'FAST');
}
}
},
});
}
这是我遇到的一些错误。在我的控制台。
When I use jSPDF-Autotable to create a table on my PDF some of the images come out gray and washed out. It looks like some of the images are coming out fine and some of them are overlapping on themselves.
I am using files that are stored in firebase storage. I download them and then turn them into base64 files and try to add them to my PDF. The first ones add fine and then some of them always end up washed out. Please any help is appreciated!
componentDidMount() {
window.scrollTo(0, 0)
function toDataURL(url, callback) {
var xhr = new XMLHttpRequest();
xhr.onload = function () {
var reader = new FileReader();
reader.onloadend = function () {
callback(reader.result);
}
reader.readAsDataURL(xhr.response);
};
xhr.open('GET', url);
xhr.responseType = 'blob';
xhr.send();
}
const { item } = this.state;
console.log(item.files)
const images = []
item.files.map((l) => { images.push({ key: l.key, type: 'photo', url: l.fileLink, b64: '' }) });
item.lineItems.map((l) => { images.push({ key: l.key, type: 'photo', url: l.imageThumb.fileLink, b64: '' }) });
images.map(async (l, i) => {
const url = l.url;
toDataURL(url, (dataUrl) => {
l.b64 = dataUrl;
})
if (i + 1 === images.length) {
this.setState({ creating: false })
}
})
this.setState({ images })
}
createPDF = async () => {
d.autoTable({
startY: 3.9, margin: 1, pageBreak: 'auto', showHead: false,
body: images.map((l, i) => {
const index = i + 1;
const even = index % 2 == 0;
const color = even === true ? [200, 200, 200] : [255, 255, 255];
const title = [{ content: `${l.url}`, meta: { key: l.key, img: l.b64 } }]
return ([...title])
})
,
columns: [
{ header: 'Test', },
{ header: 'Test', },
],
didDrawCell: async (data) => {
if (data.cell.raw !== undefined) {
console.log(data);
if (data.section === 'body') {
console.log("ADD IMAGE")
data.row.height = 2
const ww = d.getImageProperties(data.cell.raw.meta.img).width;
const wh = d.getImageProperties(data.cell.raw.meta.img).height;
const ratio = ww / wh;
d.addImage(data.cell.raw.meta.img, 'PNG', data.cell.x + .2, data.cell.y, 1.75 * ratio, 1.75, `${data.cell.raw.meta.key}`, 'FAST');
}
}
},
});
}
Here are some of the errors I am getting. In my console.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,在这里,您可以选择其他任何遇到的人。从ArcGIS API中获得数据URL后,请使用此功能。
Well here you go for anyone else that runs into this. Once you have your data url from arcgis api use this function.