예제 #1
0
        public IActionResult BuildDocument([FromBody] OcrResults[] json)
        {
            try
            {
                HtmlParser          htmlParser = new HtmlParser();
                List <HtmlDocument> documents  = new List <HtmlDocument>();

                foreach (OcrResults result in json)
                {
                    documents.Add(htmlParser.CreateHtmlFromVisionResult(result));
                }

                Document.PdfConverter.PdfClient pdfClient = new Document.PdfConverter.PdfClient(converter);
                string path = pdfClient.ConvertHtmlToPdf(documents);

                MemoryStream ms = new MemoryStream();
                using (FileStream stream = new FileStream(path, FileMode.Open))
                {
                    stream.CopyTo(ms);
                }
                ms.Position = 0;

                System.IO.File.Delete(path);

                FileStreamResult streamResult = new FileStreamResult(ms, "application/pdf")
                {
                    FileDownloadName = "OCRResult.pdf"
                };

                return(streamResult);
            }
            catch (Exception ex)
            {
                throw;
            }
        }