Ejemplo n.º 1
0
 public async Task<IHttpActionResult> Upload()
 {
     System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
     try
     {
         byte[] content = await Request.Content.ReadAsByteArrayAsync();
         Extractor e = new Extractor();
         DocumentModel doc = e.ReadPdf(content);
         watch.Start();
         DbManager db = new DbManager();
         db.AddDocument(doc);
         watch.Stop();
         return Ok(doc);
     }
     catch (Exception e)
     {
         return BadRequest(e.Message);
     }
 }
Ejemplo n.º 2
0
        public void ParsePDF()
        {
            const string file = @"C:\Users\vmalakhov.ARTGROUP\Desktop\pdfupload\JobCost.pdf";
            var path = @"C:\Users\vmalakhov.ARTGROUP\Desktop\pdfupload\pdfupload\Files\1410712015114130133.xlsx";
            using(var stream = new FileStream(file, FileMode.Open))
            {
                byte[] content;
                using (BinaryReader b = new BinaryReader(stream))
                {
                    int length = (int)stream.Length;
                    content = b.ReadBytes(length);
                }
                Extractor e = new Extractor();
                var doc = e.ReadPdf(content);

                ExcelExport.Exporter ex = new ExcelExport.Exporter();
                ex.ExportToExcel(doc,path);
                Assert.AreNotEqual(doc, null);
            }
        }
Ejemplo n.º 3
0
 public async Task<HttpResponseMessage> Download()
 {
     HttpResponseMessage result = null;
     byte[] content = await Request.Content.ReadAsByteArrayAsync();
     Extractor e = new Extractor();
     if (content.Length > 0)
     {
         DocumentModel doc = e.ReadPdf(content);
         var excelSavePath = System.Web.Hosting.HostingEnvironment.MapPath("~/Files/");
         //var path = @"C:\Users\vmalakhov.ARTGROUP\Desktop\pdfupload\pdfupload\Files\1410712015114130133.xlsx";
         var path = new Exporter().ExportToExcel(doc, excelSavePath);
         
         result = Request.CreateResponse(HttpStatusCode.OK);
         result.Content = new StreamContent(new FileStream(path, FileMode.Open, FileAccess.Read));
         result.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment");
         result.Content.Headers.ContentDisposition.FileName = "table.xlsx";
        
     }
     else
     {
         result.RequestMessage.CreateResponse(HttpStatusCode.BadRequest);
     }
     return result;
 }