fix: paper printing size setting #760
This commit is contained in:
@@ -1948,12 +1948,11 @@ export class CommandAdapt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async print() {
|
public async print() {
|
||||||
const { scale, printPixelRatio, paperDirection } = this.options
|
const { scale, printPixelRatio, paperDirection, width, height } =
|
||||||
|
this.options
|
||||||
if (scale !== 1) {
|
if (scale !== 1) {
|
||||||
this.draw.setPageScale(1)
|
this.draw.setPageScale(1)
|
||||||
}
|
}
|
||||||
const width = this.draw.getOriginalWidth()
|
|
||||||
const height = this.draw.getOriginalHeight()
|
|
||||||
const base64List = await this.draw.getDataURL({
|
const base64List = await this.draw.getDataURL({
|
||||||
pixelRatio: printPixelRatio,
|
pixelRatio: printPixelRatio,
|
||||||
mode: EditorMode.PRINT
|
mode: EditorMode.PRINT
|
||||||
|
|||||||
@@ -1,5 +1,35 @@
|
|||||||
import { PaperDirection } from '../dataset/enum/Editor'
|
import { PaperDirection } from '../dataset/enum/Editor'
|
||||||
|
|
||||||
|
function convertPxToPaperSize(width: number, height: number) {
|
||||||
|
if (width === 1125 && height === 1593) {
|
||||||
|
return {
|
||||||
|
size: 'a3',
|
||||||
|
width: '297mm',
|
||||||
|
height: '420mm'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (width === 794 && height === 1123) {
|
||||||
|
return {
|
||||||
|
size: 'a4',
|
||||||
|
width: '210mm',
|
||||||
|
height: '297mm'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (width === 565 && height === 796) {
|
||||||
|
return {
|
||||||
|
size: 'a5',
|
||||||
|
width: '148mm',
|
||||||
|
height: '210mm'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 其他默认不转换
|
||||||
|
return {
|
||||||
|
size: '',
|
||||||
|
width: `${width}px`,
|
||||||
|
height: `${height}px`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export interface IPrintImageBase64Option {
|
export interface IPrintImageBase64Option {
|
||||||
width: number
|
width: number
|
||||||
height: number
|
height: number
|
||||||
@@ -24,10 +54,17 @@ export function printImageBase64(
|
|||||||
const doc = contentWindow.document
|
const doc = contentWindow.document
|
||||||
doc.open()
|
doc.open()
|
||||||
const container = document.createElement('div')
|
const container = document.createElement('div')
|
||||||
|
const paperSize = convertPxToPaperSize(width, height)
|
||||||
base64List.forEach(base64 => {
|
base64List.forEach(base64 => {
|
||||||
const image = document.createElement('img')
|
const image = document.createElement('img')
|
||||||
image.style.width = `${width}px`
|
image.style.width =
|
||||||
image.style.height = `${height}px`
|
direction === PaperDirection.HORIZONTAL
|
||||||
|
? paperSize.height
|
||||||
|
: paperSize.width
|
||||||
|
image.style.height =
|
||||||
|
direction === PaperDirection.HORIZONTAL
|
||||||
|
? paperSize.width
|
||||||
|
: paperSize.height
|
||||||
image.src = base64
|
image.src = base64
|
||||||
container.append(image)
|
container.append(image)
|
||||||
})
|
})
|
||||||
@@ -39,7 +76,9 @@ export function printImageBase64(
|
|||||||
}
|
}
|
||||||
@page {
|
@page {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
size: ${direction === PaperDirection.HORIZONTAL ? `landscape` : `portrait`};
|
size: ${paperSize.size} ${
|
||||||
|
direction === PaperDirection.HORIZONTAL ? `landscape` : `portrait`
|
||||||
|
};
|
||||||
}`
|
}`
|
||||||
style.append(document.createTextNode(stylesheet))
|
style.append(document.createTextNode(stylesheet))
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user