You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
791 B

export function printImageBase64(base64List: string[], width: number, height: number) {
const iframe = document.createElement('iframe')
document.body.append(iframe)
const doc = iframe.contentWindow!.document
doc.open()
const container = document.createElement('div')
base64List.forEach(base64 => {
const image = document.createElement('img')
image.style.width = `${width}px`
image.style.height = `${height}px`
image.src = base64
container.append(image)
})
const style = document.createElement('style')
const stylesheet = `*{margin:0;padding:0;}`
style.append(document.createTextNode(stylesheet))
setTimeout(() => {
doc.write(`${style.outerHTML}${container.innerHTML}`)
iframe.contentWindow?.print()
doc.close()
iframe.remove()
})
}