electron-hiprint
electron-hiprint copied to clipboard
render-pdf 生成内容与 getPdf api 不一致
左侧为 vue-plugin-hiprint getPdf 效果,右侧为 electron-hiprint 提供 render-pdf 效果
附json 点击查看
{
"panels": [{
"index": 0,
"name": 1,
"height": 12,
"width": 12,
"paperHeader": 0,
"paperFooter": 31.515151515151512,
"printElements": [{
"options": {
"left": 1.5,
"top": 0,
"height": 25.5,
"width": 25.5,
"title": "二维码",
"qrcodeType": "qrcode",
"testData": "qrcode",
"field": "qrcode",
"qrCodeLevel": 0,
"coordinateSync": false,
"widthHeightSync": false,
"hideTitle": true,
"zIndex": 1,
"right": 27.375,
"bottom": 23.375003814697266,
"vCenter": 14.625,
"hCenter": 10.625003814697266
},
"printElementType": {
"title": "二维码",
"type": "qrcode"
}
}],
"paperNumberLeft": 4,
"paperNumberTop": 12,
"paperNumberContinue": true,
"watermarkOptions": {
"content": "",
"rotate": 25,
"timestamp": true,
"format": "YYYY-MM-DD HH:mm",
"fillStyle": "rgba(184, 184, 184, 0.3)",
"fontSize": "14px",
"width": 200,
"height": 200
},
"panelLayoutOptions": {
"layoutType": "column",
"layoutRowGap": 0,
"layoutColumnGap": 0
}
}]
}
自定义纸张大小为12*12, electron-hiprint 提供 render-pdf生成的矢量PDF与前台导出查看pdf(PdfObjectNewWindow)效果不一致,且多打了一张空白页。
使用版本及方法如下图
使用electron-hiprint 提供 render-pdf导出矢量Pdf 的方法
exportSvgPdf() {
const printOptions = {
pageSize: {
width: hiprintTemplate.editingPanel.width * 1000,
height: hiprintTemplate.editingPanel.height * 1000,
},
printer: 'Microsoft Print to PDF',
template: hiprintTemplate.getJson(),
data: printData,
}
hiprint.hiwebSocket.socket.emit('render-pdf', {
...printOptions,
})
hiprint.hiwebSocket.socket.on('render-pdf-success', (data) => {
console.log('render-pdf-success: ', data)
this.previewPdfByBlob(data.buffer)
})
hiprint.hiwebSocket.socket.on('render-pdf-error', (data) => {
console.log('render-pdf-error: ', data)
})
},
// 预览PDF 流
previewPdfByBlob(data) {
const blob = new Blob([data], { type: 'application/pdf' })
const blobURL = window.URL.createObjectURL(blob)
if (blobURL) {
window.open(URL.createObjectURL(blob))
}
},
模板JSON
{
"panels": [
{
"index": 0,
"name": 1,
"height": 12,
"width": 12,
"paperHeader": 1.5,
"paperFooter": 31.515151515151516,
"printElements": [
{
"options": {
"left": 1.5,
"top": 0,
"height": 9.75,
"width": 19.5,
"title": "文本",
"right": 20.25,
"bottom": 6.75,
"vCenter": 10.5,
"hCenter": 1.875
},
"printElementType": {
"title": "文本",
"type": "text"
}
}
],
"paperNumberLeft": 12,
"paperNumberTop": 13.5,
"paperNumberDisabled": true,
"paperNumberContinue": true,
"watermarkOptions": {
"content": "vue-plugin-hiprint",
"rotate": 25,
"timestamp": true,
"format": "YYYY-MM-DD HH:mm"
},
"panelLayoutOptions": {}
}
]
}
今天研究了很久,尝试过很多方式暂时无法解决,已知该问题暂时只出现在小模板上