打印不光要能打印内部的单据,对于检验的打印还有外送回传的PDF报告也需要能够打印,所以需要把打印PDF文件整合进来,为此给打印元素绘制协议增加PDF类型的元素。
定义如下,由绘制协议按地址下载文件后和其他打印元素整合:
/**
* 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;
}
打印示例
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);
}
}
到此打印初步成体系