1

我有一个使用 Google Cloud Print API ( https://github.com/jittagornp/GoogleCloudPrint ) 打印 pdf 的 Java 应用程序。在大多数情况下,它就像一个魅力,但时不时地(大约 100 分之一)它会返回一个错误,看起来像这样“Det går inte att göra ändringar i ett avslutat jobb”。大致翻译成英文,上面写着:“无法对已完成的作业进行更改” 令人惊讶的是,无论有无错误,页面每次都能完美打印。

每次调用 GCP 的代码如下所示:

    public static SubmitJobResponse submitPrintJob(String filename, String type){

        String jsonTicket;
        String printerId;

        SubmitJobResponse response = null;

        String jobtitle;

        jobtitle = filename.substring(filename.lastIndexOf('/') + 1);

        // Login to GCP
        GoogleCloudPrint cloudPrint = gcpLogin();

        jsonTicket = "{'version':'1.0','print':{'vendor_ticket_item':[],'color':{'type':1},'copies':{'copies':4}}}";
        printerId = session("printerlabel"); 

        try {

            // Get file as byte array
            Path path = Paths.get(filename);
            byte[] content = Files.readAllBytes(path);

            Gson gson = new Gson();
            Ticket ticket = gson.fromJson(jsonTicket, Ticket.class);

            String json = gson.toJson(ticket);

            //create job
            SubmitJob submitJob = new SubmitJob();
            submitJob.setContent(content);
            submitJob.setContentType("application/pdf");
            submitJob.setPrinterId(printerId);
            submitJob.setTicket(ticket);
            submitJob.setTitle(jobtitle);

            //send job
            response = cloudPrint.submitJob(submitJob);
            Logger.debug("PrinterID => {}", printerId);
            Logger.debug("submit job response => {}", response.isSuccess() + "," + response.getMessage()); 
            if(response.isSuccess()) {
                Logger.debug("submit job id => {}", response.getJob().getId());
            }

            cloudPrint.disconnect();

        } catch (Exception ex) {
            Logger.warn(null, ex);
        }

        return response;

    }

该 API 在 GCP 上使用对“/submit?output=json&printerid=”的调用,所以为什么它说我正在尝试更改已完成的作业 - 我没有提交作业 ID - 只有打印机 ID。

我如何摆脱这些错误的错误?

4

0 回答 0