static byte[] _pageAsBitmapBytes(PdfDocument doc, int pageCurrent, DOC_TYPE docType) { int w = (int)doc.PageSizes[pageCurrent].Width; int h = (int)doc.PageSizes[pageCurrent].Height; ////if (w >= h) w = this.Width; ////else w = 1200; //if (w < 1200) w = 1200; //h = (int)((w * doc.PageSizes[i].Height) / doc.PageSizes[i].Width); if (w > 1200) { w = 1200; h = (int)((w * doc.PageSizes[pageCurrent].Height) / doc.PageSizes[pageCurrent].Width); } if (docType == DOC_TYPE.PNG_OGRINAL) { using (var image = doc.RenderTransparentBG(pageCurrent, w, h, 100, 100)) using (var ms = new MemoryStream()) { image.Save(ms, ImageFormat.Png); return(ms.ToArray()); } } else { using (var image = doc.Render(pageCurrent, w, h, 100, 100, false)) using (var ms = new MemoryStream()) { image.Save(ms, ImageFormat.Png); return(ms.ToArray()); } } }
public void generateDocument(DOC_TYPE docType, string id) { /* * string filename = docType.ToString() + "-" + id + ".docx"; * file = new Document(); * fileBuilder = new DocumentBuilder(file); * * * * * Dictionary<string, object> documentDIC = document.ToBsonDocument().ToDictionary(); * insertField(documentDIC, document.GetType().Name); * * fileBuilder.Document.Save("merging-field-" + id + ".docx"); * file.MailMerge.Execute(mergeFields.ToArray(), mergeValues.ToArray()); * fileBuilder.Document.Save(filename); */ }
public static void SplitAllJpeg(string requestId, COMMANDS cmd, string input, Dictionary <string, object> data) { string file = input; if (File.Exists(file)) { var redis = new RedisBase(new RedisSetting(REDIS_TYPE.ONLY_WRITE, __CONFIG.REDIS_PORT_WRITE)); long docId = 0; try { using (var doc = PdfDocument.Load(file)) { int pageTotal = doc.PageCount; DOC_TYPE docType = DOC_TYPE.JPG_OGRINAL; if (data.ContainsKey("png")) { docType = DOC_TYPE.PNG_OGRINAL; } docId = StaticDocument.BuildId(docType, pageTotal, new FileInfo(file).Length); if (redis.HEXISTS(docId.ToString(), "0")) { App.Reply(cmd, requestId, input, new Dictionary <string, object>() { { "id", docId }, { "type", docType.ToString() }, { "size", 0 }, { "page", 0 }, { "page_total", pageTotal }, }); return; } var sizes = new Dictionary <string, string>(); for (int i = 0; i < pageTotal; i++) { byte[] buf = null; int len = 0; bool ok = false; string err = ""; try { buf = _pageAsBitmapBytes(doc, i, docType); len = buf.Length; ok = redis.HSET(docId, i, buf); } catch (Exception ex) { err = ex.Message + Environment.NewLine + ex.StackTrace; } App.Reply(cmd, requestId, input, new Dictionary <string, object>() { { "id", docId }, { "type", docType.ToString() }, { "size", len }, { "page", i }, { "page_total", pageTotal }, }); sizes.Add(string.Format("{0}:{1}", docId, i), len.ToString()); //Thread.Sleep(100); } redis.HMSET("_IMG_SIZE", sizes); App.Reply(cmd, requestId, input, new Dictionary <string, object>() { { "id", docId }, { "type", docType.ToString() }, { "size", 0 }, { "page", pageTotal }, { "page_total", pageTotal }, }); } } catch (Exception exInfo) { string errInfo = cmd.ToString() + " -> " + file + Environment.NewLine + exInfo.Message + Environment.NewLine + exInfo.StackTrace; redis.HSET("_ERROR:PDF:" + cmd.ToString(), docId.ToString(), errInfo); } } }
/// <summary> /// Gets documents from response, returned type depends on passed returnType parameter. /// If returnType is DOC_TYPE_SIMPLEXML, returns Dictionary<string, CPS_SimpleXML>. /// If returnType is DOC_TYPE_ARRAY, returns null - not supported yet. /// If returnType is DOC_TYPE_STDCLASS, returns Dictionary<string, XmlElement>. /// </summary> /// <param name="returnType">Defines used return type.</param> /// <returns>Documents as Dictionary<string, CPS_SimpleXML> or Dictionary<string, XmlElement>.</returns> public Object getRawDocuments(DOC_TYPE returnType) { if (returnType == DOC_TYPE.DOC_TYPE_SIMPLEXML) { Dictionary<string, CPS_SimpleXML> ret = new Dictionary<string, CPS_SimpleXML>(); foreach (KeyValuePair<string, XmlElement> pair in this.p_documents) ret[pair.Key] = new CPS_SimpleXML(pair.Value); return ret; } else if (returnType == DOC_TYPE.DOC_TYPE_ARRAY) { return null; // not supported yet } else // DOC_TYPE.DOC_TYPE_STDCLASS return this.p_documents; }
/// <summary> /// Gets aggregate data from response, returned type depends on passed returnType parameter. /// If returnType is DOC_TYPE_SIMPLEXML, returns Dictionary<string, List<CPS_SimpleXML>>. /// If returnType is DOC_TYPE_ARRAY, returns null - not supported yet. /// If returnType is DOC_TYPE_STDCLASS, returns Dictionary<string, List>XmlElement>>. /// </summary> /// <param name="returnType">Defines used return type.</param> /// <returns>Aggregate data as Dictionary<string, List<CPS_SimpleXML>> or Dictionary<string, List<XmlElement>>.</returns> public Object getRawAggregate(DOC_TYPE returnType) { if (returnType == DOC_TYPE.DOC_TYPE_SIMPLEXML) { Dictionary<string, List<CPS_SimpleXML>> ret = new Dictionary<string, List<CPS_SimpleXML>>(); foreach (KeyValuePair<string, List<XmlElement>> pair in this.p_aggregate) { ret[pair.Key] = new List<CPS_SimpleXML>(); foreach (XmlElement xmle in pair.Value) ret[pair.Key].Add(new CPS_SimpleXML(xmle)); } return ret; } else if (returnType == DOC_TYPE.DOC_TYPE_ARRAY) { return null; // not supported yet } else // DOC_TYPE.DOC_TYPE_STDCLASS return this.p_aggregate; }
/// <summary> /// Gets response content for simple commands, like 'status', returned type depends on passed returnType parameter. /// If returnType is DOC_TYPE_SIMPLEXML, returns CPS_SimpleXML. /// If returnType is DOC_TYPE_ARRAY, returns null - not supported yet. /// If returnType is DOC_TYPE_STDCLASS, returns XmlElement. /// </summary> /// <param name="returnType">Defines used return type.</param> /// <returns>Content as CPS_SimpleXML or XmlElement.</returns> public Object getContentArray(DOC_TYPE returnType = DOC_TYPE.DOC_TYPE_STDCLASS) { if (returnType == DOC_TYPE.DOC_TYPE_SIMPLEXML) return new CPS_SimpleXML(this.p_contentArray); else if (returnType == DOC_TYPE.DOC_TYPE_ARRAY) return null; // not supported yet else // DOC_TYPE.DOC_TYPE_STDCLASS return this.p_contentArray; }