md
This commit is contained in:
parent
a6c0f9cf82
commit
ff00d1d485
@ -62,6 +62,7 @@
|
||||
* 但他会下载最新的2.16版本,这个版本和原来的2.5结构目录不一样,
|
||||
* 一定要使用4.2的话就手动装一下pdfjs-dist的2.5.207 ==> npm i pdfjs-dist@2.5.207
|
||||
*/
|
||||
import printJS from 'print-js'
|
||||
import pdf from 'vue-pdf'
|
||||
import PdfUtils from '@/utils/pdfUtils.js';
|
||||
export default {
|
||||
@ -376,7 +377,9 @@ export default {
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
this.$refs.pdf.print();
|
||||
|
||||
printJS(this.loadPdfUrl);
|
||||
// this.$refs.pdf.print();
|
||||
// window.print();
|
||||
}else{
|
||||
this.$emit("onPrint");
|
||||
|
||||
@ -18,64 +18,9 @@ import * as pdfjsWorker from 'pdfjs-dist/build/pdf.worker.entry';
|
||||
*/
|
||||
export default class PdfUtils {
|
||||
constructor() {
|
||||
// { blob, docTitle, isAddWatermark = false, watermark: { type = 'text', text = 'WFT', image } }
|
||||
const _self = this
|
||||
// if(!blob) {
|
||||
// return console.error('[PDF Blob Is a required parameter]')
|
||||
// }
|
||||
// if(!isAddWatermark) { // 不添加水印
|
||||
// _self.preView(blob, docTitle)
|
||||
// } else {
|
||||
// let bytes,imageType
|
||||
// if(type == 'image') {
|
||||
// if(!image) {
|
||||
// return console.error('["image" Is a required parameter]')
|
||||
// }
|
||||
// bytes = image.bytes
|
||||
// imageType = image.imageType
|
||||
// }
|
||||
// const map = {
|
||||
// 'text': _self.addTextWatermark.bind(_self),
|
||||
// 'image': _self.addImageWatermark.bind(_self),
|
||||
// 'canvas': _self.addCanvasWatermark.bind(_self)
|
||||
// }
|
||||
// blob.arrayBuffer().then(async buffer => {
|
||||
// const existingPdfBytes = buffer
|
||||
// const pdfDoc = await PDFDocument.load(existingPdfBytes)
|
||||
// let params
|
||||
// if(type == 'text') params = { pdfDoc, text, docTitle }
|
||||
// if(type == 'image') params = { pdfDoc, bytes, imageType, docTitle }
|
||||
// if(type == 'canvas') params = { pdfDoc, text, docTitle }
|
||||
// map[type](params)
|
||||
// }).catch(e => console.error('[Preview Pdf Error]:', e))
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过模版生成A4纸面单
|
||||
* @param {*} templatePath
|
||||
* @param {*} outputPath
|
||||
* @param {*} data
|
||||
*/
|
||||
// const { PDFDocument, StandardFonts } = require('pdf-lib');
|
||||
// const fs = require('fs');
|
||||
// const fontkit = require('@pdf-lib/fontkit')
|
||||
// let pdfDoc
|
||||
// let font
|
||||
// 使用示例
|
||||
// const templatePath = 'template.pdf';
|
||||
// const outputPath = 'output.pdf';
|
||||
// const data = {
|
||||
// 'key': 'value支持中文参数',
|
||||
// };
|
||||
|
||||
// fillPdfForm(templatePath, outputPath, data)
|
||||
// .then(() => {
|
||||
// console.log('PDF生成成功');
|
||||
// })
|
||||
// .catch((error) => {
|
||||
// console.log('PDF生成失败:', error);
|
||||
// });
|
||||
|
||||
async fillPdfForm(templatePath, outputPath, data) {
|
||||
const templateBytes = await fs.promises.readFile(templatePath);
|
||||
@ -98,6 +43,31 @@ export default class PdfUtils {
|
||||
await fs.promises.writeFile(outputPath, modifiedPdfBytes);
|
||||
}
|
||||
|
||||
async getPdfByTpl(tplBase64Data, data) {
|
||||
const templateBytes = await fs.promises.readFile(templatePath);
|
||||
pdfDoc = await PDFDocument.load(templateBytes);
|
||||
pdfDoc.registerFontkit(fontkit);
|
||||
font = await pdfDoc.embedFont(fontBytes);
|
||||
const form = pdfDoc.getForm();
|
||||
|
||||
for (const fieldKey in data) {
|
||||
const field = form.getTextField(fieldKey);
|
||||
if (field) {
|
||||
field.setText(data[fieldKey]);
|
||||
field.updateAppearances(font)
|
||||
}
|
||||
}
|
||||
|
||||
const modifiedPdfBytes = await pdfDoc.save();
|
||||
|
||||
await fs.promises.writeFile(outputPath, modifiedPdfBytes);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 添加 Text 水印
|
||||
async addTextWatermark({ pdfDoc, text, docTitle }) {
|
||||
// console.log(StandardFonts, 'StandardFonts-->>') // 字体
|
||||
|
||||
@ -138,6 +138,9 @@
|
||||
selPrinterName:null,
|
||||
|
||||
currentSelection:[],
|
||||
|
||||
pdfUtils:new PdfUtils({})
|
||||
|
||||
};
|
||||
},
|
||||
watch: {
|
||||
@ -358,8 +361,9 @@
|
||||
}
|
||||
else if(code == 200){
|
||||
console.log("===获取到数据====>");
|
||||
const pdfData=deepClone(data);
|
||||
loadingInstance.close();
|
||||
loadingInstance.close();
|
||||
|
||||
const pdfData=deepClone(data);
|
||||
let pdfInfo={
|
||||
"billCode":pdfData.ydSn,
|
||||
"pdfUrl":null,
|
||||
@ -368,7 +372,6 @@
|
||||
|
||||
that.pdfList.push(pdfInfo);
|
||||
|
||||
console.log(that.pdfList);
|
||||
|
||||
if(!that.openPdfView && that.showCounter==0){
|
||||
that.openPdfView = true;
|
||||
@ -432,20 +435,76 @@
|
||||
}
|
||||
else if(code == 200){
|
||||
|
||||
if(!that.isInitA4){
|
||||
const pdfData=deepClone(data);
|
||||
loadingInstance.close();
|
||||
let pdfUtils=new PdfUtils({});
|
||||
pdfUtils.getBlobUrl(pdfData.file, pdfData.ydSn+".pdf",true )
|
||||
that.pdfUtils.getBlobUrl(pdfData.file, pdfData.ydSn+".pdf",true )
|
||||
}else{
|
||||
|
||||
const pdfData=deepClone(data);
|
||||
let pdfInfo={
|
||||
"billCode":pdfData.ydSn,
|
||||
"pdfUrl":null,
|
||||
"pdfBase64":pdfData.file
|
||||
}
|
||||
that.pdfList.push(pdfInfo);
|
||||
|
||||
}
|
||||
}
|
||||
else if(code == 800){
|
||||
|
||||
// 全部获取完成
|
||||
// console.log("===全部获取完成====>");
|
||||
// A4下载
|
||||
if(that.isInitA4){
|
||||
that.downA4PDF();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
},
|
||||
|
||||
downA4PDF(){
|
||||
let cacheA4FileList=[];
|
||||
const newList = Object.assign([], this.pdfList);
|
||||
if(newList&&newList.length>4){
|
||||
let spliteArr = (array = [], subGroupLength = 0) => {
|
||||
let index = 0;
|
||||
const newArray = [];
|
||||
while (index < array.length) {
|
||||
newArray.push(array.slice(index, index += subGroupLength));
|
||||
}
|
||||
return newArray;
|
||||
}
|
||||
const subPdfList=spliteArr(newList, 4);
|
||||
for (let i=0; i < subPdfList.length;i++){
|
||||
let fileItem={
|
||||
"billCode":"page-"+(i+1),
|
||||
"pdfUrl":null,
|
||||
"childreen":subPdfList[i]
|
||||
}
|
||||
cacheA4FileList.push(fileItem);
|
||||
}
|
||||
}else{
|
||||
let fileItem={
|
||||
"billCode":"page-"+1,
|
||||
"pdfUrl":null,
|
||||
"childreen":newList
|
||||
}
|
||||
cacheA4FileList.push(fileItem);
|
||||
}
|
||||
|
||||
// 下载
|
||||
for(let i=0;i<cacheA4FileList.length;i++){
|
||||
let thisSubList=cacheA4FileList[i].childreen;
|
||||
let needGenList=[];
|
||||
for(let j=0;j<thisSubList.length;j++){
|
||||
needGenList.push(thisSubList[j].pdfBase64)
|
||||
}
|
||||
this.pdfUtils.mergePdfToA4(needGenList,"page-"+i+".pdf",true);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
// 响应PDF预览
|
||||
onPdfViewPrint(){
|
||||
this.$emit("onPrint");
|
||||
|
||||
@ -107,7 +107,7 @@
|
||||
-->
|
||||
|
||||
<!-- <el-table-column :label="$t('客户编码')" align="center" prop="customerCode" min-width="100" /> -->
|
||||
<el-table-column :label="$t('收件人')" align="left" prop="name" width="100" >
|
||||
<el-table-column :label="$t('收件人')" align="left" prop="name" width="100" :show-overflow-tooltip="true" >
|
||||
<template slot-scope="scope">
|
||||
<div class="link-type" @click="handleUpdate(scope.row)">{{scope.row.name}}</div>
|
||||
</template>
|
||||
@ -118,7 +118,7 @@
|
||||
<!-- <el-table-column :label="$t('地址别名')" align="center" prop="alias" min-width="100" /> -->
|
||||
<!-- <el-table-column :label="$t('地址类型')" align="center" prop="addressType" min-width="100" /> -->
|
||||
<el-table-column :label="$t('国家')" align="center" prop="countryName" width="80" />
|
||||
<el-table-column :label="$t('地区')" align="center" prop="provinceName" width="100" :show-overflow-tooltip="true">
|
||||
<el-table-column :label="$t('地区')" align="left" prop="provinceName" width="200" :show-overflow-tooltip="true">
|
||||
<template slot-scope="scope">
|
||||
<div>{{scope.row.provinceName}} {{scope.row.cityName}} {{scope.row.countyName}} </div>
|
||||
</template>
|
||||
@ -128,12 +128,12 @@
|
||||
<!-- <el-table-column :label="$t('城镇')" align="center" prop="town" min-width="100" /> -->
|
||||
<el-table-column :label="$t('地址')" align="left" prop="address" min-width="200" :show-overflow-tooltip="true" />
|
||||
<!-- <el-table-column :label="$t('邮编')" align="center" prop="postCode" min-width="100" /> -->
|
||||
<el-table-column :label="$t('公司')" align="center" prop="company" min-width="100" />
|
||||
<el-table-column :label="$t('email')" align="center" prop="email" min-width="100" />
|
||||
<el-table-column :label="$t('公司')" align="left" prop="company" min-width="170" :show-overflow-tooltip="true" />
|
||||
<el-table-column :label="$t('email')" align="left" prop="email" min-width="100" />
|
||||
<!-- <el-table-column :label="$t('是否默认')" align="center" prop="blDefaultFlag" min-width="100" /> -->
|
||||
<!-- <el-table-column :label="$t('排序')" align="center" prop="orderNum" min-width="100" /> -->
|
||||
<!-- <el-table-column :label="$t('使用站点是否默认')" align="center" prop="blSiteDefaultFlag" min-width="100" /> -->
|
||||
<el-table-column :label="$t('所属站点')" align="center" prop="useSite" min-width="100" />
|
||||
<el-table-column :label="$t('使用网点')" align="center" prop="useSiteName" min-width="100" />
|
||||
<el-table-column :label="$t('创建时间')" align="center" prop="createTime" min-width="170" />
|
||||
<!-- <el-table-column :label="$t('使用站点代码')" align="center" prop="useSiteCode" min-width="100" /> -->
|
||||
<!-- <el-table-column :label="$t('删除标志(0代表存在')" align="center" prop="delFlag" min-width="100" /> -->
|
||||
|
||||
@ -109,7 +109,7 @@
|
||||
-->
|
||||
|
||||
<!-- <el-table-column :label="$t('客户编码')" align="center" prop="customerCode" min-width="100" /> -->
|
||||
<el-table-column :label="$t('寄件人')" align="left" prop="name" width="100" >
|
||||
<el-table-column :label="$t('寄件人')" align="left" prop="name" width="170" :show-overflow-tooltip="true" >
|
||||
<template slot-scope="scope">
|
||||
<div class="link-type" @click="handleUpdate(scope.row)">{{scope.row.name}}</div>
|
||||
</template>
|
||||
@ -120,7 +120,7 @@
|
||||
<!-- <el-table-column :label="$t('地址别名')" align="center" prop="alias" min-width="100" /> -->
|
||||
<!-- <el-table-column :label="$t('地址类型')" align="center" prop="addressType" min-width="100" /> -->
|
||||
<el-table-column :label="$t('国家')" align="center" prop="countryName" width="80" />
|
||||
<el-table-column :label="$t('地区')" align="center" prop="provinceName" width="100" :show-overflow-tooltip="true">
|
||||
<el-table-column :label="$t('地区')" align="left" prop="provinceName" width="200" :show-overflow-tooltip="true">
|
||||
<template slot-scope="scope">
|
||||
<div>{{scope.row.provinceName}} {{scope.row.cityName}} {{scope.row.countyName}} </div>
|
||||
</template>
|
||||
@ -130,12 +130,12 @@
|
||||
<!-- <el-table-column :label="$t('城镇')" align="center" prop="town" min-width="100" /> -->
|
||||
<el-table-column :label="$t('地址')" align="left" prop="address" min-width="200" :show-overflow-tooltip="true" />
|
||||
<!-- <el-table-column :label="$t('邮编')" align="center" prop="postCode" min-width="100" /> -->
|
||||
<el-table-column :label="$t('公司')" align="center" prop="company" min-width="100" />
|
||||
<el-table-column :label="$t('公司')" align="left" prop="company" min-width="170" :show-overflow-tooltip="true" />
|
||||
<el-table-column :label="$t('email')" align="center" prop="email" min-width="100" />
|
||||
<!-- <el-table-column :label="$t('是否默认')" align="center" prop="blDefaultFlag" min-width="100" /> -->
|
||||
<!-- <el-table-column :label="$t('排序')" align="center" prop="orderNum" min-width="100" /> -->
|
||||
<!-- <el-table-column :label="$t('使用站点是否默认')" align="center" prop="blSiteDefaultFlag" min-width="100" /> -->
|
||||
<el-table-column :label="$t('所属站点')" align="center" prop="useSite" min-width="100" />
|
||||
<el-table-column :label="$t('使用网点')" align="center" prop="useSiteName" min-width="100" />
|
||||
<el-table-column label="创建人" align="center" prop="createByName" width="80" :show-overflow-tooltip="true"/>
|
||||
<el-table-column label="创建网点" align="center" prop="createSiteName" width="80" :show-overflow-tooltip="true"/>
|
||||
<el-table-column label="创建时间" align="center" prop="createTime" width="170"/>
|
||||
|
||||
@ -257,7 +257,7 @@
|
||||
</el-col>
|
||||
|
||||
<el-col :span="1.5">
|
||||
<TanexPrinterPanel ref="tanexPrinter" :isShowPinters="true" :isShowTpl="true" :isShowSubBillRange="true" @onPrint="handleBatchPrint"></TanexPrinterPanel>
|
||||
<TanexPrinterPanel ref="tanexPrinter" :isShowPinters="true" :isShowTpl="true" :isInitA4="false" :isShowSubBillRange="true" @onPrint="handleBatchPrint"></TanexPrinterPanel>
|
||||
</el-col>
|
||||
|
||||
|
||||
|
||||
@ -171,7 +171,7 @@
|
||||
</el-checkbox-group>
|
||||
</div>
|
||||
<div style="margin-left:10px">
|
||||
<TanexPrinterPanel ref="tanexPrinter" v-model="printerStatus" @onPrint="handleBatchPrint" @onPrintComplete="onComplete"></TanexPrinterPanel>
|
||||
<TanexPrinterPanel ref="tanexPrinter" v-model="printerStatus" @onPrint="handleBatchPrint" :isInitA4="false" @onPrintComplete="onComplete"></TanexPrinterPanel>
|
||||
</div>
|
||||
</div>
|
||||
</el-form-item>
|
||||
@ -1534,7 +1534,7 @@ methods: {
|
||||
this.form.sender.country=value.country;
|
||||
this.form.sender.province=value.province;
|
||||
this.form.sender.city=value.city;
|
||||
this.form.sender.county=value.district;
|
||||
this.form.sender.county=value.county;
|
||||
// this.form.receiveTown=value.town;
|
||||
this.form.sender.address=value.address;
|
||||
this.form.sender.company=value.company;
|
||||
@ -1545,7 +1545,7 @@ methods: {
|
||||
this.form.reciever.country=value.country;
|
||||
this.form.reciever.province=value.province;
|
||||
this.form.reciever.city=value.city;
|
||||
this.form.reciever.county=value.district;
|
||||
this.form.reciever.county=value.county;
|
||||
// this.form.receiveTown=value.town;
|
||||
this.form.reciever.address=value.address;
|
||||
this.form.reciever.company=value.company;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user