金蝶云苍穹 根据打印模板生成PDF文件,并保存到附件中

生成PDF所用方法 PrintServiceHelper.createSinglePdf

 //获取附件控件
            AttachmentPanel attachmentPanel = this.getView().getControl("attachmentpanel");
            List<Map<String, Object>> attachmentData = attachmentPanel.getAttachmentData();
            //附件数量
            int size = attachmentData.size();
            if (size >= 2) {
                this.getView().showErrorNotification("超过附件数量最大值2,请删除后再次生成!");
                return;
            }
            String pageId = this.getView().getPageId();
            Object pkValue = this.getModel().getValue("id");
            //参数说明 : 当前页的id 单据标识 打印模板标识 当前单据标识
            byte[] createPdf = PrintServiceHelper.createSinglePdf(pageId, KEY_FORMID, KEY_PRT_MODELID, pkValue);
            //限制生成的附件大小
            int attachSize = 2;
            //大于10M,提示信息 1048576 = 1M
            if(createPdf.length >= 1048576 * attachSize){
                this.getView().showErrorNotification("附件大小不能超过"+attachSize+"M !");
                return;
            }
            //拿到字节输入流
            InputStream pdfIs = new ByteArrayInputStream(createPdf);
            //附件缓存
            TempFileCache tfc = CacheFactory.getCommonCacheFactory().getTempFileCache();
            int timeout = 7200;
            //上传到附件
            StringBuffer uid = new StringBuffer("rc-upload-");
            uid.append((new Date()).getTime());
            uid.append("-");
            int index = (int) (1.0D + Math.random() * 10.0D);
            uid.append(index);
            Map<String, Object> attachmentInfo = new HashMap();
            List<Map<String, Object>> attachments = new ArrayList();
            String pkid = pkValue.toString();
            String formid = KEY_FORMID;
            String billno = (String) this.getModel().getValue("billno");
            String appId = this.getModel().getDataEntityType().getAppId();
            String neddPaths = tfc.saveAsUrl(billno + ".pdf", pdfIs, timeout);
            Map<String, Object> tempAttachment = new HashMap();
            SimpleDateFormat sdf = new SimpleDateFormat("HHmmss");
            String nowTime = sdf.format(new Date());
            tempAttachment.put("uid", uid);
            tempAttachment.put("url", neddPaths);
            tempAttachment.put("size", createPdf.length);
            tempAttachment.put("description", "生成pdf文件");
            tempAttachment.put("name", billno+"-"+nowTime + ".pdf");
            attachments.add(tempAttachment);
            //构造附件数据
            attachmentInfo.put("attachmentpanel", attachments);
            //AppId 应用的编码
            DynamicObjectCollection collection = AttachmentServiceHelper.saveTempAttachments(formid, pkid, appId, attachmentInfo);
            if (collection != null && collection.size() != 0) {
                this.getView().showSuccessNotification("附件已生成!");
                this.getView().updateView("attachmentpanel");
            }
            try {
                pdfIs.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值