public async Task <IActionResult> Index(string MRecordId)
        {
            var MRecord = await _mRecordService.GetMedicalRecordById(MRecordId);

            if (MRecord.DateCompleted > 0)
            {
                MRecord.WasPrinted = true;
                await _mRecordRepository.UpdateMedicalRecord(Helper.AutoDTO <MedicalRecordModel, MedicalRecord>(MRecord));

                var converter = new HtmlToPdfConverter(HtmlRenderingEngine.Blink);
                var settings  = new BlinkConverterSettings();
                settings.PdfPageSize        = new SizeF(PdfPageSize.A4);
                settings.Margin.All         = 20;
                settings.MediaType          = MediaType.Print;
                settings.BlinkPath          = Path.Combine(_env.ContentRootPath, "BlinkBinariesWindows");
                converter.ConverterSettings = settings;
                string html = await _renderService.RenderToStringAsync <MedicalRecordModel>
                                  ("/Views/print/print.cshtml", MRecord);

                var document = converter.Convert(html, "~/css/print.css");
                document.EnableMemoryOptimization = true;

                MemoryStream stream = new MemoryStream();
                document.Save(stream);
                return(File(stream.ToArray(), System.Net.Mime.MediaTypeNames.Application.Pdf, $"{MRecordId}.pdf"));
            }
            return(BadRequest());
        }
Esempio n. 2
0
        public IActionResult downloadAnalysis()
        {
            var url = "https://localhost:44374/User/getAnalysis?pdfview=1";
            HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.Blink);

            BlinkConverterSettings settings = new BlinkConverterSettings();

            settings.AdditionalDelay = 10000;
            settings.BlinkPath       = Path.Combine(this._hostingEnvironment.ContentRootPath, "BlinkBinariesWindows");

            htmlConverter.ConverterSettings = settings;

            PdfDocument document = htmlConverter.Convert(url);

            MemoryStream stream = new MemoryStream();

            document.Save(stream);
            return(this.File(stream.ToArray(), System.Net.Mime.MediaTypeNames.Application.Pdf, "Report.pdf"));
        }
Esempio n. 3
0
        private PdfDocument ConvertWithBlinkRendering()
        {
            //Initialize HTML to PDF converter with Blink settings
            HtmlToPdfConverter     htmlConverter     = new HtmlToPdfConverter(HtmlRenderingEngine.Blink);
            BlinkConverterSettings converterSettings = new BlinkConverterSettings();

            //Set page margins
            converterSettings.Margin = new PdfMargins()
            {
                All = float.Parse(pagemargin)
            };

            //Set page orientation
            if (rdbtnOrientation == "Portrait")
            {
                converterSettings.Orientation = PdfPageOrientation.Portrait;
            }
            else
            {
                converterSettings.Orientation = PdfPageOrientation.Landscape;
            }

            //Set rotation
            converterSettings.PageRotateAngle = (PdfPageRotateAngle)Enum.Parse(typeof(PdfPageRotateAngle), rotate);

            //Enable Javascript
            converterSettings.EnableJavaScript = chkEnableJavaScript == "on" ? true : false;
            //Enable Hyperlink
            converterSettings.EnableHyperLink = chkEnableHyperlink == "on" ? true : false;
            //Enable Form
            converterSettings.EnableForm = chkEnableForm == "on" ? true : false;
            //Enabel Toc
            converterSettings.EnableToc = chkEnableToc == "on" ? true : false;
            //Enable Bookmark
            converterSettings.EnableBookmarks = chkEnableBookmark == "on" ? true : false;

            //Set Blink viewport size
            int viewportWidth = 1024;

            if (int.TryParse(ViewportWidth, out viewportWidth))
            {
            }

            int viewportHeight = 0;

            if (int.TryParse(ViewportHeight, out viewportHeight))
            {
            }

            converterSettings.ViewPortSize = new Size(viewportWidth, viewportHeight);

            //Set BlinkPath
            string BlinkBinaryPath = ResolveApplicationImagePath("BlinkBinaries");

            converterSettings.BlinkPath = BlinkBinaryPath;

            //Set additional delay
            if (int.TryParse(jsAdditionalDelay, out int additionalDelay))
            {
                converterSettings.AdditionalDelay = additionalDelay * 1000;
            }

            //Adding Header
            if (showHeader == "on")
            {
                converterSettings.PdfHeader = this.AddHeader(converterSettings.PdfPageSize.Width, "Syncfusion Essential PDF", " ");
            }

            //Adding Footer
            if (showFooter == "on")
            {
                converterSettings.PdfFooter = this.AddFooter(converterSettings.PdfPageSize.Height, "@Copyright 2016");
            }

            //Assign Blink settings to HTML converter
            htmlConverter.ConverterSettings = converterSettings;

            //Convert url to pdf
            Pdfdoc = htmlConverter.Convert(sourceUrl);

            return(Pdfdoc);
        }