套打.二开案例.将将套打页面xml转为图片

栏目:云星空知识作者:金蝶来源:金蝶云社区发布:2024-09-16浏览:1

套打.二开案例.将将套打页面xml转为图片

【场景】将套打导出生成图片 利用功能:[导出PDF以图片导出](https://wenku.my7c.com/article/380805823498323968?productLineId=1) 【案例】 <1>第一步,得到套打的页面json数据 参考[套打json页面](https://wenku.my7c.com/article/390832006529651968?productLineId=1) <2>转换xaml为图片 ```csharp using Kingdee.BOS; using Kingdee.BOS.Core.DynamicForm.PlugIn; using Kingdee.BOS.Core.DynamicForm.PlugIn.Args; using Kingdee.BOS.Http; using Kingdee.BOS.JSON; using Kingdee.BOS.Orm.DataEntity; using Kingdee.BOS.ServiceHelper.Report; using Kingdee.BOS.Util; using System; using System.Collections.Generic; using System.IO; namespace DynamicFormPlugIn.NotePrint { [Kingdee.BOS.Util.HotUpdate] public class GeneratePicByNoteXamlPlugIn : AbstractDynamicFormPlugIn { public override void ButtonClick(ButtonClickEventArgs e) { if (string.Equals(e.Key, "F_BHR_ConvPicByXaml", StringComparison.OrdinalIgnoreCase)) { /* * 将套打json中的xaml页面转换为 图片 * 利用xaml 页面渲染技术,在服务端生成图片(画布),支持版本 202211 */ string filePath = string.Format("E:\\Test\\{0}.json", "1"); string fileText = System.IO.File.ReadAllText(filePath); JSONObject jsonObj = JSONObject.Parse(fileText); if (!jsonObj.ContainsKey("pages")) return; Dictionary<string,object> pageArray = jsonObj["pages"] as Dictionary<string, object>; List<string> pageXaml = new List<string>(); foreach (var pageItem in pageArray) { var pageObj = pageItem.Value as JSONObject; string xaml = pageObj["xaml"].ToString(); pageXaml.Add(xaml); } var config = PrintServiceHelper.GetXamlTransformConfig(this.Context); var imageList = GetImageByHttpHost(pageXaml, config); if(imageList != null && imageList.Count >0) { imageList[0].Save(string.Format("E:\\Test\\{0}.webp", "1")); } } } /// <summary> /// 通过Http服务将XAML转换为图片 /// </summary> /// <param name="pageXAML">页面XAML列表</param> /// <param name="dyXamlTransformConfig">转换配置信息</param> /// <returns></returns> private List<System.Drawing.Image> GetImageByHttpHost(List<string> pageXAML, DynamicObjectCollection dyXamlTransformConfig) { List<System.Drawing.Image> images = new List<System.Drawing.Image>(); Dictionary<string, string> dicConfig = new Dictionary<string, string>(); foreach (var item in dyXamlTransformConfig) { var key = item["FPARAMKEY"].ToString(); var value = item["FPARAMVALUE"].ToString(); dicConfig[key] = value; } JSONObject json = new JSONObject(); json.Add("config", dicConfig); json.Add("xaml", pageXAML); string url = string.Format("{0}://{1}:{2}/Image/XamlToBase64Image.kcapi", KDConfiguration.Current.HttpServerScheme, KDConfiguration.Current.HttpServerHost, KDConfiguration.Current.FileConvertServiceJobPort); string reqContent = JsonUtil.SerializeWithOutNull(json); int timeOut = 10 * 60 * 1000; string rtnJson = HttpUtil.PostJson(url, timeOut, reqContent); var rtn = JsonUtil.DeserializeObject<GenericHttpResult<List<string>>>(rtnJson); if (rtn.Code == (int)HttpResultCode.Success) { var base64ImageList = rtn.Data; if (base64ImageList != null && base64ImageList.Count > 0) { foreach (var base64 in base64ImageList) { byte[] data = Convert.FromBase64String(base64); using (MemoryStream ms = new MemoryStream(data)) { using (var bmpTemp = new System.Drawing.Bitmap(ms)) { var iamge = new System.Drawing.Bitmap(bmpTemp); images.Add(iamge); } } } } } return images; } } } ``` 【效果】 ![4L1B`DAWONA46Y4.webp](/download/01008331bacd3f514d89b18f080200545180.webp) 【说明】 <1>如果是老版本客户,只能自己实现将xaml渲染为图片的功能,(不建议在代码中直接创建STA线程),使用WPF xaml做转换 <2>转换失败的问题,对照实现逻辑排查日志

有点灰技术了!


还要配置什么东西吗image.webp

套打.二开案例.将将套打页面xml转为图片

【场景】将套打导出生成图片利用功能:[导出PDF以图片导出](https://wenku.my7c.com/article/380805823498323968?productLineId=1)【案例】...
点击下载文档
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息