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);
    }
}

打印效果

打印预览效果

在线预览效果

到此打印初步成体系

相关推荐
WaaTong11 分钟前
《重学Java设计模式》之 原型模式
java·设计模式·原型模式
m0_7430484411 分钟前
初识Java EE和Spring Boot
java·java-ee
AskHarries13 分钟前
Java字节码增强库ByteBuddy
java·后端
小灰灰__33 分钟前
IDEA加载通义灵码插件及使用指南
java·ide·intellij-idea
夜雨翦春韭36 分钟前
Java中的动态代理
java·开发语言·aop·动态代理
程序媛小果1 小时前
基于java+SpringBoot+Vue的宠物咖啡馆平台设计与实现
java·vue.js·spring boot
追风林1 小时前
mac m1 docker本地部署canal 监听mysql的binglog日志
java·docker·mac
芒果披萨1 小时前
El表达式和JSTL
java·el
duration~2 小时前
Maven随笔
java·maven
zmgst2 小时前
canal1.1.7使用canal-adapter进行mysql同步数据
java·数据库·mysql