feat: set print layout format when printing #448
This commit is contained in:
@@ -1920,7 +1920,7 @@ export class CommandAdapt {
|
||||
}
|
||||
|
||||
public async print() {
|
||||
const { scale, printPixelRatio } = this.options
|
||||
const { scale, printPixelRatio, paperDirection } = this.options
|
||||
if (scale !== 1) {
|
||||
this.draw.setPageScale(1)
|
||||
}
|
||||
@@ -1930,7 +1930,11 @@ export class CommandAdapt {
|
||||
pixelRatio: printPixelRatio,
|
||||
mode: EditorMode.PRINT
|
||||
})
|
||||
printImageBase64(base64List, width, height)
|
||||
printImageBase64(base64List, {
|
||||
width,
|
||||
height,
|
||||
direction: paperDirection
|
||||
})
|
||||
if (scale !== 1) {
|
||||
this.draw.setPageScale(scale)
|
||||
}
|
||||
|
||||
@@ -1,8 +1,15 @@
|
||||
import { PaperDirection } from '../dataset/enum/Editor'
|
||||
|
||||
export interface IPrintImageBase64Option {
|
||||
width: number
|
||||
height: number
|
||||
direction?: PaperDirection
|
||||
}
|
||||
export function printImageBase64(
|
||||
base64List: string[],
|
||||
width: number,
|
||||
height: number
|
||||
options: IPrintImageBase64Option
|
||||
) {
|
||||
const { width, height, direction = PaperDirection.VERTICAL } = options
|
||||
const iframe = document.createElement('iframe')
|
||||
// 离屏渲染
|
||||
iframe.style.visibility = 'hidden'
|
||||
@@ -25,7 +32,15 @@ export function printImageBase64(
|
||||
container.append(image)
|
||||
})
|
||||
const style = document.createElement('style')
|
||||
const stylesheet = `*{margin:0;padding:0;}@page{margin:0;}`
|
||||
const stylesheet = `
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
@page {
|
||||
margin: 0;
|
||||
size: ${direction === PaperDirection.HORIZONTAL ? `landscape` : `portrait`};
|
||||
}`
|
||||
style.append(document.createTextNode(stylesheet))
|
||||
setTimeout(() => {
|
||||
doc.write(`${style.outerHTML}${container.innerHTML}`)
|
||||
|
||||
Reference in New Issue
Block a user