卓正--WORD在线编辑预览保存打印和多文件打印

1.先安装pageoffice4.5.0.13.jar

在包目录下打开cmd安装

mvn install:install-file -DgroupId=com.zhuozhengsoft -DartifactId=pageoffice -Dversion=4.5.0.13  -Dpackaging=jar  -Dfile=pageoffice4.5.0.13.jar


    com.zhuozhengsoft
    pageoffice
    4.5.0.13

2.在@SpringBootApplication项目启动文件里添加,服务器授权

${file.save.path}是在配置文件配置的放注册文件文件地址,随便设置

# pageoffice注册表保存地址
file:
  save:
    path: /
@Value("${file.save.path}")
String poSysPath;

/**
 * 添加PageOffice的服务器端授权程序Servlet(必须)
 * @return
 */
@Bean
public ServletRegistrationBean servletRegistrationBean() {
    Server poserver = new Server();
    //设置PageOffice注册成功后,license.lic文件存放的目录
    poserver.setSysPath(poSysPath);
    ServletRegistrationBean srb = new ServletRegistrationBean(poserver);
    srb.addUrlMappings("/poserver.zz");
    srb.addUrlMappings("/posetup.exe");
    srb.addUrlMappings("/pageoffice.js");
    srb.addUrlMappings("/jquery.min.js");
    srb.addUrlMappings("/pobstyle.css");
    srb.addUrlMappings("/sealsetup.exe");
    return srb;
} 

 3.java后台代码

package com.tlorder.order.controller;

@Controller
@RequestMapping("/pageOffice")
public class PageOfficeController extends BaseController {

    @Autowired
    private IWebPubFilesService webPubFilesService;
    @Autowired
    private IOrderMultiFileService orderMultiFileService;
    @Autowired
    private ISysUserService userService;

    //单据模板在线编辑
    @RequestMapping(value = "/onlineEditing", method = RequestMethod.GET)
    public ModelAndView onlineEditing(@PathParam("fid") Integer fid, @PathParam("Identification") Integer Identification, HttpServletRequest request, Map map) {
        //获取文件对象
        WebPubFiles webPubFiles = webPubFilesService.selectWebPubFilesById(Integer.valueOf(fid));

        //--- PageOffice的调用代码 开始 -----
        PageOfficeCtrl poCtrl = new PageOfficeCtrl(request);
        //设置服务器页面
        poCtrl.setServerPage("/poserver.zz");//设置授权程序servlet
        poCtrl.addCustomToolButton("保存", "Save()", 1); //添加自定义按钮
        poCtrl.addCustomToolButton("打印", "PrintFile()", 6);
        //poCtrl.addCustomToolButton("全屏/还原", "IsFullScreen()", 4);
        poCtrl.addCustomToolButton("关闭", "CloseFile()", 21);
        //隐藏功能
        poCtrl.setTitlebar(false); //隐藏标题栏
        poCtrl.setMenubar(false); //隐藏菜单栏
        poCtrl.setJsFunction_AfterDocumentOpened("afterDocumentOpened()");//设置软件打开后全屏js
        //设置保存页面
        //poCtrl.setSaveFilePage("saveFile?id=");//设置保存的action
        //打开 Word 文档
        //判断是否是打开源模板 还是 单据模板
        if (Identification == 1) {
            poCtrl.setSaveFilePage("saveFile?Identification=1&fileId=" + webPubFiles.getId());//设置保存的action
            poCtrl.webOpen(webPubFiles.getDataDiskpath(), OpenModeType.docNormalEdit, "");
        } else {
            poCtrl.setSaveFilePage("saveFile?Identification=1&fileId=" + webPubFiles.getId());//设置保存的action
            poCtrl.webOpen(webPubFiles.getDiskpath(), OpenModeType.docNormalEdit, "");
        }
        poCtrl.setCaption("word文档在线编辑");
        map.put("pageoffice", poCtrl.getHtmlCode("PageOfficeCtrl1"));
        //--- PageOffice的调用代码 结束 -----

        ModelAndView mv = new ModelAndView("/demo/pageoffice/pageoffice");
        return mv;
    }

    //模板在线编辑保存
    @RequestMapping(value = "/saveFile", method = RequestMethod.POST)
    public void saveFile(HttpServletResponse response, HttpServletRequest request) {
        String fileId = request.getParameter("fileId");
        String Identification = request.getParameter("Identification");
        //System.out.println("fileId=" + fileId);
        WebPubFiles webPubFiles = webPubFilesService.selectWebPubFilesById(Integer.valueOf(fileId));
        if (webPubFiles == null) {

        } else {
            String fileDiskPath = "";

            if (!Identification.equals("1")) {
                fileDiskPath = webPubFiles.getDiskpath();
            } else {
                fileDiskPath = webPubFiles.getDataDiskpath();
            }
            // System.out.println("fileDiskPath=" + fileDiskPath);
            FileSaver fs = new FileSaver(request, response);
            //保存文件
            fs.saveToFile(fileDiskPath);
            fs.close();
        }
    }

    //多文件打印
    @RequestMapping(value = "/filesURL", method = RequestMethod.GET)
    public String filesURL(@PathParam("masterNo") String masterNo, ModelMap mmap) {

        OrderMultiFile orderMultiFile = new OrderMultiFile();
        orderMultiFile.setMasterNo(masterNo);
        //须打印对象
        List orderMultiFileList = orderMultiFileService.selectOrderMultiFileList(orderMultiFile);
        mmap.put("orderMultiFileList", orderMultiFileList);
        return "/demo/pageoffice/printDefault";

    }

    //多文件打印
    @RequestMapping(value = "/printFiles")
    public ModelAndView printFiles(HttpServletRequest request, Map map) {
        FileMakerCtrl fmCtrl = new FileMakerCtrl(request);
        fmCtrl.setServerPage(request.getContextPath() + "/poserver.zz");
        String id = request.getParameter("id");
        OrderMultiFile orderMultiFile = orderMultiFileService.selectOrderMultiFileById(Integer.valueOf(id));
        if (id != null && id.length() > 0) {
            //WordDocument doc = new WordDocument();
            //给数据区域赋值,即把数据填充到模板中相应的位置
            //*doc.openDataRegion("PO_company").setValue("北京卓正志远软件有限公司  " + id);
            //fmCtrl.setSaveFilePage("Save.jsp?id=" + id);
            //fmCtrl.setWriter(doc);
            WebPubFiles webPubFiles = webPubFilesService.selectWebPubFilesById(orderMultiFile.getFileId());
            fmCtrl.setJsFunction_OnProgressComplete("OnProgressComplete()");
            fmCtrl.fillDocument(webPubFiles.getDataDiskpath(), DocumentOpenType.Word);
        }
        map.put("pageoffice", fmCtrl.getHtmlCode("FileMakerCtrl"));
        map.put("printNumber", orderMultiFile.getPrintNumber());
        ModelAndView mv = new ModelAndView("/demo/pageoffice/printFiles");
        return mv;
    }

    //单个文件打印
    @RequestMapping(value = "/fileURL", method = RequestMethod.GET)
    public String fileURL(@PathParam("id") Integer id, @PathParam("printNumber") String printNumber, ModelMap mmap) {
        OrderMultiFile orderMultiFile = orderMultiFileService.selectOrderMultiFileById(id);
        orderMultiFile.setPrintNumber(printNumber);
        List orderMultiFileList = new ArrayList();
        orderMultiFileList.add(orderMultiFile);
        mmap.put("orderMultiFileList", orderMultiFileList);
        return "/demo/pageoffice/printDefault";
    }
}

4.HTML代码

一、单个文件的在线编辑打印保存




    
    
    
    


 

二、多个文件打印

(1).进度条页




    
    
    
    
    



 (2)、打印页




    
    
    
    
    
    


    
    

5.JS代码

 pageoffice有兼容问题要导入jquery.min.js和pageoffice.js

common.js主要放的是cookie的代码:

https://blog.csdn.net/qq_42307369/article/details/103157214




//打印全部单据
function printing(masterNo) {
    var url = ctx + "pageOffice" + "/filesURL?masterNo=" + masterNo;
    var printer = getCookie("tenglong_printer");
    if (printer == null) {
        if (tlprint == null) {
            setPrinter();
            return;
        }
        else {
            setCookie("tenglong_printer",tlprint);
        }
    }
    POBrowser.openWindowModeless(url, 'width=550px;height=350px;')
}


//单个文件打印
function prints(id,printNumber) {
    var url = ctx + "pageOffice" + "/fileURL?id=" + id+"&printNumber="+printNumber;
    POBrowser.openWindowModeless(url, 'width=550px;height=350px;')
}

//文件在线编辑
function onlineEditing(fileId) {
    var Identification = 1;
    var selectRows = $("#bootstrap-table").bootstrapTable('getSelections', function (row) {
        return row;
    });
    var url = ctx + "pageOffice" + "/onlineEditing?fid=" + fileId + "&Identification=" + Identification;
    POBrowser.openWindowModeless(url, 'width=' + width + ';height=' + height + ';')
}

//设置打印机
function setPrinter() {
    var url = ctx + "system/user/edit";
    layer.open({
        type: 1,
        area: ['300px', '140px'],
        //固定
        maxmin: false,
        shade: 0.3,
        title: '设置打印机',
        content: ""
            + "
" + "" + "
", btn: ['确定', '关闭'], // 弹层外区域关闭 shadeClose: true, yes: function (index, layero) { var printer = $("#printer").val(); setCookie("tenglong_printer", printer); layer.close(index); }, }); }

你可能感兴趣的:(#,卓正office)