JRT打印预览实现

news2025/1/24 5:48:56

JRT客户端部分已经实现了打印、导出Excel部分,之前没实现打印预览部分,因为要自己写打印预览界面,所以留到最后做,经过两晚的努力,实现了打印预览。

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

在这里插入图片描述

在这里插入图片描述

打印预览界面代码

package Monitor.Print;

import javafx.application.Platform;
import javafx.embed.swing.SwingFXUtils;
import javafx.geometry.Insets;
import javafx.geometry.Orientation;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.TextField;
import javafx.scene.image.ImageView;
import javafx.scene.layout.*;
import javafx.scene.text.Text;
import javafx.stage.Modality;
import javafx.stage.Stage;
import Monitor.Print.PrintProtocol;

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

import javafx.scene.image.Image;

/**
 * 实现打印预览的弹窗和逻辑
 */
public class PrintPreview {
    /**
     * 舞台
     */
    private Stage curStage = null;


    /**
     * 操作打印协议的对象
     */
    private PrintProtocol printProtocol = null;

    /**
     * 当前所在页
     */
    TextField txtCurPage = new TextField();

    /**
     * 放预览图片
     */
    FlowPane bottom = new FlowPane(500, 1);

    /**
     * 打印预览构造函数
     *
     * @param oper
     */
    public PrintPreview(PrintProtocol oper) {
        printProtocol = oper;
        // 创建新的Stage对象,设置标题和尺寸
        curStage = new Stage();
        curStage.setTitle("打印预览-由JRT计划提供");
        curStage.setWidth(1366);
        curStage.setHeight(768);

        SplitPane splitPane = new SplitPane();
        splitPane.setOrientation(Orientation.VERTICAL);

        // 打印当前页
        Button btnPrintCur = new Button("打印当前页");
        btnPrintCur.setStyle("-fx-background-color: #6abfef;");
        btnPrintCur.setOnMouseClicked(e -> {
            try {
                String curPage = txtCurPage.getText();
                List<Integer> pages = new ArrayList<>();
                pages.add(Integer.valueOf(curPage) - 1);
                oper.SetPrintPage(pages);
                oper.PrintOnece();
            } catch (Exception ex) {
                Alert alert = new Alert(Alert.AlertType.INFORMATION);
                alert.setTitle("提示");
                alert.setContentText(ex.getMessage());
                alert.showAndWait();
            }
        });
        btnPrintCur.setPrefHeight(26);

        // 打印全部
        Button btnPrintAll = new Button("打印全部");
        btnPrintAll.setStyle("-fx-background-color: #6abfef;");
        btnPrintAll.setOnMouseClicked(e -> {
            try {
                List<Integer> pages = new ArrayList<>();
                for (int i = 0; i < oper.AllPageNum; i++) {
                    pages.add(i);
                }
                oper.SetPrintPage(pages);
                oper.PrintOnece();
                Hide();
            } catch (Exception ex) {
                Alert alert = new Alert(Alert.AlertType.INFORMATION);
                alert.setTitle("提示");
                alert.setContentText(ex.getMessage());
                alert.showAndWait();
            }
        });
        btnPrintAll.setPrefHeight(26);


        // 打印奇数页
        Button btnPrintOdd = new Button("打印奇数页");
        btnPrintOdd.setStyle("-fx-background-color: #6abfef;");
        btnPrintOdd.setOnMouseClicked(e -> {
            try {
                List<Integer> pages = new ArrayList<>();
                for (int i = 0; i < oper.AllPageNum; i++) {
                    if (i % 2 == 0) {
                        pages.add(i);
                    }
                }
                oper.SetPrintPage(pages);
                oper.PrintOnece();
                Hide();
            } catch (Exception ex) {
                Alert alert = new Alert(Alert.AlertType.INFORMATION);
                alert.setTitle("提示");
                alert.setContentText(ex.getMessage());
                alert.showAndWait();
            }
        });
        btnPrintOdd.setPrefHeight(26);

        // 打印偶数页
        Button btnPrintEven = new Button("打印偶数页");
        btnPrintEven.setStyle("-fx-background-color: #6abfef;");
        btnPrintEven.setOnMouseClicked(e -> {
            try {
                List<Integer> pages = new ArrayList<>();
                for (int i = 0; i < oper.AllPageNum; i++) {
                    if (i % 2 == 1) {
                        pages.add(i);
                    }
                }
                oper.SetPrintPage(pages);
                oper.PrintOnece();
                Hide();
            } catch (Exception ex) {
                Alert alert = new Alert(Alert.AlertType.INFORMATION);
                alert.setTitle("提示");
                alert.setContentText(ex.getMessage());
                alert.showAndWait();
            }
        });
        btnPrintEven.setPrefHeight(26);

        // 打印偶数页逆序
        Button btnPrintEvenRevert = new Button("打印偶逆序");
        btnPrintEvenRevert.setStyle("-fx-background-color: #6abfef;");
        btnPrintEvenRevert.setOnMouseClicked(e -> {
            try {
                List<Integer> pages = new ArrayList<>();
                for (int i = oper.AllPageNum - 1; i >= 0; i--) {
                    if (i % 2 == 1) {
                        pages.add(i);
                    }
                }
                oper.SetPrintPage(pages);
                oper.PrintOnece();
                Hide();
            } catch (Exception ex) {
                Alert alert = new Alert(Alert.AlertType.INFORMATION);
                alert.setTitle("提示");
                alert.setContentText(ex.getMessage());
                alert.showAndWait();
            }
        });
        btnPrintEvenRevert.setPrefHeight(26);

        //打印开始页
        TextField txtStart = new TextField();
        txtStart.setPrefWidth(60);
        txtStart.setPrefHeight(26);

        //分割字符
        Label lab = new Label("-");

        //打印结束页
        TextField txtEnd = new TextField();
        txtEnd.setPrefWidth(60);
        txtEnd.setPrefHeight(26);

        // 范围打印
        Button btnPrintRange = new Button("范围打印");
        btnPrintRange.setStyle("-fx-background-color: #6abfef;");
        btnPrintRange.setOnMouseClicked(e -> {
            try {
                String start = txtStart.getText();
                String end = txtEnd.getText();
                int startInt = Integer.valueOf(start) - 1;
                int endInt = Integer.valueOf(end) - 1;
                List<Integer> pages = new ArrayList<>();
                for (int i = 0; i < oper.AllPageNum; i++) {
                    if (i >= startInt && i <= endInt) {
                        pages.add(i);
                    }
                }
                oper.SetPrintPage(pages);
                oper.PrintOnece();
                Hide();
            } catch (Exception ex) {
                Alert alert = new Alert(Alert.AlertType.INFORMATION);
                alert.setTitle("提示");
                alert.setContentText(ex.getMessage());
                alert.showAndWait();
            }
        });
        btnPrintRange.setPrefHeight(26);

        // 打印设置
        Button btnPrintSetting = new Button("打印设置");
        btnPrintSetting.setStyle("-fx-background-color: #449be2;");
        btnPrintSetting.setOnMouseClicked(e -> {
            oper.job.printDialog();
        });
        btnPrintSetting.setPrefHeight(26);

        //当前页
        txtCurPage.setPrefWidth(30);
        txtCurPage.setText("1");
        txtCurPage.setPrefHeight(26);

        //所有页
        Label labAllPage = new Label("/" + oper.AllPageNum);
        labAllPage.setPrefHeight(26);

        // 上一页
        Button btnPrev = new Button("上一页");
        btnPrev.setStyle("-fx-background-color: #39c6c8;");
        btnPrev.setOnMouseClicked(e -> {
            try {
                String curPage = txtCurPage.getText();
                int curPageInt = Integer.valueOf(curPage);
                curPageInt--;
                if (curPageInt < 1 || curPageInt > oper.AllPageNum) {
                    return;
                }
                txtCurPage.setText(curPageInt + "");
                BufferedImage img = new BufferedImage(867, 1169, BufferedImage.TYPE_INT_ARGB);
                Graphics g = img.getGraphics();
                g.setColor(Color.WHITE);
                g.fillRect(0, 0, img.getWidth(), img.getHeight());
                oper.PrintHandeler.DrawOnePage(g, curPageInt - 1);
                Image image = SwingFXUtils.toFXImage(img, null);
                ImageView onePage = new ImageView(image);
                bottom.getChildren().clear();
                bottom.getChildren().add(onePage);
            } catch (Exception ex) {
                Alert alert = new Alert(Alert.AlertType.INFORMATION);
                alert.setTitle("提示");
                alert.setContentText(ex.getMessage());
                alert.showAndWait();
            }
        });
        btnPrev.setPrefHeight(26);

        // 下一页
        Button btnNext = new Button("下一页");
        btnNext.setStyle("-fx-background-color: #39c6c8;");
        btnNext.setOnMouseClicked(e -> {
            try {
                String curPage = txtCurPage.getText();
                int curPageInt = Integer.valueOf(curPage);
                curPageInt++;
                if (curPageInt < 1 || curPageInt > oper.AllPageNum) {
                    return;
                }
                txtCurPage.setText(curPageInt + "");

                BufferedImage img = new BufferedImage(867, 1169, BufferedImage.TYPE_INT_ARGB);
                Graphics g = img.getGraphics();
                g.setColor(Color.WHITE);
                g.fillRect(0, 0, img.getWidth(), img.getHeight());
                oper.PrintHandeler.DrawOnePage(g, curPageInt - 1);
                Image image = SwingFXUtils.toFXImage(img, null);
                ImageView onePage = new ImageView(image);
                bottom.getChildren().clear();
                bottom.getChildren().add(onePage);
            } catch (Exception ex) {
                Alert alert = new Alert(Alert.AlertType.INFORMATION);
                alert.setTitle("提示");
                alert.setContentText(ex.getMessage());
                alert.showAndWait();
            }
        });
        btnNext.setPrefHeight(26);


        HBox top = new HBox(20, btnPrintCur, btnPrintAll, btnPrintOdd, btnPrintEven, btnPrintEvenRevert, txtStart, lab, txtEnd, btnPrintRange, btnPrintSetting, txtCurPage, labAllPage, btnPrev, btnNext);
        top.setPadding(new Insets(5, 5, 5, 15));
        top.setPrefHeight(40);
        top.setMaxHeight(40);

        bottom.setAlignment(Pos.CENTER);
        bottom.setPadding(new Insets(10, 10, 10, 15));
        // 创建一个ScrollPane
        ScrollPane scrollPane = new ScrollPane();
        // 设置滚动条的可见性为自动
        //scrollPane.setScrollbarsVisible(true);
        scrollPane.setContent(bottom);
        //画每页的图
        if (oper.AllPageNum > 0) {
            for (int i = 0; i < oper.AllPageNum; i++) {
                try {
                    BufferedImage img = new BufferedImage(867, 1169, BufferedImage.TYPE_INT_ARGB);
                    Graphics g = img.getGraphics();
                    g.setColor(Color.WHITE);
                    g.fillRect(0, 0, img.getWidth(), img.getHeight());
                    oper.PrintHandeler.DrawOnePage(g, i);
                    Image image = SwingFXUtils.toFXImage(img, null);
                    ImageView onePage = new ImageView(image);
                    Label labSP = new Label("---第" + (i + 1) + "页---");
                    bottom.getChildren().add(labSP);
                    bottom.getChildren().add(onePage);

                } catch (Exception ex) {
                    // 弹出一个信息对话框
                    Alert alert = new Alert(Alert.AlertType.INFORMATION);
                    alert.setTitle("提示");
                    alert.setHeaderText(null);
                    alert.setContentText(ex.getMessage());
                }
            }
        }

        //bottom.setBackground(new Background(new BackgroundFill(Color.WHITE, new CornerRadii(10), new Insets(10))));
        splitPane.getItems().addAll(top, scrollPane);
        Scene scene = new Scene(splitPane);
        splitPane.setStyle("-fx-background-color: #FAFAFA;");
        curStage.setOnCloseRequest(event -> {
            try {

            } catch (Exception ex) {

            }
        });
        curStage.setScene(scene);
        curStage.setMaximized(true);
        curStage.setAlwaysOnTop(true);
    }

    /**
     * 隐藏
     */
    private void Hide() {
        Platform.runLater(() -> {
            curStage.hide();
        });
    }

    /**
     * 展示
     */
    public void Show() {
        curStage.showAndWait();
    }
}

打印控制类调整

package Monitor.Print;

import JRTPrintDraw.DrawConvert;
import JRTPrintDraw.DrawElement;
import JRTPrintDraw.JRTPrintDrawProtocol;
import JRTPrintDraw.JsonDealUtil;
import JRTPrintDraw.WebService.Parameters;
import Monitor.Print.PrintPreview;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import javafx.application.Platform;
import javafx.scene.control.Alert;

import javax.print.DocFlavor;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.standard.Media;
import javax.print.attribute.standard.MediaSizeName;
import javax.print.attribute.standard.MediaTray;
import java.awt.*;
import java.awt.print.*;
import java.util.ArrayList;
import java.util.List;

public class PrintProtocol implements Printable {
    /**
     * 纸张名称
     */
    private String PageName;

    /**
     * 打印句柄
     */
    public JRTPrintDrawProtocol PrintHandeler = null;

    /**
     * 所有页数
     */
    public int AllPageNum = 0;

    /**
     * 通俗理解就是书、文档
     */
    private Book book = new Book();

    /**
     * 获取打印服务对象
     */
    PrinterJob job = PrinterJob.getPrinterJob();

    /**
     * 设置成竖打
     */
    PageFormat pf = new PageFormat();

    /**
     * 得到打印机
     *
     * @param printerName
     * @return
     */
    public static PrintService GetPrinter(String printerName) {

        DocFlavor psInFormat = DocFlavor.INPUT_STREAM.AUTOSENSE;
        HashPrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
        PrintService printService[] = PrintServiceLookup.lookupPrintServices(psInFormat, pras);
        PrintService myPrinter = null;
        //遍历所有打印机如果没有选择打印机或找不到该打印机则调用默认打印机
        for (PrintService printService2 : printService) {
            String svcName = printService2.toString();
            if (svcName.contains(printerName)) {
                myPrinter = printService2;
                break;
            }
        }
        if (myPrinter == null) {
            myPrinter = PrintServiceLookup.lookupDefaultPrintService();
            return myPrinter;
        }
        return myPrinter;
    }

    /**
     * 按打印元素绘制协议实现打印
     *
     * @param rowids        数据主键
     * @param userCode      用户
     * @param paramList     参数
     * @param connectString 连接串
     * @param printFlag     打印标识
     * @param className     调用类名
     * @param funcName      方法名称
     */
    public PrintProtocol(String rowids, String userCode, String paramList, String connectString, String printFlag, String className, String funcName) throws Exception {
        try {
            Parameters para = new Parameters();
            para.P0 = rowids;
            para.P1 = userCode;
            para.P2 = paramList;
            para.P3 = rowids;
            String json = JRTPrintDraw.WebService.WebGetData.GetData(connectString, className, funcName, para, null);
            List<DrawElement> elementList = JsonDealUtil.Json2List(json, DrawElement.class);

            PrintHandeler = new JRTPrintDrawProtocol();
            AllPageNum = PrintHandeler.JRTPrintDrawInit(elementList);

            // 设置打印类
            job.setPageable(book);

            pf.setOrientation(PageFormat.PORTRAIT);
            boolean hasSetPaper = false;
            //控制打印机的数据
            if (elementList.get(0).PrintType.contains("PRINTER")) {
                DrawElement dr = elementList.get(0);
                //打印机名称
                String tPrinterName = elementList.get(0).PrintFlag;
                //选择打印机
                if (tPrinterName != null && !tPrinterName.isEmpty()) {
                    PrintService printService = GetPrinter(tPrinterName);
                    job.setPrintService(printService);
                }
                //设置打印机其他参数
                if (dr.PrintType.equals("PRINTER")) {
                    //设置打印机宽度
                    int PrinterWidth = DrawConvert.ToInt32(dr.PrintWidth);
                    //设置打印机高度
                    int PrinterHeight = DrawConvert.ToInt32(dr.PrintHeight);
                    PrintHandeler.WriteLog("PRINTER得到纸张宽高:" + PrinterWidth + " " + PrinterHeight);
                    //页面名称
                    PageName = dr.DataField;
                    //停靠
                    String ReportLayout = dr.PrintAlignment;
                    PrintHandeler.WriteLog("PRINTER得打印机名称:" + tPrinterName);
                    //指定打印机送纸来源
                    int iPaperSource = DrawConvert.ToInt32(dr.PrintFont);
                    if (ReportLayout == "Landscape") {
                        pf.setOrientation(PageFormat.LANDSCAPE);
                        PrintHandeler.WriteLog("PRINTER旋转纸张:Landscape");
                    }
                    //宽高大于0就控制
                    if (PrinterWidth > 0 && PrinterHeight > 0) {
                        //通过Paper设置页面的空白边距和可打印区域。必须与实际打印纸张大小相符。
                        Paper paper = new Paper();
                        // 设置纸张大小为 A4 大小(210 mm × 297 mm)
                        int width = PrinterWidth;
                        int height = PrinterHeight;
                        //旋转
                        if (ReportLayout == "Landscape") {
                            int tmp = width;
                            width = height;
                            height = tmp;
                        }
                        double margin = 0;
                        paper.setSize(width, height);
                        paper.setImageableArea(margin, margin, width - 2 * margin, height - 2 * margin);
                        pf.setPaper(paper);
                        hasSetPaper = true;

                    }
                }
            }
            if (hasSetPaper == false) {
                Paper paper = new Paper();
                // 设置纸张大小为 A4 大小(210 mm × 297 mm)
                int width = 794;
                int height = 1123;
                double margin = 0;
                paper.setSize(width, height);
                paper.setImageableArea(margin, margin, width - 2 * margin, height - 2 * margin);
                pf.setPaper(paper);
            }
            book.append(this, pf, AllPageNum);
            if (printFlag.contains("PrintPreview")) {
                Platform.runLater(() -> {
                    try {
                        PrintPreview frmPreview = new PrintPreview(this);
                        frmPreview.Show();
                    } catch (Exception ee) {
                        Alert alert = new Alert(Alert.AlertType.INFORMATION);
                        alert.setTitle("提示");
                        alert.setContentText(ee.getMessage());
                        alert.showAndWait();
                    }
                });
            } else {
                job.print();
            }
        } catch (PrinterException e) {
            e.printStackTrace();
        }
    }

    /**
     * 设置打印页数
     *
     * @param pages
     */
    public void SetPrintPage(List<Integer> pages) {
        PrintHandeler.SetPrintPage(pages);
        book.append(this, pf, pages.size());
    }

    /**
     * 执行一次打印
     */
    public void PrintOnece() throws Exception {
        job.print();
        //恢复页
        List<Integer> pages = new ArrayList<>();
        for (int i = 0; i < AllPageNum; i++) {
            pages.add(i);
        }
        SetPrintPage(pages);
    }

    /**
     * 打印画图
     *
     * @param graphics
     * @param pageFormat
     * @param pageIndex
     * @return
     * @throws PrinterException
     */
    @Override
    public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
        // 转换成Graphics2D 拿到画笔
        Graphics2D g2 = (Graphics2D) graphics;
        if (PrintHandeler != null) {
            try {
                int drawOneRet = PrintHandeler.DrawOnePage(g2, pageIndex);
                return drawOneRet;
            } catch (Exception ex) {
                if (ex.getCause() != null) {
                    PrintHandeler.WriteLog(ex.getCause().getMessage());
                } else {
                    PrintHandeler.WriteLog(ex.getMessage());
                }
                ex.printStackTrace();
                return 1;
            }
        }
        return 1;
    }
}

之前做打印设计时候就考虑到后面做预览和在线打印预览要共用绘图,就把打印和绘图分离彻底了
在这里插入图片描述
从所有页里提取打印页,这是比老的设计合理的部分,因为合理设计,极大的简化了打印和打印预览的实现逻辑。
在这里插入图片描述

打印业务代码

import JRT.Core.Dto.OutParam;
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, OutParam Session, OutParam Output) throws  Exception{
        List<PrintElement> retList=new ArrayList<>();
        //画一个文本
        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());

        //画一个文本
        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());
        //画一个文本
        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());
        //画一个文本
        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);
    }
}





到此,JRT的设计目标全部实现,开始我还计划JRTWeb部分到过年左右完成的,JRTClient部分3-5年内实现,速度大大超出预期,也正好借着火候一鼓作气把全部实现了。

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

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【Linux】telnet命令使用

telnet命令 telnet命令用于使用telnet协议与另一台主机进行通信。如果在没有主机参数的情况下调用telnet&#xff0c;它将进入命令模式&#xff0c;由其提示&#xff08;telnet>&#xff09;指示。在这种模式下&#xff0c;它接受并执行下面列出的命令。如果使用参数调用它…

相交链表(LeetCode 160)

文章目录 1.问题描述2.难度等级3.热门指数4.解题思路方法一&#xff1a;暴力法方法二&#xff1a;哈希表方法三&#xff1a;双栈方法四&#xff1a;双指针&#xff1a;记录链表长度方法五&#xff1a;双指针&#xff1a;互换遍历 5.实现示例参考文献 1.问题描述 给你两个单链表…

ai智能客服的发展是怎么样的?

随着科技的不断发展&#xff0c;人工智能&#xff08;AI&#xff09;技术已经逐渐进入了我们的生活&#xff0c;其中最为突出的应用之一就是智能客服。智能客服是指利用人工智能技术来实现客户服务的一种方式&#xff0c;它可以通过自然语言处理、机器学习等技术&#xff0c;来…

go语言 | etcd源码导读(一)

参考 本文参考https://zhuanlan.zhihu.com/p/600893553 https://www.topgoer.com/%E6%95%B0%E6%8D%AE%E5%BA%93%E6%93%8D%E4%BD%9C/go%E6%93%8D%E4%BD%9Cetcd/etcd%E4%BB%8B%E7%BB%8D.html 前沿etcd 与 raft etcd是使用Go语言开发的一个开源的、高可用的分布式key-value存储系…

【MySQL数据类型】

目录&#xff1a; 前言数据类型分类整数类型tinyintbit 小数类型floatdecimal 字符串类型charvarchar日期和时间enum & set在集合中查找find_in_set 前言 剑指offer&#xff1a;一年又4天 数据类型分类 整数类型 tinyint 整数类型都分为有符号和无符号两种&#xff0c;默…

【7】PyQt布局layout

目录 1. 布局简介 2. 水平布局QHBoxLayout 3. 竖直布局QVBoxLayout 4. 表单布局QFormLayout 5. 布局嵌套 1. 布局简介 一个pyqt窗口中可以有多个控件。所谓布局,指的就是多个控件在窗口中的展示方式 布局方式大致分为: 水平布局竖直布局网格布局表单布局 2. 水平布局Q…

zookeeper集群 +kafka集群

1.zookeeper kafka3.0之前依赖于zookeeper zookeeper是一个开源&#xff0c;分布式的架构&#xff0c;提供协调服务&#xff08;Apache项目&#xff09; 基于观察者模式涉及的分布式服务管理架构 存储和管理数据&#xff0c;分布式节点上的服务接受观察者的注册&#xff0c…

【EI会议征稿中,IEEE出版】第三届计算机科学、电子信息工程和智能控制技术国际会议(CEI 2023)

第三届计算机科学、电子信息工程和智能控制技术国际会议&#xff08;CEI 2023&#xff09; 2023 3rd International Conference on Computer Science, Electronic Information Engineering and Intelligent Control Technology 第三届计算机科学、电子信息工程和智能控制技术…

Auto4D:从时序点云标注4D物体

文章&#xff1a;Auto4D: Learning to Label 4D Objects from Sequential Point Clouds 作者&#xff1a;Bin Yang&#xff0c; Min Bai&#xff0c; Ming Liang&#xff0c; Wenyuan Zeng&#xff0c; Raquel Urtasun 编辑&#xff1a;点云PCL 来源&#xff1a;arXiv 2021 …

180天Java从入门到就业-Day04-01Java程序流程控制介绍、Java分支结构if语句

1.程序流程控制介绍 1.1 流程控制结构介绍 流程控制语句是用来控制程序中各语句执行顺序的语句,可以将语句组合成完成一定功能的逻辑模块。 一个程序会包含三种流程控制结构:顺序结构、分支结构、循环结构 顺序结构在没有使用程序流程控制语句(if-else语句、switch-case语…

解决vue3项目打包发布到服务器后访问页面显示空白问题

1.在 vite.config.ts 文件中 加入 base:./ 当你将 base 设置为 / 时&#xff0c;它表示你的应用程序将部署在服务器的根路径上&#xff0c;&#xff08;将 base 设置为 / 表示你的应用程序部署在服务器的根路径上&#xff0c;并且 Vite 会相应地处理资源和路由的路径…

掌握大型语言模型(LLM)技术:推理优化

原文链接&#xff1a;Mastering LLM Techniques: Inference Optimization | NVIDIA Technical Blog 大模型相关技术文章已整理到Github仓库&#xff0c;欢迎start! 堆叠Transformer层以创建大型模型可以获得更好的准确性、few-shot学习能力&#xff0c;甚至在各种语言任务中具有…

springboot 2.4.4集成 hikari连接池多数据源实例

文章目录 前言一、配置步骤1.1 pom配置1.2 application.properties配置1.3 DataSourceContextHolder类1.4 DynamicDataSource1.5 DataSourceconfig类配置1.6 配置TargetDataSource注解1.7 切面方法1.8 dao的写法 二、测试验证2.1 启动springboot项目2.2 检查数据库连接2.3 debu…

SpringBoot项目打jar包

本文章使用idea进行打包 1.打开项目&#xff0c;右击项目选中Open Module Settings进入project Structure&#xff0c;如下图所示&#xff1a; 2.选中Artifacts&#xff0c;点击中间的加号&#xff08;Project Settings->Artifacts->JAR->From modules with dependen…

JavaScript <有道翻译之数据解密‘23年12月06日版‘>--案例(三)

前言: 记得上半年还是去年,有道翻译还是直接返回明文数据;现在也跟着,用接口返回加密数据了; 娱乐一下,破他的密文数据... 成品效果图: js部分: 对于找他的密文数据有点费时,针对密文--->搜他地址和启动器不是特别容易,辗转多时(搜:descrypt/json.parse 结合使用更快),有图…

SpaceSight、Echo 联合升级,打造更懂场景的 AI 「超级门店」

当各领域都在谈论「增长」&#xff0c;门店业务的增长又该从哪里开始着手…… 在日常运营中&#xff0c;「高效」和「细致」是否无法同时实现&#xff1f;「任务下达」和「任务执行」之间有多大偏差&#xff1f; 在客户洞察上&#xff0c;如何用「过去」的数据预测「未来」&…

docker搭建logstash和使用方法

配置logstash 查询下载镜像【固定和elasticsearch一样的版本】 [roothao ~]# docker search logstash NAME DESCRIPTION STARS OFFICIAL AUTOMATED logstash …

CoreDNS实战(五)-接入prometheus监控

1 背景 Prometheus插件作为coredns的Plugins&#xff0c;默认情况下是内置在coredns中&#xff0c;如果是自己编译安装的版本&#xff0c;需要注意在编译安装的时候的plugin.cfg文件中添加了prometheus:metrics&#xff0c;这样才能确保编译成功。 # 首先我们检查一下运行的版…

万亿氢能产业链崛起,汉威科技助力安全发展

近年来化石能源的大量使用带来了碳排放急剧上升、环境污染、极端天气频发、全球变暖等一系列问题&#xff0c;加之化石能源储量日益减少&#xff0c;各国不得不考虑重构能源体系&#xff0c;寻找化石能源的替代方案&#xff0c;努力降低碳排放。 在此背景下&#xff0c;氢能成…

gmid方法设计五管OTA二级远放

首先给出第一级是OTA&#xff0c;第二级是CS的二级运放电路图&#xff1a; gmid的设计方法可以根据GBW、Av、CL来进行电路设计&#xff0c;因此在设计电路之前需要以上的参数要求。 1、为了满足电路的相位裕度至少60&#xff0c;需要对GBW、主极点、零点进行分析。 首先给出其…