Ejemplo n.º 1
0
        public async Task <byte[]> GetPdfFromHtmlAsync(PdfGeneratorInputContent inputContent)
        {
            var doc = new HtmlToPdfDocument()
            {
                GlobalSettings =
                {
                    ColorMode   = ColorMode.Color,
                    Orientation = inputContent.Portrait.GetValueOrDefault(true) ? Orientation.Portrait : Orientation.Landscape,
                    DPI         = inputContent.DPI.GetValueOrDefault(300)
                },
                Objects =
                {
                    new ObjectSettings()
                    {
                        PagesCount  = true,
                        HtmlContent = inputContent.Html,
                        WebSettings ={ DefaultEncoding                   = "utf-8" },
                        //HeaderSettings = { FontSize = 9, Right = "Page [page] of [toPage]", Line = true, Spacing = 2.812 }
                    }
                }
            };

            DinkToPdf.PaperKind paperKind = MapPaperKind(inputContent.PaperKind);
            doc.GlobalSettings.PaperSize = paperKind;
            if (paperKind == DinkToPdf.PaperKind.Custom)
            {
                doc.GlobalSettings.PaperSize = new PechkinPaperSize(inputContent.Width.GetValueOrDefault().ToString(), inputContent.Height.GetValueOrDefault().ToString());
            }
            return(await Task.Run(() => { return _pdfConverter.Convert(doc); }));
        }
Ejemplo n.º 2
0
        public async Task <FileStreamResult> Post([FromBody] PdfGeneratorInputContent value)
        {
            var result = await _pdfGeneratorService.GetPdfFromHtmlAsync(value);

            Stream stream       = new MemoryStream(result);
            var    streamResult = new FileStreamResult(stream, "application/pdf")
            {
                FileDownloadName = "report.pdf"
            };

            return(streamResult);
        }