You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Angular Syncfusion PDF Viewer打印预览去空白页及自动设99%缩放求助

问题描述

Angular项目中使用Syncfusion PDF Viewer展示PDF时遇到异常:特定PDF在打印预览弹窗中会多出一页空白页,但常规展示无问题;手动将打印预览缩放比例改为自定义99%后,空白页消失。需要实现打印预览默认自动设置为99%缩放。

已尝试无效的方案
  • 查阅Syncfusion官方多平台(.NET Web Forms、.NET Core、JavaScript、WPF等)去空白页文档
  • 排查应用内可能导致宽度溢出的设置
  • 尝试自定义打印媒体CSS:
@media print {
  * {
    transform: scale(0.99);
    transform-origin: 0 0;
  }
}
可行解决方案

针对Angular版Syncfusion PDF Viewer,可通过监听printBegin事件拦截默认打印流程,自定义打印参数设置缩放比例为99%,具体实现如下:

  1. 模板中绑定printBegin事件:
<ejs-pdfviewer
  id="pdfViewer"
  [documentPath]="documentPath"
  (printBegin)="onPrintBegin($event)"
></ejs-pdfviewer>
  1. 组件TS代码实现事件处理逻辑:
import { Component } from '@angular/core';
import { PrintBeginEventArgs } from '@syncfusion/ej2-angular-pdfviewer';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  public documentPath: string = '目标PDF路径';

  onPrintBegin(args: PrintBeginEventArgs): void {
    // 取消默认打印行为
    args.cancel = true;
    // 获取PDF Viewer实例并调用打印方法,指定缩放比例为0.99
    const pdfViewer = document.getElementById('pdfViewer') as any;
    pdfViewer.print({ scale: 0.99 });
  }
}

若上述方法仍有异常,可尝试调整PDF Viewer的页面适配设置,强制文档适配打印纸张宽度:

<ejs-pdfviewer
  id="pdfViewer"
  [documentPath]="documentPath"
  [pageSettings]="{ layout: 'FitToWidth' }"
></ejs-pdfviewer>

内容的提问来源于stack exchange,提问作者Zachary Golla

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 18:25:01