本帖最后由 想念 于 2023-7-6 11:01 编辑
这个是我设置pdf的代码 。let fontsObj = fonts,fonts在下面的压缩文件中
- /**导出PDF*/
- handleExport(){
- let spread = this.designer.getWorkbook()
- let fontsObj = fonts;
- this.registerCustomFont(fontsObj);
- this.addFontsToFontManager(fontsObj);
- this.setPrintInfo(spread);
- spread.savePDF(function (blob) {
- saveAs(blob, '辰元评级.pdf');
- },function (error) {
- console.log(error);
- }, {
- });
- },
- registerCustomFont(fontsObj) {
- var fonts = {
- normal: fontsObj["simkai.ttf"],
- };
- GC.Spread.Sheets.PDF.PDFFontsManager.registerFont("楷体", fonts);
- },
- addFontsToFontManager(fontsObj) {
- var fonts = {
- normal: fontsObj["MTCORSVA.TTF"],
- };
- GC.Spread.Sheets.PDF.PDFFontsManager.fallbackFont = function (font) {
- var fontInfoArray = font.split(" "),
- fontName = fontInfoArray[fontInfoArray.length - 1];
- if (fontName === "mtcorsva") {
- return fonts.normal;
- }
- };
- },
- setPrintInfo(spread) {
- for (let i = 0; i < spread.getSheetCount(); i++) {
- var sheet = spread.getSheet(i)
- var printInfo = sheet.printInfo();
- sheet.suspendPaint();
- printInfo.showBorder(false); // 是否显示边框
- printInfo.showGridLine(false); // 是否打印网格线 (默认是打印)
- printInfo.blackAndWhite(false); // 彩色打印
- // printInfo.margin({top:20, bottom:20, left:20, right:20,}) // 边距
- if(i==1) {
- printInfo.columnEnd(6); // 打印截至至某一列
- sheet.setRowPageBreak(44, true); // 设置在打印时是否在此表单上的指定行之前插入强制分页符
- sheet.setRowPageBreak(82, true); // 设置在打印时是否在此表单上的指定行之前插入强制分页符
- printInfo.headerCenter(this.form.fileCode);
- printInfo.footerCenter("&P/&N");
- printInfo.watermark([{x: 60, y: 20, width: 201, height: 48, imageSrc: this.images1, page: "all"}]);
- }else {
- printInfo.margin({top:-10, bottom:-10, left:-12, right:-50,}) // 边距
- printInfo.columnEnd(12) // 打印截至至某一列
- printInfo.rowEnd(62) // 打印截至至某一行
- }
- printInfo.centering(GC.Spread.Sheets.Print.PrintCentering.horizontal); // 打印的居中方式
- printInfo.qualityFactor(8); //打印质量,value为1~8的一个数值,越高则打印效果越好
- sheet.resumePaint();
- }
- }
复制代码 |
|