private void SaveImage(string base64) { if (string.IsNullOrEmpty(base64)) { return; } string fileName = (UniqueID.GetID('a') + UniqueID.GetID() + ".png").ToString(); if (!Directory.Exists(Path.Combine(way, "img_for_txt"))) { Directory.CreateDirectory(Path.Combine(way, "img_for_txt")); } string path = Path.Combine(way, "img_for_txt", fileName); var buffer = Convert.FromBase64String(base64); using (var file = File.Create(path)) { file.Write(buffer, 0, buffer.Length); file.Close(); } ImageBuffer.AddElement(new ImageInfo { Name = fileName, Path = path, CreationDate = DateTime.Now }); }
public void RenderImage(ImageRenderInfo renderInfo) { var imageObject = renderInfo.GetImage(); var data = imageObject.GetImageAsBytes(); string fileName = (UniqueID.GetID('a') + UniqueID.GetID() + "." + imageObject.GetFileType()).ToString(); if (!Directory.Exists(System.IO.Path.Combine(way, "img_for_txt"))) { Directory.CreateDirectory(System.IO.Path.Combine(way, "img_for_txt")); } string path = System.IO.Path.Combine(way, "img_for_txt", fileName); File.WriteAllBytes(path, data); ImageBuffer.AddElement(new ImageInfo { Name = fileName, Path = path, CreationDate = DateTime.Now }); }
public override bool Parse() { try { Document doc = new Document(path); string text = doc.GetText(); tworker.WorkText(text); foreach (Section section in doc.Sections) { //Get Each Paragraph of Section foreach (Paragraph paragraph in section.Paragraphs) { //Get Each Document Object of Paragraph Items foreach (DocumentObject docObject in paragraph.ChildObjects) { //If Type of Document Object is Picture, Extract. if (docObject.DocumentObjectType == DocumentObjectType.Picture) { DocPicture pic = docObject as DocPicture; string fileName = (UniqueID.GetID('a') + UniqueID.GetID() + ".png").ToString(); if (!Directory.Exists(System.IO.Path.Combine(way, "img_for_txt"))) { Directory.CreateDirectory(Path.Combine(way, "img_for_txt")); } string path = Path.Combine(way, "img_for_txt", "img_for_txt", fileName); //Save Image pic.Image.Save(path, System.Drawing.Imaging.ImageFormat.Png); ImageBuffer.AddElement(new ImageInfo { Name = fileName, Path = path, CreationDate = DateTime.Now }); } } } } return(true); } catch (Exception e) { return(false); } }