JRT实现在线打印预览

在JRT打印元素绘制协议一篇已经介绍过打印把绘图和打印逻辑进行了分离,这是和老设计最大的不同。因为老的设计时候没想着做在线预览功能,是后面硬性扩出来的。这次从最初设计就考虑绘图逻辑各处共用,包括打印预览,在线打印预览等、后面还会再加PDF之类的。

总之:设计很重要,设计不到位后期功能难做,复杂度也会很高。

先看效果:
在这里插入图片描述

在这里插入图片描述

后台ashx对接绘图

import JRT.Core.Dto.OutValue;
import JRT.Core.MultiPlatform.FileCollection;
import JRT.Model.Bussiness.Parameters;
import JRTBLLBase.BaseHttpHandlerNoSession;
import JRTBLLBase.Helper;
import JRT.Core.Dto.HashParam;
import JRT.Core.Dto.ParamDto;
import JRT.Core.Dto.OutParam;
import JRT.Model.Entity.*;
import JRT.Core.Util.Convert;
import JRT.Core.MultiPlatform.JRTContext;
import JRTPrintDraw.DrawElement;
import JRTPrintDraw.JRTPrintDrawProtocol;
import JRTPrintDraw.JsonDealUtil;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.util.Base64;
import java.util.List;/*** 打印绘图在线预览的后台类,对接打印绘图库,由于打印元素绘制协议是完全剥离的,所以很好共用,这样体现了设计的优势*/
public class ashJRTPrintDrawView  extends BaseHttpHandlerNoSession {/*** 得到打印画图的图片。分页的话有多张图片,在C#层面对接,返回串自己在前面加data:image/png;base64,后给图片绑定。分页多个图的Base64串以^分隔* @return* @throws Exception*/public String QryPrintDrawImgs() throws Exception{//打印M类名String ClassName = Helper.ValidParam(JRTContext.GetRequest(Request,"ClassName"), "");//打印M方法名String FuncName = Helper.ValidParam(JRTContext.GetRequest(Request,"FuncName"), "");//绘图宽度int Width = Helper.ValidParam(JRTContext.GetRequest(Request,"Width"), 827);//绘图高度int Height = Helper.ValidParam(JRTContext.GetRequest(Request,"Height"), 583);//返回类型String RetType = "BASE64";//文件名String FileName = Helper.ValidParam(JRTContext.GetRequest(Request,"FileName"), "PrintImg.bmp");Parameters param = new Parameters();param.P0 = Helper.ValidParam(JRTContext.GetRequest(Request,"P0"), "");param.P1 = Helper.ValidParam(JRTContext.GetRequest(Request,"P1"), "");param.P2 = Helper.ValidParam(JRTContext.GetRequest(Request,"P2"), "");param.P3 = Helper.ValidParam(JRTContext.GetRequest(Request,"P3"), "");param.P4 = Helper.ValidParam(JRTContext.GetRequest(Request,"P4"), "");param.P5 = Helper.ValidParam(JRTContext.GetRequest(Request,"P5"), "");param.P6 = Helper.ValidParam(JRTContext.GetRequest(Request,"P6"), "");param.P7 = Helper.ValidParam(JRTContext.GetRequest(Request,"P7"), "");param.P8 = Helper.ValidParam(JRTContext.GetRequest(Request,"P8"), "");param.P9 = Helper.ValidParam(JRTContext.GetRequest(Request,"P9"), "");param.P10 = Helper.ValidParam(JRTContext.GetRequest(Request,"P10"), "");param.P11 = Helper.ValidParam(JRTContext.GetRequest(Request,"P11"), "");param.P12 = Helper.ValidParam(JRTContext.GetRequest(Request,"P12"), "");param.P13 = Helper.ValidParam(JRTContext.GetRequest(Request,"P13"), "");String strRet = "";int rowCount = 0;String logInfo = "^^^^";String json = Helper.GetVMData(ClassName, FuncName, param, null, null);List<DrawElement> elementList = JsonDealUtil.Json2List(json, DrawElement.class);JRTPrintDrawProtocol PrintHandeler = new JRTPrintDrawProtocol();int AllPageNum = PrintHandeler.JRTPrintDrawInit(elementList);for(int p=0;p<AllPageNum;p++){List<DrawElement> onePageData=PrintHandeler.GetOnePageData(p);float maxY = 0;for (int j = 0; j < onePageData.size(); j++){DrawElement curRow = onePageData.get(j);float PrintY = 0;if (!curRow.PrintY.isEmpty()){PrintY = Convert.ToFloat(curRow.PrintY);}if (maxY < PrintY){maxY = PrintY;}//图片元素if (curRow.PrintType.equals("Graph")){float PrintHeight = 0;if (!curRow.PrintHeight.isEmpty()){PrintHeight = Convert.ToFloat(curRow.PrintHeight);}if (maxY < PrintY+ PrintHeight){maxY = PrintY+ PrintHeight;}}//是外送文件if (curRow.PrintType.equals("FILE")){if (strRet.isEmpty()){strRet = curRow.DataField;}else{strRet = strRet + "~" + curRow.DataField;}}}//A4if (maxY > 583){Height = 1169;}BufferedImage img = new BufferedImage(Width, Height, BufferedImage.TYPE_INT_ARGB);Graphics g = img.getGraphics();g.setColor(Color.WHITE);g.fillRect(0, 0, img.getWidth(), img.getHeight());PrintHandeler.DrawOnePage(g, p);if (strRet.isEmpty()){strRet = ImgToBase64(img);}else{strRet = strRet + "~" + ImgToBase64(img);;}}return strRet;}/*** 图片转Base64串* @param img* @return* @throws Exception*/private String ImgToBase64(BufferedImage img) throws Exception {ByteArrayOutputStream baos = new ByteArrayOutputStream();ImageIO.write(img, "png", baos);byte[] bytes = baos.toByteArray();String base64Image = Base64.getEncoder().encodeToString(bytes);return base64Image;}
}

在线预览界面实现

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><title>打印绘图预览</title><script type="text/javascript">var sysTheme = '';</script><script src="../../resource/common/js/JRTBSBase.js" type="text/javascript"></script><script language="javascript" type="text/javascript">SYSPageCommonInfo.Init(true);var BasePath = '';var ResourcePath = '';var WebServicAddress = SYSPageCommonInfo.Data.WebServicAddress;var SessionStr = SYSPageCommonInfo.Data.SessionStr;</script><script src="../../jrtprint/js/JRTPrint.js" type="text/javascript"></script><style type="text/css">.btnMini {z-index:9999;position:relative;right:10px;top:0px;}</style><script type="text/javascript">//得到传入的打印主参数var PrintDR = requestUrlParam(location.href, "PrintDR").replace("#", "");//打印类名var PrintClassName = requestUrlParam(location.href, "PrintClassName").replace("#", "");//仅仅浏览模式var OnlyView = requestUrlParam(location.href, "OnlyView").replace("#", "");var UserDR = requestUrlParam(location.href, "UserDR").replace("#", "");var Align = requestUrlParam(location.href, "Align").replace("#", "");//显示顶部按钮var ShowTopBtn = requestUrlParam(location.href, "ShowTopBtn").replace("#", "");var userCode = UserDR;//1:报告处理打印 2:自助打印 3:医生打印var paramList = "1";//所有页面数var AllPageNum = 1;var AllPageArr = null;var AllPageBllIDArr = null;$(function () {if (OnlyView == "1") {//批量预览if (PrintDR == "") {PrintDR = localStorage["OnlyViewPrintDR"];}$("#btnPrint").hide();$("#btnPDF").hide();$("#btnPrintMini").remove();$("#btnPDFMini").remove();}//不显示顶部按钮if (ShowTopBtn == "0") {$("#divOper").hide();}else {$(".btnMini").hide();}//没传打印类的默认类if (PrintClassName == null || PrintClassName == "") {PrintClassName = "vm.test.PrintBarCodeTest";}if (Align == "Left") {$("#divOper").css("margin", "0 0 0 0");$("#divMian").css("margin", "0 0 0 0");}//打印$("#btnPrint").click(function () {InvokePrint("1");});$("#btnPrintMini").click(function () {InvokePrint("1");});//导出PDF$("#btnPDF").click(function () {InvokePrint("3");});$("#btnPDFMini").click(function () {InvokePrint("3");});//页数回车$("#txtCurPage").keydown(function (event) {if (event.keyCode == "13") {var curPage = $("#txtCurPage").val();var curPage = parseInt(curPage);if (curPage < 1) {curPage = 1;}if (curPage > AllPageNum) {curPage = AllPageNum;}ShowOnePage(curPage);}});//快捷键$(window).keydown(function (e) {if (e.key == "PageUp" || e.key == "ArrowUp") {PrePage();}else if (e.key == "ArrowLeft") {PrePage();}else if (e.key == "PageDown" || e.key == "ArrowDown") {NextPage();}else if (e.key == "ArrowRight") {NextPage();}else if (e.key == "F6") {UnCheckParent();}});//前一页$("#btnPrePage").click(function () {PrePage();});$("#btnPrePageMini").click(function () {PrePage();});//前一页function PrePage() {var curPage = $("#txtCurPage").val();var curPage = parseInt(curPage);curPage = curPage - 1;if (curPage < 1) {curPage = 1;}$("#txtCurPage").val(curPage);ShowOnePage(curPage);}//后一页$("#btnNextPage").click(function () {NextPage();});$("#btnNextPageMini").click(function () {NextPage();});//下一页function NextPage() {var curPage = $("#txtCurPage").val();var curPage = parseInt(curPage);curPage = curPage + 1;if (curPage > AllPageNum) {curPage = AllPageNum;}$("#txtCurPage").val(curPage);ShowOnePage(curPage);}//显示一页function ShowOnePage(curPage) {var imgStr = '';if ((AllPageArr[curPage - 1].toLowerCase().indexOf("../../") > -1) || (AllPageArr[curPage - 1].toLowerCase().indexOf("ftp://") > -1) || (AllPageArr[curPage - 1].toLowerCase().indexOf("http://") > -1) || (AllPageArr[curPage - 1].toLowerCase().indexOf("https://") > -1)) {if (curPage > 0) {imgStr += '<div style="font-weight:bold;color:#ff5252;">第' + curPage + '页</div><iframe src="' + DealPdfViewUrl(AllPageArr[curPage - 1]) + '"  style="margin-bottom:10px;width:827px;height:1189px;"/>';}else {imgStr += '<iframe src="' + DealPdfViewUrl(AllPageArr[curPage - 1]) + '"  style="margin-bottom:10px;width:827px;height:1189px;"/>';}}else {if (curPage > 0) {imgStr += '<div style="font-weight:bold;color:#ff5252;">第' + curPage + '页</div><img src="' + "data:image/png;base64," + AllPageArr[curPage - 1] + '" alt="报告" style="margin-bottom:10px;"/>';}else {imgStr += '<img src="' + "data:image/png;base64," + AllPageArr[curPage - 1] + '" alt="报告" style="margin-bottom:10px;"/>';}}$("#divMian").html(imgStr);}//校验参数if (PrintDR == "") {$("#spPage").html("没按要求传入PrintDR!");return;}//请求打印$.ajax({type: "get",dataType: "text", //text, json, xmlcache: false, //async: true, //为true时,异步,不等待后台返回值,为false时强制等待;-asirurl: '../ashx/ashJRTPrintDrawView.ashx?Method=QryPrintDrawImgs',data: { ClassName: PrintClassName, FuncName: "GetData", Width: 827, Height: 583, P0: PrintDR, P1: userCode, P2: paramList, RetBll: "1" },success: function (data) {AllPageArr = data.split("~");var imgStr = '';AllPageBllIDArr = [];for (var i = 0; i < AllPageArr.length; i++) {var onePage = AllPageArr[i];var onePageArr = onePage.split('^');var oneBll = "";if (onePageArr.length > 1) {oneBll = onePageArr[1];}AllPageBllIDArr.push(oneBll);AllPageArr[i] = onePageArr[0];}AllPageNum = AllPageArr.length;for (var i = 0; i < AllPageArr.length; i++) {if ((AllPageArr[i].toLowerCase().indexOf("../../") > -1) || (AllPageArr[i].toLowerCase().indexOf("ftp://") > -1) || (AllPageArr[i].toLowerCase().indexOf("http://") > -1) || (AllPageArr[i].toLowerCase().indexOf("https://") > -1)) {if (i > 0) {imgStr += '<div style="font-weight:bold;color:#ff5252;">第' + (i + 1) + '页</div><iframe src="' + DealPdfViewUrl(AllPageArr[i]) + '"  style="margin-bottom:10px;width:827px;height:1189px;"/>';}else {imgStr += '<iframe src="' + DealPdfViewUrl(AllPageArr[i]) + '"  style="margin-bottom:10px;width:827px;height:1189px;"/>';}}else {if (i > 0) {imgStr += '<div style="font-weight:bold;color:#ff5252;">第' + (i + 1) + '页</div><img src="' + "data:image/png;base64," + AllPageArr[i] + '" alt="报告" style="margin-bottom:10px;"/>';}else {imgStr += '<img src="' + "data:image/png;base64," + AllPageArr[i] + '" alt="报告" style="margin-bottom:10px;"/>';}}}$("#spPage").html("当前报告共(" + AllPageArr.length + ")页");$("#divMian").html(imgStr);}});$("#txtCurPage").focus();});//打印function InvokePrint(type) {//0:打印所有报告 1:循环打印每一份报告var printFlag = "0";var rowids = PrintDR;//打印用户 var userCode = UserDR;//PrintOut:打印  PrintPreview打印预览  PDF#地址  【0用户选  -1桌面  具体地址】//1:报告处理打印 2:自助打印 3:医生打印var paramList = "LIS";if (type == null || type == "1") {//PrintOut:打印  PrintPreview打印预览var printType = "PrintOut";}else if (type == "2") {//PrintOut:打印  PrintPreview打印预览var printType = "PrintPreview";}else if (type == "3") {//打印预览printType = "PDF#0";}var Param = printFlag + "@" + WebServicAddress + "@" + rowids + "@" + userCode + "@" + printType + "@" + paramList + "@" + PrintClassName + "@GetData";JRTBasePrint(Param);}</script>
</head>
<body><div id="divOper" style="margin: auto auto; width: 850px; background-color: #F5F5F5; text-align: center; padding-top: 5px; padding-bottom: 5px;"><a id="btnPrint" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-print',plain:true" style="margin-left: 10px;">打印</a>&nbsp&nbsp<a id="btnPDF" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-export',plain:true">导出PDF</a>&nbsp&nbsp<a id="btnPrePage" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-arrow-left',plain:true" title="PgLeft">上一页</a>&nbsp&nbsp<a id="btnNextPage" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-arrow-right',plain:true" title="PgRight">下一页</a>&nbsp&nbsp<input id="txtCurPage" type="text" style="width: 40px;" class="easyui-validatebox" value="1" />&nbsp&nbsp<span id="spPage" style="font-weight: bold; color: #ff793e; font-size: 14px;"></span><span style="font-weight: bold; color: #AAAAAA; font-size: 14px; float: right; margin-right: 10px;">JRT在线浏览</span></div><div style="margin: auto auto; width: 850px;text-align:center;"><div class="btnMini"><a id="btnPrintMini" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-print',plain:true" title="打印"></a><span class="jrtsp6>"></span><a id="btnPDFMini" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-export',plain:true" title="导出PDF"></a><span class="jrtsp6>"></span><a id="btnPrePageMini" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-arrow-left',plain:true" title="上一页[PgLeft]"></a><span class="jrtsp6>"></span><a id="btnNextPageMini" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-arrow-right',plain:true" title="下一页[PgRight]"></a><span class="jrtsp6>"></span></div><div id="divMian" style="margin: auto auto; width: 850px; background-color: #DDDDDD; text-align: center; padding-top: 10px;"></div></div></body>
</html>

其他页面使用
在这里插入图片描述

这样就可以实现在线预览功能,客户端不用环境也能进行打印预览,包括一些业务场景可以让用户看到图的效果,提高体验,也方便外部系统看一些报告和各种单据,只需要推送URL即可

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/282360.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

搭建自托管密码管理器

文章目录 背景准备工作服务器域名SSL 证书 开始安装 Docker安装 Docker Compose阿里云安装 Docker安装 Docker Compose 验证 起飞安装官方 Bitwarden修改配置文件 (端口号、SSL 证书等)(可选) 修改环境配置文件&#xff1a;启动 Bitwarden 服务验证所有容器是否正常运行 安装第…

STM32 DAC+串口

提示&#xff1a;文章写完后&#xff0c;目录可以自动生成&#xff0c;如何生成可参考右边的帮助文档 文章目录 前言一、DAC是什么&#xff1f;二、STM32 DAC1.什么型号有DAC2. 简介3. 主要特点4. DAC框图5. DAC 电压范围和引脚 三、程序步骤1. 开启DAC时钟2. 配置引脚 PA4 PA5…

Shell三剑客:sed(命令)一

一、删除命令&#xff1a;d [rootlocalhost ~]# sed -r /root/d passwd.txt bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin sync:x:5:0:sync:/sbin:/bin/sync…

gitlab 安装

1.安装依赖 sudo apt updatesudo apt-get upgradesudo apt-get install curl openssh-server ca-certificates postfix安装gitlab curl -s https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash官网下载安装包 要选ubuntu focal 安…

Linux环境下HTTP请求的代码详解与实例

嘿&#xff0c;Linux狂热者们&#xff0c;是时候让我们在这个充满激情的平台上探索一下HTTP协议的奥秘了。我知道&#xff0c;对于这个我们每天都在使用&#xff0c;但却可能没深入了解过的HTTP&#xff0c;你们一定充满了好奇和期待。那么&#xff0c;让我们一起踏上这趟探索之…

基于ssm线上学习网站论文

线上学习网站 摘要 随着信息技术在管理上越来越深入而广泛的应用&#xff0c;作为学校以及一些培训机构&#xff0c;都在用信息化战术来部署线上学习以及线上考试&#xff0c;可以与线下的考试有机的结合在一起&#xff0c;实现线上学习网站在技术上已成熟。本文介绍了线上学…

论文修改润色算学术不端吗 快码论文

大家好&#xff0c;今天来聊聊论文修改润色算学术不端吗&#xff0c;希望能给大家提供一点参考。 以下是针对论文重复率高的情况&#xff0c;提供一些修改建议和技巧&#xff0c;可以借助此类工具&#xff1a; 标题&#xff1a;论文修改润色是否算学术不端&#xff1f;专业软件…

gin使用自签名SSL证书与自签名证书不受信任方法解决

文章目录 1. X.509 V3证书介绍2、使用openssl生成自签名证书和解决不受信任问题2.1、生成根证书2.2、为域名生成证书申请文件2.3、为域名创建证书的扩展描述文件2.4、为域名创建证书 3、Go应用中使用自签名证书3.1、gin框架调用实现3.2、运行效果 4、使用java的bouncycastle生成…

C语言——预处理详解(#define用法+注意事项)

#define 语法规定 #define定义标识符 语法: #define name stuff #define例子 #include<stdio.h> #define A 100 #define STR "abc" #define FOR for(;;)int main() {printf("%d\n", A);printf("%s\n", STR);FOR;return 0; } 运行结果…

设计可编辑表格组件

前言 什么是可编辑表格呢&#xff1f;简单来说就是在一个表格里面进行表单操作&#xff0c;执行增删改查。这在一些后台管理系统中是尤为常见的。 今天我们根据vue2 element-ui来设计一个表单表格组件。&#xff08;不涉及完整代码&#xff0c;想要使用完整功能可以看底部连…

【C语言】实战项目——通讯录

引言 学会创建一个通讯录&#xff0c;对过往知识进行加深和巩固。 文章很长&#xff0c;要耐心学完哦&#xff01; ✨ 猪巴戒&#xff1a;个人主页✨ 所属专栏&#xff1a;《C语言进阶》 &#x1f388;跟着猪巴戒&#xff0c;一起学习C语言&#x1f388; 目录 引言 实战 建…

使用Audition录制电脑内部声音

在电脑上播放的媒体文件&#xff0c;包括视频和声音&#xff0c;很多是可以播放却无法保存的。例如一些网页播放的视频&#xff0c;或者在线播放的音乐。 视频的话&#xff0c;可以使用工具来截图&#xff0c;抓取GIF或录屏。 声音的话&#xff0c;也可以使用工具进行录制。这里…