国产linux系统(银河麒麟,统信uos)使用 PageOffice 国产版在线打开 pdf 文件

PageOffice 国产版 :支持信创系统,支持银河麒麟V10和统信UOS,支持X86(intel、兆芯、海光等)、ARM(飞腾、鲲鹏、麒麟等)芯片架构。

查看本示例演示效果
本示例关键代码的编写位置
Vue+Springboot

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

在OA办公、文档流转等各个Web系统中,实现最简单在线查看PDF功能,调用PageOffice只需要几行代码就可以完成。

后端代码

  1. 在后端编写代码调用webOpen方法打开文件。
PDFCtrl pdfCtrl = new PDFCtrl(request);
//pdfCtrl.setAllowCopy(false);//禁止拷贝
pdfCtrl.webOpen("D:\\documents\\test.pdf");
// Linux服务器添加前缀:file://
// pdfCtrl.webOpen("file://"+"/root/documents/test.pdf");

前端代码

  1. 在OnPDFCtrlInit事件中添加按钮(根据实际业务需求处理即可);
	  OnPDFCtrlInit() {
      //PDF的初始化事件回调函数,您可以在这里添加自定义按钮
	  	if(("linux")!=(pdfctrl.ClientOS)){
			pdfctrl.AddCustomToolButton("隐藏/显示书签", "SetBookmarks()", 0);
		}
		pdfctrl.AddCustomToolButton("打印", "PrintFile()", 6);
		pdfctrl.AddCustomToolButton("-", "", 0);
		pdfctrl.AddCustomToolButton("实际大小", "SetPageReal()", 16);
		pdfctrl.AddCustomToolButton("适合页面", "SetPageFit()", 17);
		pdfctrl.AddCustomToolButton("适合宽度", "SetPageWidth()", 18);
		pdfctrl.AddCustomToolButton("缩小", "ZoomOut()", 17);
		pdfctrl.AddCustomToolButton("放大", "ZoomIn()", 18);
		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);
    },
  1. 实现自定义按钮所调用的js函数;
	  SetBookmarks() {
		 pdfctrl.BookmarksVisible = !pdfctrl.BookmarksVisible;
	  },
	  PrintFile() {
		 pdfctrl.ShowDialog(4);
	  },
	  SwitchFullScreen() {
		 pdfctrl.FullScreen = !pdfctrl.FullScreen;
	  },
	  SetPageReal() {
		 pdfctrl.SetPageFit(1);
	  },
	  SetPageFit() {
		 pdfctrl.SetPageFit(2);
	  },
	  SetPageWidth() {
		 pdfctrl.SetPageFit(3);
	  },
	  ZoomIn() {
		 pdfctrl.ZoomIn();
	  },
	  ZoomOut() {
		 pdfctrl.ZoomOut();
	  },
	  FirstPage() {
		 pdfctrl.GoToFirstPage();
	  },
	  PreviousPage() {
		 pdfctrl.GoToPreviousPage();
	  },
	  NextPage() {
		 pdfctrl.GoToNextPage();
	  },
	  LastPage() {
		 pdfctrl.GoToLastPage();
	  },
	  SetRotateRight() {
		 pdfctrl.RotateRight();
	  },
	  SetRotateLeft() {
		 pdfctrl.RotateLeft();
	  },

参考链接:最简单的打开PDF

posted on 2024-06-19 17:37  qianxi  阅读(19)  评论(0编辑  收藏  举报