PageOffice 开发者中心 PageOffice 开发者中心
首页
文档
  • 后端Java手册 (opens new window)
  • 后端.netcore手册 (opens new window)
  • 前端JavaScript手册 (opens new window)
下载
购买 (opens new window)
首页
文档
  • 后端Java手册 (opens new window)
  • 后端.netcore手册 (opens new window)
  • 前端JavaScript手册 (opens new window)
下载
购买 (opens new window)
  • 开始

  • 通用控制

  • Word

  • Excel

  • PDF

    • 最简单的打开PDF
    • 添加自定义工具栏按钮
      • 加盖印章和签字功能
    • FileMaker

    • PPT

    • 更多

    目录

    添加自定义工具栏按钮

    # 添加自定义工具栏按钮

    • 查看本示例演示效果
    • 本示例关键代码的编写位置,请参考“开始 - 快速上手”里您所使用的开发语言框架的最简集成代码

    注意

    本文中展示的代码均为关键代码,复制粘贴到您的项目中,按照实际的情况,例如文档路径,用户名等做适当修改即可使用。

    PageOffice针对PDF阅读器提供了自定义工具栏按钮的功能,以便开发人员根据需求添加必要的自定义按钮,比如:放大、缩小、翻页等功能。

    本示例演示如何添加一个自定义按钮。

    # 后端代码

    本示例无后端关键代码。

    # 前端代码

    1. 在OnPDFCtrlInit事件中添加一个自定义按钮;
      OnPDFCtrlInit() {
        pdfctrl.AddCustomToolButton("测试按钮", "myTest()", 0);
      },
      
      // Make sure to add code blocks to your code group
      1. 实现自定义按钮所调用的js函数;
        function myTest() {
            alert("测试按钮被点击了");
        }
        
        // Make sure to add code blocks to your code group

        # 常用按钮

        常用的PDF翻页、缩放、打印、页面设置等按钮代码如下:

          <script>
              function OnPDFCtrlInit() {
                  pdfctrl.AddCustomToolButton("打印", "PrintFile()", 6);
                  pdfctrl.AddCustomToolButton("隐藏/显示书签", "SetBookmarks()", 0);
                  pdfctrl.AddCustomToolButton("-", "", 0);
                  pdfctrl.AddCustomToolButton("实际大小", "SetPageReal()", 16);
                  pdfctrl.AddCustomToolButton("适合页面", "SetPageFit()", 17);
                  pdfctrl.AddCustomToolButton("适合宽度", "SetPageWidth()", 18);
                  pdfctrl.AddCustomToolButton("-", "", 0);
                  pdfctrl.AddCustomToolButton("放大", "ZoomIn()", 14);
                  pdfctrl.AddCustomToolButton("缩小", "ZoomOut()", 15);
                  pdfctrl.AddCustomToolButton("-", "", 0);
                  pdfctrl.AddCustomToolButton("首页", "FirstPage()", 8);
                  pdfctrl.AddCustomToolButton("上一页", "PreviousPage()", 9);
                  pdfctrl.AddCustomToolButton("下一页", "NextPage()", 10);
                  pdfctrl.AddCustomToolButton("尾页", "LastPage()", 11);
                  pdfctrl.AddCustomToolButton("-", "", 0);
                  pdfctrl.AddCustomToolButton("向左旋转90度", "SetRotateLeft()", 12);
                  pdfctrl.AddCustomToolButton("向右旋转90度", "SetRotateRight()", 13);
                  pdfctrl.AddCustomToolButton("-", "", 0);
                  pdfctrl.AddCustomToolButton("全屏/还原", "SwitchFullScreen()", 4);
              }
          
              function SetBookmarks() {
                  pdfctrl.BookmarksVisible = !pdfctrl.BookmarksVisible;
              }
          
              function PrintFile() {
                  pdfctrl.ShowDialog(4);
              }
          
              function SwitchFullScreen() {
                  pdfctrl.FullScreen = !pdfctrl.FullScreen;
              }
          
              function SetPageReal() {
                  pdfctrl.SetPageFit(1);
              }
          
              function SetPageFit() {
                  pdfctrl.SetPageFit(2);
              }
          
              function SetPageWidth() {
                  pdfctrl.SetPageFit(3);
              }
          
              function ZoomIn() {
                  pdfctrl.ZoomIn();
              }
          
              function ZoomOut() {
                  pdfctrl.ZoomOut();
              }
          
              function FirstPage() {
                  pdfctrl.GoToFirstPage();
              }
          
              function PreviousPage() {
                  pdfctrl.GoToPreviousPage();
              }
          
              function NextPage() {
                  pdfctrl.GoToNextPage();
              }
          
              function LastPage() {
                  pdfctrl.GoToLastPage();
              }
          
              function SetRotateRight() {
                  pdfctrl.RotateRight();
              }
          
              function SetRotateLeft() {
                  pdfctrl.RotateLeft();
              }
          
          </script>
          
          // Make sure to add code blocks to your code group
          上次更新: 2024/07/19, 13:11:18
          PageOffice | Copyright © 2013-2026 卓正软件 京ICP备12010902号-2 京公网安备 11010502019270号
          • 跟随系统
          • 浅色模式
          • 深色模式
          • 阅读模式