Esempio n. 1
0
        public HttpResponseMessage GenerateHtmlFromJson([FromBody] GenerateDocumentRequest request)
        {
            request.ValidateNotNull();
            HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(_documentGenerator.Generate(request.Content, request.Filename,
                                                                        DocumentTypeEnum.Json, DocumentTypeEnum.Html, null).Content)
            };

            response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
            {
                FileName = request.Filename + ".html"
            };
            response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/html");
            return(response);
        }
Esempio n. 2
0
        public HttpResponseMessage GeneratePdfFromJson([FromBody] GenerateDocumentRequest request)
        {
            request.ValidateNotNull();
            HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new ByteArrayContent(_documentGenerator.Generate(request.Content, request.Filename,
                                                                           DocumentTypeEnum.Json, DocumentTypeEnum.Pdf, null).ByteContent)
            };

            response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
            {
                FileName = request.Filename + ".pdf"
            };
            response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
            return(response);
        }
Esempio n. 3
0
        public HttpResponseMessage GenerateDocxFromHtml([FromBody] GenerateDocumentRequest request)
        {
            request.ValidateNotNull();
            HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new ByteArrayContent(_documentGenerator.Generate(request.Content, request.Filename,
                                                                           DocumentTypeEnum.Html, DocumentTypeEnum.Docx, null).ByteContent)
            };

            response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
            // https://www.ryadel.com/en/get-file-content-mime-type-from-extension-asp-net-mvc-core/
            response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
            {
                FileName = request.Filename + ".docx"
            };
            return(response);
        }
Esempio n. 4
0
        public HttpResponseMessage GenerateDocxFromJson([FromBody] GenerateDocumentRequest request)
        {
            request.ValidateNotNull();
            string htmlContent = _documentGenerator.Generate(request.Content, request.Filename,
                                                             DocumentTypeEnum.Json, DocumentTypeEnum.Html, null).Content;
            HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new ByteArrayContent(_documentGenerator.Generate(htmlContent, request.Filename,
                                                                           DocumentTypeEnum.Html, DocumentTypeEnum.Docx, null).ByteContent)
            };

            response.Content.Headers.ContentType        = new MediaTypeHeaderValue("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
            response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
            {
                FileName = request.Filename + ".docx"
            };
            return(response);
        }