Skip to content
printForm2.jsp 5.15 KiB
Newer Older
杨郁彬's avatar
杨郁彬 committed
<!DOCTYPE html>
<html>
<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<%
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath();
    pageContext.setAttribute("basePath", basePath);
%>
<head>
    <title>文件查看</title>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <script type="text/javascript">
        var _ctx = '${ctx}';
    </script>
    <script src="${ctx}/static/jquery-cui/js/jquery-1.9.1.min.js"></script>
    <script src="${ctx}/static/suwell/suwell_ofdReader.js"></script>
    <style type="text/css">
        html, body {
            height: 100%;
            width: 100%;
            padding: 0;
            margin: 0;
        }

        .readOnly {
            pointer-events: none;
            filter: alpha(opacity=50); /*IE滤镜,透明度50%*/
            -moz-opacity: 0.5; /*Firefox私有,透明度50%*/
            opacity: 0.5; /*其他,透明度50%*/
            text-decoration: line-through;
            color: darkgrey;
        }

        a {
            color: #000000;
            border: 1px solid #818181;
            background-image: url(${ctx}/static/cm/image/btn-bg.png);
            padding: 4px 15px;
            border-radius: 2px;
            margin: 0px 4px;
            text-decoration: none;
        }
    </style>
</head>
<body>
<div style="text-align: left;width: 100%;height: 100%;">
    <div id="tools" style="height: 40px;padding-top: 5px;">
        <div class="buttens-foot-tools" style="margin: auto">

            <a href="${ctx}/stamp/downloadFiles?attachmentId=${attachmentId}" target="_blank">下载</a>
            <%--<a href="javascript:;" onclick="fileSaveTest()" id="refreshRed">保存</a>--%>
        </div>
    </div>
    <div id="ofdReader" style="">

    </div>
    <script type="text/javascript">
        //var exampleOfdUrl ='D:\\upload\\201909\\c4889422-254a-4f40-9666-3c7486316d6a.ofd';
        var ocx = null;
        var attachmentId = '${attachmentId}';
        var businessId = '${businessId}';
        var exampleOfdUrl = '${basePath}/attachment/viewOfd/${attachmentId}';
        var uploadOFDUrl = '${basePath}/attachment/uploadOnlyOneDZYZ/${attachmentId}';

        $(function () {
            init();
            if (ocx) {
                ocx.setCompsiteVisible('f_open', false);//隐藏【打开】菜单
                ocx.setCompsiteVisible('f_save', false);//隐藏【保存】菜单
                ocx.setCompsiteVisible('f_print', false);//隐藏【打印】菜单
                //ocx.setCompsiteVisible('f_saveas', false);//显示【另保存】菜单
                //ocx.setCompsiteVisible('t_sealsign', false);//隐藏【签章工具栏】   //需要打开电子签章这行要注释
                ocx.setConfigInfo('print_fast_checked', false);//“快速打印”不勾选
                openFile(exampleOfdUrl, true);

                // ocx.setPrintCompsiteEnable('copies', false);
                // registListener('f_print', 'beforePrint', false);
                registListener('f_print', 'afterPrint', true);
            }
        });

        /**
         * 初始化插件
         */
        function init() {
            var width = $('body').width();
            var height = $('body').height() - $('#tools').height();
            console.log('width:' + width + ',height:' + height);
            ocx = suwell.ofdReaderInit('ofdReader', width, height);
        }


        function openExample() {
            openFile(exampleOfdUrl, true);
        }

        /**
         * 打开文件
         * @param path string型,欲打开的本地文件路径、http链接或ftp文件路径。
         * @param readOnly boolean,是否只读模式打开。
         * @returns boolean 成功返回true,否则返回false。
         */
        function openFile(path, readOnly) {
            //var b = ocx.openFile(path, readOnly);
            var b = ocx.openFile(path, readOnly); //需要打开电子签章这行readOnly要改成false
            return b;
        }

        function registListener(commandId, functionName, after) {
            ocx.registListener(commandId, functionName, after);
        }

        function beforePrint(param) {
            console.log('打印前', param);
        }

        function afterPrint() {
            $.ajax({
                type: 'GET',
                url: '${ctx}/print-num/updatePrintNum?attachmentId=' + attachmentId + '&businessId=' + businessId,
                dataType: 'json',
                success: function (data) {
                    if (data) {
                        initPrintTimes();
                    }
                }
            });
        }

        function printFile() {
            ocx.printFile('', false);
            debugger;

        }

        function printFileCopies() {
            ocx.printFileCopies(1);
        }

        function fileSaveTest() {
            console.log("上传文件1111");
            ocx.saveFile(uploadOFDUrl)
            //location.href=path;
        }
    </script>
</body>
</html>