JRT打印元素绘制协议整合PDF

打印不光要能打印内部的单据,对于检验的打印还有外送回传的PDF报告也需要能够打印,所以需要把打印PDF文件整合进来,为此给打印元素绘制协议增加PDF类型的元素。

定义如下,由绘制协议按地址下载文件后和其他打印元素整合:

java 复制代码
/**
     * PDF文件的ftp或http全路径。用英文逗号分隔两个A5PDF路径打印会自动合并为一个A4。一个A5路径后跟个英文逗号,会把PDF转A4纸打印,会把PDF每页提取成大图当一页打印
     *
     * @param httpOrFtpPath pdf文件的下载路径
     * @return
     */
    public static PrintElement DrawPDF(String httpOrFtpPath) {
        PrintElement ret = new PrintElement();
        ret.DataField = httpOrFtpPath;
        ret.PrintType = "PDF";
        return ret;
    }

整合协议

PDF文件在文件服务放一个

打印示例

java 复制代码
import JRT.Core.Dto.OutParam;
import JRT.Core.Dto.OutValue;
import JRT.Core.Dto.PrintElement;
import JRT.Core.Util.PrintDrawProtocol;
import JRTBLLBase.BaseHttpHandlerNoSession;
import JRTBLLBase.Helper;

import java.awt.*;
import java.util.ArrayList;
import java.util.List;

/**
 * 输出符合打印元素绘制协议的打印元素数据,来供打印执行层打印
 */
public class PrintBarCodeTest extends BaseHttpHandlerNoSession {
    /**
     * 按传入的RowID输出符合打印元素绘制协议的数据来实现打印控制
     * @param RowID 业务主键
     * @param P1
     * @param P2
     * @param P3
     * @param P4
     * @param P5
     * @param P6
     * @param P7
     * @param P8
     * @param P9
     * @param P10
     * @param P11
     * @param P12
     * @param P13
     * @param Session
     * @param Output
     * @return
     */
    public String GetData(String RowID, String P1, String P2, String P3, String P4, String P5, String P6, String P7, String P8, String P9, String P10, String P11, String P12, String P13, OutValue Session, OutValue Output) throws  Exception{
        List<PrintElement> retList=new ArrayList<>();
        //打印PDF文件
        //retList.add(PrintDrawProtocol.DrawFile("http://localhost:8080/JRTWeb/FileService/test.pdf"));
        retList.add(PrintDrawProtocol.DrawPDF("http://localhost:8080/JRTWeb/FileService/test.pdf"));
        //画logo
        retList.add(PrintDrawProtocol.DrawLabel(420,10,"logn图","宋体",12,"", null,"","0"));
        retList.add(PrintDrawProtocol.DrawGraph(420,20,64,64,"http://localhost:8080/JRTWeb/FileService/logo.png",false));
        //画一个文本
        retList.add(PrintDrawProtocol.DrawLabel(20,20,"zhanglianzhu","宋体",12,"", null,"","0"));
        //画一个条码
        retList.add(PrintDrawProtocol.DrawBarCode(20,50,"0947809",true,5,30,"","宋体",12,"",null,"","0"));
        //换一根横线
        retList.add(PrintDrawProtocol.DrawLine(20,70,70,70,1,"",""));
        //换一根竖线
        retList.add(PrintDrawProtocol.DrawLine(50,10,50,470,1,"",""));
        //绘制一个条码
        retList.add(PrintDrawProtocol.DrawQRCode(20,90,"jbase",90,90));
        //绘制一个条码
        retList.add(PrintDrawProtocol.DrawLabel(20,210,"jbase打印支持","宋体",12,"",null,"","0"));
        //绘制一个条码
        retList.add(PrintDrawProtocol.DrawLabel(20,230,"20231118 22:49","宋体",12,"",null,"","0"));
        //画一个点
        retList.add(PrintDrawProtocol.DrawPoint(20,270,10,10,"o",""));
        retList.add(PrintDrawProtocol.DrawPoint(100,270,10,10,"[]",""));
        retList.add(PrintDrawProtocol.DrawPoint(200,270,10,10,"<>",""));
        //画多边形
        List<Point> pointList=new ArrayList<>();
        Point p1=new Point();
        p1.x=10;
        p1.y=300;
        pointList.add(p1);
        Point p2=new Point();
        p2.x=100;
        p2.y=310;
        pointList.add(p2);
        Point p3=new Point();
        p3.x=50;
        p3.y=360;
        pointList.add(p3);
        retList.add(PrintDrawProtocol.DrawPoly(pointList,""));
        //画复选框
        retList.add(PrintDrawProtocol.DrawCheckBox(10,400,true,30,30));
        //画单选框
        retList.add(PrintDrawProtocol.DrawRadio(60,400,true,30,30));
        //画复选框
        retList.add(PrintDrawProtocol.DrawCheckBox(110,400,false,30,30));
        //画单选框
        retList.add(PrintDrawProtocol.DrawRadio(160,400,false,30,30));

        //换页
        retList.add(PrintDrawProtocol.ChangePage());

        //画logo
        retList.add(PrintDrawProtocol.DrawLabel(420,10,"logn图","宋体",12,"", null,"","0"));
        retList.add(PrintDrawProtocol.DrawGraph(420,20,64,64,"http://localhost:8080/JRTWeb/FileService/logo.png",false));
        //画一个文本
        retList.add(PrintDrawProtocol.DrawLabel(10,10,"这是打印的第二页","宋体",12,"", null,"","0"));
        //画一个条码
        retList.add(PrintDrawProtocol.DrawBarCode(10,50,"0947809",true,5,30,"","宋体",12,"",null,"","0"));
        //换一根横线
        retList.add(PrintDrawProtocol.DrawLine(10,70,70,70,1,"",""));
        //换一根竖线
        retList.add(PrintDrawProtocol.DrawLine(50,10,50,470,1,"",""));
        //绘制一个条码
        retList.add(PrintDrawProtocol.DrawQRCode(10,90,"jbase",90,90));
        //绘制一个条码
        retList.add(PrintDrawProtocol.DrawLabel(10,210,"jbase打印支持","宋体",12,"",null,"","0"));
        //绘制一个条码
        retList.add(PrintDrawProtocol.DrawLabel(10,230,"20231119","宋体",12,"",null,"","0"));

        //换页
        retList.add(PrintDrawProtocol.ChangePage());
        //画logo
        retList.add(PrintDrawProtocol.DrawLabel(420,10,"logn图","宋体",12,"", null,"","0"));
        retList.add(PrintDrawProtocol.DrawGraph(420,20,64,64,"http://localhost:8080/JRTWeb/FileService/logo.png",false));
        //画一个文本
        retList.add(PrintDrawProtocol.DrawLabel(10,10,"这是打印的第三页","宋体",12,"", null,"","0"));
        //画一个条码
        retList.add(PrintDrawProtocol.DrawBarCode(10,50,"0947809",true,5,30,"","宋体",12,"",null,"","0"));
        //换一根横线
        retList.add(PrintDrawProtocol.DrawLine(10,70,70,70,1,"",""));
        //换一根竖线
        retList.add(PrintDrawProtocol.DrawLine(50,10,50,470,1,"",""));
        //绘制一个条码
        retList.add(PrintDrawProtocol.DrawQRCode(10,90,"jbase",90,90));
        //绘制一个条码
        retList.add(PrintDrawProtocol.DrawLabel(10,210,"jbase打印支持","宋体",12,"",null,"","0"));
        //绘制一个条码
        retList.add(PrintDrawProtocol.DrawLabel(10,230,"20231119","宋体",12,"",null,"","0"));

        //换页
        retList.add(PrintDrawProtocol.ChangePage());
        //画logo
        retList.add(PrintDrawProtocol.DrawLabel(420,10,"logn图","宋体",12,"", null,"","0"));
        retList.add(PrintDrawProtocol.DrawGraph(420,20,64,64,"http://localhost:8080/JRTWeb/FileService/logo.png",false));
        //画一个文本
        retList.add(PrintDrawProtocol.DrawLabel(10,10,"这是打印的第四页","宋体",12,"", null,"","0"));
        //画一个条码
        retList.add(PrintDrawProtocol.DrawBarCode(10,50,"0947809",true,5,30,"","宋体",12,"",null,"","0"));
        //换一根横线
        retList.add(PrintDrawProtocol.DrawLine(10,70,70,70,1,"",""));
        //换一根竖线
        retList.add(PrintDrawProtocol.DrawLine(50,10,50,470,1,"",""));
        //绘制一个条码
        retList.add(PrintDrawProtocol.DrawQRCode(10,90,"jbase",90,90));
        //绘制一个条码
        retList.add(PrintDrawProtocol.DrawLabel(10,210,"jbase打印支持","宋体",12,"",null,"","0"));
        //绘制一个条码
        retList.add(PrintDrawProtocol.DrawLabel(10,230,"20231206","宋体",12,"",null,"","0"));

        //先包一个打印元素绘制协议数据生成的工具类来解决元素约束问题,工具类实现了调用工具类得到标签,条码,文本等
        return Helper.Object2Json(retList);
    }
}

打印效果

打印预览效果

在线预览效果

到此打印初步成体系

相关推荐
桂月二二2 小时前
Java与容器化:如何使用Docker和Kubernetes优化Java应用的部署
java·docker·kubernetes
liuxin334455662 小时前
学籍管理系统:实现教育管理现代化
java·开发语言·前端·数据库·安全
小马爱打代码2 小时前
设计模式详解(建造者模式)
java·设计模式·建造者模式
栗子~~3 小时前
idea 8年使用整理
java·ide·intellij-idea
2301_801483693 小时前
Maven核心概念
java·maven
Q_19284999063 小时前
基于Spring Boot的电影售票系统
java·spring boot·后端
我要学编程(ಥ_ಥ)4 小时前
初始JavaEE篇 —— 网络原理---传输层协议:深入理解UDP/TCP
java·网络·tcp/ip·udp·java-ee
就爱学编程4 小时前
重生之我在异世界学编程之C语言:数据在内存中的存储篇(下)
java·服务器·c语言
yuanbenshidiaos4 小时前
C++--------------树
java·数据库·c++
俎树振5 小时前
Java数组深入解析:定义、操作、常见问题与高频练习
java·开发语言