Esempio n. 1
0
        public async Task <Stream> GetCombineFromHtml(string HTMLString)
        {
            var job = new DownloadTask()
            {
                Url      = "",
                FileName = GetUUID() + ".pdf",
                IsPDF    = true,
                Index    = 0,
                Content  = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(HTMLString))
            };

            job = await ConvertPdfFromHTML(job);

            return(job.Content);
        }
Esempio n. 2
0
        //Convert Pdf from HTMLString
        public async Task <DownloadTask> ConvertPdfFromHTML(DownloadTask job)
        {
            GlobalProperties.EnableFallbackToRestrictedRenderingEngine = true;
            GlobalProperties.EnableRestrictedRenderingEngine           = true;

            var converter = new HtmlToPdf();

            // set converter options
            converter.Options.PdfPageSize        = PdfPageSize.A4;
            converter.Options.PdfPageOrientation = PdfPageOrientation.Portrait;
            converter.Options.WebPageWidth       = 1240;

            // create a new pdf document converting an url
            var reader = new StreamReader(job.Content);
            var doc    = converter.ConvertHtmlString(reader.ReadToEnd());
            var tmp    = doc.Save();

            job.Content = new MemoryStream(tmp);

            return(job);
        }
Esempio n. 3
0
        //Convert Pdf from URL
        public async Task <DownloadTask> ConvertPdf(DownloadTask job)
        {
            GlobalProperties.EnableFallbackToRestrictedRenderingEngine = true;
            GlobalProperties.EnableRestrictedRenderingEngine           = true;

            var converter = new HtmlToPdf();

            // set converter options
            converter.Options.PdfPageSize        = PdfPageSize.A4;
            converter.Options.PdfPageOrientation = PdfPageOrientation.Portrait;
            converter.Options.WebPageWidth       = 1240;

            // create a new pdf document converting an url
            var doc = converter.ConvertUrl(job.Url);
            var tmp = doc.Save();

            job.Content = new MemoryStream(tmp);

            logger.LogDebug("convert url to pdf[job index:{index}] complete", job.Index);

            return(job);
        }