public ActionResult <string> Generate([FromBody] string html)
        {
            var workStream = new MemoryStream();
            var byteInfo   = workStream.ToArray();

            workStream.Write(byteInfo, 0, byteInfo.Length);
            workStream.Position = 0;

            var converter = new SelectPdf.HtmlToPdf
            {
                Options =
                {
                    DisplayHeader   = true,
                    DisplayFooter   = true,
                    MarginLeft      =   20,
                    MarginRight     =   20,
                    MaxPageLoadTime =  200,
                    EmbedFonts      = true
                }
            };

            var filename = $"{Guid.NewGuid()}.pdf";
            var doc      = converter.ConvertHtmlString(html);

            doc.Save(filename);
            doc.Close();

            return(filename);
        }
        public ActionResult Result()
        {
            string htmlString = renderViewString.Result();
            string baseUrl    = "";

            string pdf_page_size = "A4";

            SelectPdf.PdfPageSize pageSize = (SelectPdf.PdfPageSize)Enum.Parse(typeof(SelectPdf.PdfPageSize),
                                                                               pdf_page_size, true);

            string pdf_orientation = "Portrait";

            SelectPdf.PdfPageOrientation pdfOrientation =
                (SelectPdf.PdfPageOrientation)Enum.Parse(typeof(SelectPdf.PdfPageOrientation),
                                                         pdf_orientation, true);

            string pdf_align = "Justify";

            SelectPdf.PdfTextHorizontalAlign pdfTextAlign =
                (SelectPdf.PdfTextHorizontalAlign)Enum.Parse(typeof(SelectPdf.PdfTextHorizontalAlign),
                                                             pdf_align, true);

            int webPageWidth = 1024;


            int webPageHeight = 0;


            // instantiate a html to pdf converter object
            SelectPdf.HtmlToPdf converter = new SelectPdf.HtmlToPdf();


            // set converter options
            converter.Options.PdfPageSize        = pageSize;
            converter.Options.PdfPageOrientation = pdfOrientation;
            converter.Options.WebPageWidth       = webPageWidth;
            converter.Options.WebPageHeight      = webPageHeight;


            // create a new pdf document converting an url
            SelectPdf.PdfDocument doc  = converter.ConvertHtmlString(htmlString, baseUrl);
            SelectPdf.PdfFont     font = doc.AddFont(SelectPdf.PdfStandardFont.Helvetica);
            //font.Size =7;
            //doc.AddFont(new System.Drawing.Font("Verdana", 20));
            // save pdf document
            var FolderName = (@"C:\Xelshekruleba\" + name.ToString());

            if (!Directory.Exists(FolderName))

            {
                Directory.CreateDirectory(FolderName);
            }

            var filePath = FolderName + '\\' + "" + name + ".pdf";

            doc.Save(filePath);
            //System.Diagnostics.Process.Start(filePath);

            return(null);
        }
Exemple #3
0
        public string getCrearPDF_actas()
        {
            var    res       = "";
            var    nombrePdf = "pruebas.pdf";
            string path      = System.Web.Hosting.HostingEnvironment.MapPath("~/Temp/pdf/" + nombrePdf);


            SelectPdf.HtmlToPdf converter = new SelectPdf.HtmlToPdf();
            var stringHtml = "<div align='center'><p> Gas Natural de Lima y Callao S.A </p>" +
                             "<p> Calle Morelli Nro. 150 Urb.San Borja </p>" +
                             "<p> (Torre 2 CC la Rambla) Lima - Lima - San Borja </p> </div>" +
                             "<h1>OBSERVACIONES</h1>";

            converter.Options.MarginTop   = 15;
            converter.Options.MarginLeft  = 5;
            converter.Options.MarginRight = 5;
            SelectPdf.PdfDocument doc = converter.ConvertHtmlString(stringHtml);
            doc.Save(path);
            doc.Close();

            try
            {
            }
            catch (Exception ex)
            {
                res = ex.Message;
            }
            return(res);
        }
Exemple #4
0
        public ActionResult ContractPdf(Guid id)
        {
            using (AirHelpDBContext dc = new AirHelpDBContext())
            {
                var userID  = User.Identity.Name;
                var isAdmin = User.IsInRole("admin");
                var claim   = dc.Claims.Include("User").Where(c => c.ClaimId == id && (isAdmin || c.UserId == userID)).SingleOrDefault();
                if (claim == null)
                {
                    ViewBag.text = "защитена информация";
                    return(View("Views/Login/Success.cshtml"));
                }
            }
            string port = Request.Url.Port == 80 ? string.Empty : $":{Request.Url.Port.ToString()}";

            String url = $"{Request.Url.Scheme}://{Request.Url.Host}{port}/contractPdf-09-4565-3453-2345435-2355/{id}";

            SelectPdf.HtmlToPdf converter = new SelectPdf.HtmlToPdf();

            converter.Options.MarginTop    = 30;
            converter.Options.MarginBottom = 10;
            converter.Options.MarginLeft   = 20;
            converter.Options.MarginRight  = 20;
            converter.Options.PdfPageSize  = SelectPdf.PdfPageSize.A4;

            SelectPdf.PdfDocument doc = converter.ConvertUrl(url);

            Response.ContentType = "application/pdf";
            doc.Save(Response.OutputStream);
            doc.Close();
            Response.End();
            return(null);
        }
        public JsonResult GeneratePdf()
        {
            string sourceHtml = Server.MapPath("/Files/Template.html");
            string targetPdf  = Server.MapPath("/Files/sample.pdf");

            #region Itext

            //using (var htmlStream = new FileStream(SRC,FileMode.Open))
            //using (var pdfStream = new FileStream(DEST, FileMode.Create))
            //{
            //    try
            //    {
            //        HtmlConverter.ConvertToPdf(htmlStream, pdfStream);
            //    }
            //    finally
            //    {
            //        htmlStream.Close();
            //        pdfStream.Close();
            //    }
            //}

            #endregion

            #region Select.Pdf

            SelectPdf.HtmlToPdf   converter = new SelectPdf.HtmlToPdf();
            SelectPdf.PdfDocument doc       = converter.ConvertHtmlString(System.IO.File.ReadAllText(sourceHtml));
            doc.Save(targetPdf);
            doc.Close();

            #endregion

            return(Json("OK"));
        }
Exemple #6
0
        public ActionResult DisruptAutoInvoice(List <DisruptInvoice> SendInvoice)
        {
            string DocName = "DisruptInvoiceBalance";

            var path     = System.IO.Path.GetTempPath();
            var fileName = DocName + ".pdf";
            var var      = System.IO.Path.Combine(path, fileName);


            bool isFromDiller = false;

            string htmlString = RenderViewAsString("Utils", "~/Views/Utils/DisruptInvoiceBalance.cshtml", SendInvoice, isFromDiller);

            string baseUrl = "";         // collection["TxtBaseUrl"];

            string pdf_page_size = "A4"; // collection["DdlPageSize"];

            SelectPdf.PdfPageSize pageSize = (SelectPdf.PdfPageSize)Enum.Parse(typeof(SelectPdf.PdfPageSize),
                                                                               pdf_page_size, true);

            string pdf_orientation = "Portrait";// collection["DdlPageOrientation"];

            SelectPdf.PdfPageOrientation pdfOrientation =
                (SelectPdf.PdfPageOrientation)Enum.Parse(typeof(SelectPdf.PdfPageOrientation),
                                                         pdf_orientation, true);

            string pdf_align = "Justify";// collection["DdlPageOrientation"];

            SelectPdf.PdfTextHorizontalAlign pdfTextAlign =
                (SelectPdf.PdfTextHorizontalAlign)Enum.Parse(typeof(SelectPdf.PdfTextHorizontalAlign),
                                                             pdf_align, true);

            int webPageWidth = 1024;

            int webPageHeight = 0;

            SelectPdf.HtmlToPdf converter = new SelectPdf.HtmlToPdf();


            // set converter options
            converter.Options.PdfPageSize        = pageSize;
            converter.Options.PdfPageOrientation = pdfOrientation;
            converter.Options.WebPageWidth       = webPageWidth;
            converter.Options.WebPageHeight      = webPageHeight;

            // create a new pdf document converting an url
            SelectPdf.PdfDocument doc = converter.ConvertHtmlString(htmlString, baseUrl);
            var FolderName            = (@"C:\JuridicalInvoice\DisruptInvoice\" + DateTime.Now.ToString("dd-MM-yyyy"));

            if (!Directory.Exists(FolderName))

            {
                Directory.CreateDirectory(FolderName);
            }
            var name = SplitAddresName("DigitalTv Invoice " + SendInvoice.Select(s => s.Invoices_Code).FirstOrDefault());

            doc.Save(FolderName + '\\' + name);
            return(null);
        }
            private void PrintPDF(D3jsLib.Report report, D3jsLib.PdfStyle style, string filePath)
            {
                HtmlDocument htmlDoc = new HtmlDocument();

                htmlDoc.LoadHtml(report.HtmlString);

                HtmlNodeCollection nodes = htmlDoc.DocumentNode.SelectNodes("//div[@class='gridster-box']");

                foreach (HtmlNode n in nodes)
                {
                    n.InnerHtml = "";
                }

                // attempt to move *dep file
                D3jsLib.Utilities.ChartsUtilities.MoveDepFile();

                // create converter
                SelectPdf.HtmlToPdf converter = new SelectPdf.HtmlToPdf();

                // set converter options
                SelectPdf.HtmlToPdfOptions options = converter.Options;
                options.PdfPageOrientation   = style.Orientation;
                options.PdfPageSize          = style.Size;
                options.JpegCompressionLevel = style.Compression;
                options.JavaScriptEnabled    = true;
                options.EmbedFonts           = true;
                options.KeepImagesTogether   = true;
                options.KeepTextsTogether    = true;
                options.AutoFitHeight        = style.VerticalFit;
                options.AutoFitWidth         = style.HorizontalFit;
                options.MarginTop            = style.MarginTop;
                options.MarginRight          = style.MarginRight;
                options.MarginBottom         = style.MarginBottom;
                options.MarginLeft           = style.MarginLeft;

                // created unescaped file path removes %20 from path etc.
                string finalFilePath = filePath;

                Uri    uri = new Uri(filePath);
                string absoluteFilePath = Uri.UnescapeDataString(uri.AbsoluteUri);

                if (Uri.IsWellFormedUriString(absoluteFilePath, UriKind.RelativeOrAbsolute))
                {
                    Uri newUri = new Uri(absoluteFilePath);
                    finalFilePath = newUri.LocalPath;
                }

                try
                {
                    // convert html to document object and save
                    SelectPdf.PdfDocument pdfDoc = converter.ConvertHtmlString(htmlDoc.DocumentNode.InnerHtml);
                    pdfDoc.Save(finalFilePath);
                    pdfDoc.Close();
                }
                catch
                {
                    MessageBox.Show("Printing failed. Is file open in another application?");
                }
            }
Exemple #8
0
 public static void PdfConvtrFunction()
 {
     SelectPdf.HtmlToPdf converter = new SelectPdf.HtmlToPdf();
     //SelectPdf.PdfDocument doc = converter.ConvertUrl("http://www.nexthermal.org/ConfigBasic/GetConfigDiag");
     SelectPdf.PdfDocument doc = converter.ConvertUrl("http://localhost:61404/ConfigBasic/GetConfigDiag");
     doc.Save(System.Web.HttpContext.Current.Server.MapPath("~/Uploads/test.pdf"));  //save in local, send from local, delete from local
     doc.Close();
 }
Exemple #9
0
    private void GenerateHTML_TO_PDF(string HtmlString, bool ResponseShow, string FileName, bool SaveFileDir)
    {
        try
        {
            string pdf_page_size           = "A4";
            SelectPdf.PdfPageSize pageSize = (SelectPdf.PdfPageSize)Enum.Parse(typeof(SelectPdf.PdfPageSize),
                                                                               pdf_page_size, true);

            string pdf_orientation = "Portrait";
            SelectPdf.PdfPageOrientation pdfOrientation =
                (SelectPdf.PdfPageOrientation)Enum.Parse(typeof(SelectPdf.PdfPageOrientation),
                                                         pdf_orientation, true);


            int webPageWidth = 1024;


            int webPageHeight = 0;

            SelectPdf.PdfMargins margin = new SelectPdf.PdfMargins(1, 1, 1, 1);


            // instantiate a html to pdf converter object
            SelectPdf.HtmlToPdf converter = new SelectPdf.HtmlToPdf();

            // set converter options
            converter.Options.PdfPageSize        = pageSize;
            converter.Options.PdfPageOrientation = pdfOrientation;

            converter.Options.WebPageWidth  = webPageWidth;
            converter.Options.WebPageHeight = webPageHeight;
            converter.Options.MarginBottom  = 100;
            converter.Options.MarginTop     = 75;
            //converter.Options.MarginBottom=margin;
            // create a new pdf document converting an url
            SelectPdf.PdfDocument doc = converter.ConvertHtmlString(HtmlString, "");

            //doc.AddPage(pageSize, margin, pdfOrientation);\


            // save pdf document

            if (!SaveFileDir)
            {
                doc.Save(Response, ResponseShow, FileName);
            }
            else
            {
                doc.Save(FileName);
            }

            doc.Close();
        }
        catch (Exception ex)
        {
            ExceptionLogging.SendExcepToDB(ex);
        }
    }
    private void GenerateHTML_TO_PDF(string HtmlString, bool ResponseShow, string FileName, bool SaveFileDir)
    {
        try
        {
            string pdf_page_size           = "A4";
            SelectPdf.PdfPageSize pageSize = (SelectPdf.PdfPageSize)Enum.Parse(typeof(SelectPdf.PdfPageSize),
                                                                               pdf_page_size, true);

            string pdf_orientation = "Portrait";
            SelectPdf.PdfPageOrientation pdfOrientation =
                (SelectPdf.PdfPageOrientation)Enum.Parse(typeof(SelectPdf.PdfPageOrientation),
                                                         pdf_orientation, true);


            int webPageWidth = 1024;


            int webPageHeight = 0;



            // instantiate a html to pdf converter object
            SelectPdf.HtmlToPdf converter = new SelectPdf.HtmlToPdf();

            // set converter options
            converter.Options.PdfPageSize        = pageSize;
            converter.Options.PdfPageOrientation = pdfOrientation;
            converter.Options.WebPageWidth       = webPageWidth;
            converter.Options.WebPageHeight      = webPageHeight;

            // create a new pdf document converting an url
            SelectPdf.PdfDocument doc = converter.ConvertHtmlString(HtmlString, "");


            doc.Save(FileName);


            string    FilePath   = FileName;
            WebClient User       = new WebClient();
            Byte[]    FileBuffer = User.DownloadData(FilePath);
            if (FileBuffer != null)
            {
                Response.ContentType = "application/pdf";
                Response.AddHeader("content-length", FileBuffer.Length.ToString());
                Response.BinaryWrite(FileBuffer);
            }


            //if (FileName != "")
            //    doc.Save(FileName);

            doc.Close();
        }
        catch (Exception ex)
        {
            lblMsg.Text = _objBOUtiltiy.ShowMessage("danger", "Danger", ex.Message);
        }
    }
Exemple #11
0
    private bool GenerateHTML_TO_PDF(string HtmlString, bool ResponseShow, string Path, bool SaveFileDir, string QuoteNumber)
    {
        try
        {
            string pdf_page_size           = "A4";
            SelectPdf.PdfPageSize pageSize = (SelectPdf.PdfPageSize)Enum.Parse(typeof(SelectPdf.PdfPageSize),
                                                                               pdf_page_size, true);

            string pdf_orientation = "Portrait";
            SelectPdf.PdfPageOrientation pdfOrientation =
                (SelectPdf.PdfPageOrientation)Enum.Parse(typeof(SelectPdf.PdfPageOrientation),
                                                         pdf_orientation, true);

            int webPageWidth  = 1024;
            int webPageHeight = 0;

            // instantiate a html to pdf converter object
            SelectPdf.HtmlToPdf converter = new SelectPdf.HtmlToPdf();

            // set converter options
            converter.Options.PdfPageSize        = pageSize;
            converter.Options.PdfPageOrientation = pdfOrientation;
            converter.Options.WebPageWidth       = webPageWidth;
            converter.Options.WebPageHeight      = webPageHeight;

            // create a new pdf document converting an url
            SelectPdf.PdfDocument doc = converter.ConvertHtmlString(HtmlString, "");

            // save pdf document

            //if (!SaveFileDir)
            //    doc.Save(Response, ResponseShow, Path);
            //else
            //    doc.Save(Path);

            string FileName = Path + "/" + QuoteNumber + ".pdf";

            if (!Directory.Exists(Path))
            {
                Directory.CreateDirectory(Path);
            }
            else
            {
                if (File.Exists(FileName))
                {
                    File.Delete(FileName);
                }
            }

            doc.Save(FileName);

            doc.Close();

            return(true);
        }
        catch
        { return(false); }
    }
Exemple #12
0
 private void btnPDF_Click(object sender, EventArgs e)
 {
     SelectPdf.HtmlToPdf converter = new SelectPdf.HtmlToPdf();
     converter.Options.MarginBottom       = 10;
     converter.Options.MarginLeft         = 10;
     converter.Options.MarginRight        = 10;
     converter.Options.MarginTop          = 10;
     converter.Options.EmbedFonts         = true;
     converter.Options.DrawBackground     = true;
     converter.Options.JavaScriptEnabled  = true;
     converter.Options.KeepImagesTogether = true;
     SelectPdf.PdfDocument doc = converter.ConvertUrl("http://portal.exponent-ts.com/Report/FlightReport/236");
     doc.Save($"C:\\007\\Test-{DateTime.Now.Ticks}.pdf");
     doc.Close();
 }
        public IActionResult GetHolidayPdf(int Id)
        {
            var pdflist = _ctx.Holiday.Where(a => a.Id == Id).Select(s => new HolidayViewModel()
            {
                User = s.User.Name, RequestDate = s.RequestDate
            }).ToList();
            string pdfname = ("IzınPdf/" + pdflist[0].User + "-" + pdflist[0].RequestDate.ToString("dd-MM-yyyy-HH-mm-ss") + ".pdf").ToString();
            string pdfurl  = "https://" + url + "/Holiday/GetHolidayHtml/" + Id;

            SelectPdf.HtmlToPdf   converter = new SelectPdf.HtmlToPdf();
            SelectPdf.PdfDocument doc       = converter.ConvertUrl(pdfurl);
            doc.Save(pdfname);
            doc.Close();
            return(File(System.IO.File.ReadAllBytes(pdfname), "application/pdf", pdflist[0].User + "-" + pdflist[0].RequestDate.ToString("dd-MM-yyyy-HH-mm-ss") + ".pdf"));
        }
Exemple #14
0
        protected override byte[] GetPDFFromUrl(string url)
        {
            byte[] _bPDF = null;

            SelectPdf.HtmlToPdf   converter = new SelectPdf.HtmlToPdf();
            SelectPdf.PdfDocument doc       = converter.ConvertUrl(url);

            // save pdf document
            _bPDF = doc.Save();

            // close pdf document
            doc.Close();

            return(_bPDF);
        }
Exemple #15
0
        public static string RetornaPDF(string endereco, string arquivo, string pasta, string strCaminho, string html)
        {
            //try
            //{
            if (html == "")
            {
                html = retornaHTML(endereco);
            }
            string baseUrl       = endereco;
            bool   nullRoot      = true;
            string retorno       = "";
            var    caminhoFisico = @strCaminho;
            var    caminho       = "";

            if (nullRoot)
            {
                caminho = Path.Combine(caminhoFisico, pasta);
            }

            if (!Directory.Exists(caminho))
            {
                System.IO.Directory.CreateDirectory(caminho);
            }
            bool existeArquivo = System.IO.File.Exists(caminho + "\\" + arquivo);

            if (!existeArquivo)
            {
                //PdfDocument pdf = PdfGenerator.GeneratePdf(html, PageSize.A4);
                //pdf.Save(caminho + arquivo);
                SelectPdf.HtmlToPdf   converter = new SelectPdf.HtmlToPdf();
                SelectPdf.PdfDocument doc       = converter.ConvertHtmlString(html, baseUrl);
                doc.Save(caminho + "\\" + arquivo);
                doc.Close();
                retorno = "pdfGerado";
            }
            else
            {
                retorno = "pdfExistente";
            }
            return(retorno);
            //}
            //catch (Exception)
            //{
//
//	return "Erro";
//}
//
        }
Exemple #16
0
        public byte[] PrintToPDF()
        {
            //string url = string.Format(Devmasters.Core.Util.Config.GetConfigValue("SiteURL") + "api/InvoicePrint.ashx?id={0}&h={1}",
            //    this.ID, System.Web.HttpUtility.UrlEncode(this.GetInvoiceHash()));
            //url = url.Trim();
            //return Feedback.Lib.PDF.Net.PDFClient.GetURLinPDF(url);

            SelectPdf.HtmlToPdf   converter = new SelectPdf.HtmlToPdf();
            SelectPdf.PdfDocument doc       = converter.ConvertHtmlString(Print2Html());
            using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
            {
                doc.Save(ms);
                doc.Close();
                return(ms.ToArray());
            }
        }
    private void GenerateHTML_TO_PDF(string HtmlString, bool ResponseShow, string FileName, bool SaveFileDir)
    {
        string pdf_page_size = "A4";

        SelectPdf.PdfPageSize pageSize = (SelectPdf.PdfPageSize)Enum.Parse(typeof(SelectPdf.PdfPageSize),
                                                                           pdf_page_size, true);

        string pdf_orientation = "Portrait";

        SelectPdf.PdfPageOrientation pdfOrientation =
            (SelectPdf.PdfPageOrientation)Enum.Parse(typeof(SelectPdf.PdfPageOrientation),
                                                     pdf_orientation, true);


        int webPageWidth = 1024;


        int webPageHeight = 0;



        // instantiate a html to pdf converter object
        SelectPdf.HtmlToPdf converter = new SelectPdf.HtmlToPdf();

        // set converter options
        converter.Options.PdfPageSize        = pageSize;
        converter.Options.PdfPageOrientation = pdfOrientation;
        converter.Options.WebPageWidth       = webPageWidth;
        converter.Options.WebPageHeight      = webPageHeight;

        // create a new pdf document converting an url
        SelectPdf.PdfDocument doc = converter.ConvertHtmlString(HtmlString, "");

        // save pdf document
        if (!SaveFileDir)
        {
            doc.Save(Response, ResponseShow, FileName);
        }
        else
        {
            doc.Save(FileName);
        }

        // close pdf document
        doc.Close();
    }
Exemple #18
0
        public string CreatePDF(string projectID)
        {
            SelectPdf.HtmlToPdf converter = new SelectPdf.HtmlToPdf();
            converter.Options.PdfPageSize        = SelectPdf.PdfPageSize.A4;
            converter.Options.PdfPageOrientation = SelectPdf.PdfPageOrientation.Landscape;

            string url = "http://*****:*****@"~\PDFs\") + fileName;

            doc.Save(pdfPath);
            doc.Close();

            return(fileName);
        }
Exemple #19
0
 public override void WriteToStream(Type type, object value, Stream writeStream, System.Net.Http.HttpContent content)
 {
     using (var writer = new StreamWriter(writeStream))
     {
         var lp = value as LearningPlanDTO;
         if (lp == null)
         {
             throw new InvalidOperationException("Cannot serialize type");
         }
         var converter = new SelectPdf.HtmlToPdf();
         var html      = ViewRenderer.RenderView("~/Views/LearningPlanPDF.cshtml", lp);
         converter.Options.MarginTop    = 35;
         converter.Options.MarginBottom = 35;
         var doc = converter.ConvertHtmlString(html);
         doc.Save(writeStream);
     }
 }
        public async Task <bool> GenerateReport()
        {
            String ReportPath     = ConfigurationManager.AppSettings["ReportPath"];
            String ReportURL      = ConfigurationManager.AppSettings["ReportURL"] + _FlightID.ToString();
            String ReportEmailURL = ConfigurationManager.AppSettings["ReportEmailURL"] + _FlightID.ToString();
            String PDFPath        = System.IO.Path.Combine(ReportPath, $"{_FlightID}.pdf");

            //Generate PDF
            SelectPdf.HtmlToPdf converter = new SelectPdf.HtmlToPdf();
            converter.Options.MarginBottom       = 10;
            converter.Options.MarginLeft         = 10;
            converter.Options.MarginRight        = 10;
            converter.Options.MarginTop          = 10;
            converter.Options.EmbedFonts         = true;
            converter.Options.DrawBackground     = true;
            converter.Options.JavaScriptEnabled  = true;
            converter.Options.KeepImagesTogether = true;
            try {
                SelectPdf.PdfDocument doc = converter.ConvertUrl(ReportURL);
                doc.Save(PDFPath);
                doc.Close();
            } catch {
                return(false);
            }

            String NotificationEmails = _Approval?.EmailAddress;

            PortalAlertEmail portalAlertEmail = new PortalAlertEmail {
                CreatedOn    = DateTime.UtcNow,
                Attachments  = PDFPath,
                Body         = null,
                EmailSubject = $"Post Flight Report - {_FlightID}",
                EmailURL     = ReportEmailURL,
                SendType     = "Email",
                ToAddress    = NotificationEmails,
                IsSend       = 0,
                SendStatus   = "Waiting",
                UserID       = PilotID,
                SendOn       = null
            };

            await AlertQueue.AddToEmailQueue(portalAlertEmail);

            return(false);
        }
Exemple #21
0
        private void PrintPDF(D3jsLib.Report report, D3jsLib.PdfStyle style, string filePath)
        {
            HtmlDocument htmlDoc = new HtmlDocument();

            htmlDoc.LoadHtml(report.HtmlString);

            HtmlNodeCollection nodes = htmlDoc.DocumentNode.SelectNodes("//div[@class='gridster-box']");

            foreach (HtmlNode n in nodes)
            {
                n.InnerHtml = "";
            }

            // create converter
            SelectPdf.HtmlToPdf converter = new SelectPdf.HtmlToPdf();

            // set converter options
            SelectPdf.HtmlToPdfOptions options = converter.Options;
            options.PdfPageOrientation   = style.Orientation;
            options.PdfPageSize          = style.Size;
            options.JpegCompressionLevel = style.Compression;
            options.JavaScriptEnabled    = true;
            options.EmbedFonts           = true;
            options.KeepImagesTogether   = true;
            options.KeepTextsTogether    = true;
            options.AutoFitHeight        = style.VerticalFit;
            options.AutoFitWidth         = style.HorizontalFit;
            options.MarginTop            = style.MarginTop;
            options.MarginRight          = style.MarginRight;
            options.MarginBottom         = style.MarginBottom;
            options.MarginLeft           = style.MarginLeft;

            try
            {
                // convert html to document object and save
                SelectPdf.PdfDocument pdfDoc = converter.ConvertHtmlString(htmlDoc.DocumentNode.InnerHtml);
                pdfDoc.Save(filePath);
                pdfDoc.Close();
            }
            catch
            {
                MessageBox.Show("Printing failed. Is file open in another application?");
            }
        }
        public IActionResult ConvertToPdfAjax(string sourceUrl)
        {
            SelectPdf.HtmlToPdf   converter = new SelectPdf.HtmlToPdf();
            SelectPdf.PdfDocument doc       = converter.ConvertUrl(sourceUrl);

            MemoryStream ms = new MemoryStream();

            doc.Save(ms);
            doc.Close();

            ms.Position = 0;

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

            return(fileStreamResult);
        }
Exemple #23
0
        public async Task <string> UploadToAzureStorageAsync(string html, string filename, int customerId, int jobId)
        {
            SelectPdf.HtmlToPdf   convert = new SelectPdf.HtmlToPdf();
            SelectPdf.PdfDocument doc     = convert.ConvertHtmlString(html);
            var pdfBytes = doc.Save();

            try
            {
                using (Stream stream = new MemoryStream(pdfBytes))
                {
                    string connectionString = Configuration["AzureStorage:FifeShutters:ConnectionString"];
                    var    containerName    = $"invoices";
                    BlobContainerClient blobContainerClient = new BlobContainerClient(connectionString, containerName);
                    //await blobContainerClient.CreateIfNotExistsAsync();
                    await blobContainerClient.UploadBlobAsync($"{customerId}/{jobId}/{filename}", stream);

                    return(filename);
                }
            }
            catch (Exception e) { throw e; }
        }
Exemple #24
0
        //test git

        public string CreatePDF(string projectID, string userID)
        {
            SelectPdf.HtmlToPdf converter = new SelectPdf.HtmlToPdf();
            converter.Options.PdfPageSize        = SelectPdf.PdfPageSize.A4;
            converter.Options.PdfPageOrientation = SelectPdf.PdfPageOrientation.Portrait;
            converter.Options.MarginLeft         = 20;
            converter.Options.MarginRight        = 20;
            converter.Options.MarginTop          = 20;
            converter.Options.MarginBottom       = 20;

            string url = "http://*****:*****@"~\PDFs\") + fileName;

            doc.Save(pdfPath);
            doc.Close();

            return(fileName);
        }
        public FileModel WordToPdf(byte[] data, string fileName = null)
        {
            byte[] byteArray = data;
            using (MemoryStream memoryStream = new MemoryStream()) {
                memoryStream.Write(byteArray, 0, byteArray.Length);
                using (WordprocessingDocument doc =
                           WordprocessingDocument.Open(memoryStream, true)) {
                    HtmlConverterSettings settings = new HtmlConverterSettings()
                    {
                        //PageTitle = "My Page Title"
                        AdditionalCss = "td { border : 1px solid #000 !important; }"
                    };
                    XElement html = HtmlConverter.ConvertToHtml(doc, settings);

                    SelectPdf.HtmlToPdf htmlToPdf = new SelectPdf.HtmlToPdf();

                    return(_pdfSvc.GetPdfFromHtmlString(html.ToStringNewLineOnAttributes(), Path.GetFileNameWithoutExtension(fileName) ?? "Document" + ".pdf"));

                    //File.writeal(@"Test.html", html.ToStringNewLineOnAttributes());
                }
            }
        }
 public ActionResult Facture(int id)
 {
     using (var writer = new StringWriter())
     {
         Commande commande = service.find(id, User.Identity.GetUserId());
         if (commande == null)
         {
             return(RedirectToAction("Commande"));
         }
         ViewData.Model = commande;
         var         partial     = ViewEngines.Engines.FindView(ControllerContext, "Facture", "_Layout");
         ViewContext viewContext = new ViewContext(ControllerContext, partial.View, ViewData, TempData, writer);
         partial.View.Render(viewContext, writer);
         SelectPdf.HtmlToPdf   converter = new SelectPdf.HtmlToPdf();
         SelectPdf.PdfDocument doc       = converter.ConvertHtmlString(writer.ToString(), Request.Url.AbsoluteUri);
         byte[] pdf = doc.Save();
         doc.Close();
         FileResult file = new FileContentResult(pdf, "application/pdf");
         file.FileDownloadName = "Facture" + DateTime.Now.ToString() + ".pdf";
         return(file);
     }
 }
Exemple #27
0
        public ActionResult PrintContent(int id)
        {
            HelpLevel3 helpLevel3 = helpLevel3DB.GetHelpLevel3ById(id);

            if (helpLevel3 == null)
            {
                ViewBag.ErrorMessage = "Can not find this recource";
                return(RedirectToAction("Index"));
            }
            SelectPdf.HtmlToPdf converter = new SelectPdf.HtmlToPdf();
            string    url      = ConfigurationManager.AppSettings["HelpOnlineHTMLPath"].ToString() + helpLevel3.URL;
            WebClient client   = new WebClient();
            String    htmlCode = client.DownloadString(Server.MapPath(url));

            SelectPdf.PdfDocument doc = converter.ConvertHtmlString(htmlCode);
            string fileToSave         = ConfigurationManager.AppSettings["HelpOnlineHTMLPath"].ToString();

            fileToSave += "Download.pdf";
            fileToSave  = Server.MapPath(fileToSave);
            doc.Save(fileToSave);
            doc.Close();
            byte[] FileBytes = System.IO.File.ReadAllBytes(fileToSave);
            return(File(FileBytes, "application/pdf"));
        }
Exemple #28
0
        public IHttpActionResult PostSendEmailWithPDF(int id, PostSendEmailWithPDFRequest request)
        {
            var currentUser = AppUserManager.FindById(User.Identity.GetUserId());
            var program     = GetCoachingPrograms(currentUser)
                              .FirstOrDefault(i => i.Id == id);
            var lp = new LearningPlanDTO
            {
                Id              = program.Id,
                LearningPlan    = program.LearningPlan,
                UpdatedAt       = program.UpdatedAt,
                CoachingProgram = program,
            };

            var emailHtml = ViewRenderer.RenderView("~/Views/Email/Send Learning Plan as PDF.cshtml",
                                                    new System.Web.Mvc.ViewDataDictionary {
                { "Program", program },
            });

            using (var fileStream = new MemoryStream())
            {
                var coacheeName = String.Format("{0} {1}", currentUser.FirstName, currentUser.LastName);
                var subject     = String.Format("right.now. Coaching Learning Plan for {0}", coacheeName);

                var html      = ViewRenderer.RenderView("~/Views/LearningPlanPDF.cshtml", lp);
                var converter = new SelectPdf.HtmlToPdf();
                converter.Options.MarginTop    = 35;
                converter.Options.MarginBottom = 35;
                var doc = converter.ConvertHtmlString(html);
                doc.Save(fileStream);
                fileStream.Position = 0;
                var attachment = new Attachment(fileStream, subject, "application/pdf");

                EmailSender.SendEmail(request.recipients, subject, emailHtml, attachment);
            }
            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemple #29
0
        public static void ConvertHTMLtoPDF(PurchaseOrdersItem purchaseOrderItem, Warehouses warehouses)
        {
            var       file             = AppDomain.CurrentDomain.BaseDirectory + @"Bill\Page.html";
            var       tempHtmlTemplate = AppDomain.CurrentDomain.BaseDirectory + @"Bill\customhtml.html";
            var       htmlTemplate     = System.IO.File.ReadAllText(file);
            string    path             = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            Warehouse warehouse        = warehouses.Items.Count > 0 ? warehouses.Items.SingleOrDefault() : new Warehouse();

            StringBuilder sb = new StringBuilder();

            string orderDate       = String.Empty;
            string orderNumber     = String.Empty;
            string requiredDate    = String.Empty;
            string supplierCode    = String.Empty;
            string referenceNumber = String.Empty;

            orderDate       = purchaseOrderItem.OrderDate.ToString("dd/MM/yyyy");
            requiredDate    = purchaseOrderItem.RequiredDate.ToString("dd/MM/yyyy");
            orderNumber     = purchaseOrderItem.OrderNumber;
            supplierCode    = purchaseOrderItem.Supplier == null ? "" : purchaseOrderItem.Supplier.SupplierCode;
            referenceNumber = purchaseOrderItem.Guid;

            double subTotal      = purchaseOrderItem.SubTotal ?? 0;
            double taxTotal      = purchaseOrderItem.TaxTotal ?? 0;
            double completeTotal = purchaseOrderItem.Total ?? 0;

            htmlTemplate = htmlTemplate.Replace("##DeliveryName##", warehouse == null ? "" : warehouse.StreetNo);
            htmlTemplate = htmlTemplate.Replace("##StreetAddress##", warehouse == null ? "" : warehouse.AddressLine1);
            htmlTemplate = htmlTemplate.Replace("##Suburb##", warehouse == null ? "" : warehouse.AddressLine2);
            htmlTemplate = htmlTemplate.Replace("##State##", warehouse == null ? "" : warehouse.Region);
            htmlTemplate = htmlTemplate.Replace("##PostalCode##", warehouse == null ? "" : warehouse.PostCode);
            htmlTemplate = htmlTemplate.Replace("##SupCode##", supplierCode);
            htmlTemplate = htmlTemplate.Replace("##PhoneNumber##", warehouse == null ? "" : warehouse.PhoneNumber);

            // Items in the Purchase Order
            foreach (var lineItem in purchaseOrderItem.PurchaseOrderLines)
            {
                var    lineItemProduct      = CommonCode.GetProductInformation(lineItem.Product != null ? lineItem.Product.ProductCode : "");
                string lineItemSupplierCode = (lineItemProduct.Items.Count > 0 && lineItemProduct.Items.FirstOrDefault().Supplier != null) ? lineItemProduct.Items.FirstOrDefault().Supplier.SupplierProductCode : "";
                string lineItemNumber       = lineItem.LineNumber.ToString();
                string lineItemProductCode  = lineItem.Product.ProductCode;
                string lineItemDescription  = lineItem.Product.ProductDescription;
                string lineItemQuantity     = lineItem.OrderQuantity.ToString();
                string lineItemUnits        = lineItem.Product != null && lineItem.Product.UnitOfMeasure != null ? lineItem.Product.UnitOfMeasure.Name : "";
                double lineItemUnitPrice    = lineItem.UnitPrice ?? 0;
                double lineItemTotal        = lineItem.LineTotal ?? 0;
                double lineItemTax          = lineItem.LineTax ?? 0;

                string htmlFormat = string.Format(
                    "<tr style='border-bottom:2px solid #ddd;'><th style = 'padding: 5px 0; border-bottom:1px solid #ddd;'><p style = 'margin:0; font-weight:normal; font-size: 13px;' >{0}</p></th>"
                    + "<th style = 'padding:5px 0; border-bottom:1px solid #ddd;'><p style = 'margin:0; font-weight:normal;font-size: 13px;'>{1}</p></th>"
                    + "<th style = 'padding:5px 0; border-bottom:1px solid #ddd;'><p style = 'margin:0; font-weight:normal;font-size: 13px;'> {2} </p></th>"
                    + "<th style = 'padding:5px 0; border-bottom:1px solid #ddd;'><p style = 'margin:0; font-weight:normal;font-size: 13px;'> {3}</p></th>"
                    + "<th style = 'padding:5px 0; border-bottom:1px solid #ddd;'><p style = 'margin:0; font-weight:normal;font-size: 13px;'> {4} </p></th>"
                    + "<th style = 'padding:5px 0; border-bottom:1px solid #ddd;'><p style = 'margin:0; font-weight:normal;font-size: 13px;'> {5} </p></th>"
                    + "<th style = 'padding:5px 0; border-bottom:1px solid #ddd;'><p style = 'margin:0; font-weight:normal;font-size: 13px;'> {6} </p></th>"
                    + "<th style = 'padding:5px 0; border-bottom:1px solid #ddd;'><p style = 'margin:0; font-weight:normal;font-size: 13px;'> {7} </p></th>"
                    + "<th style = 'padding:5px 0; border-bottom:1px solid #ddd;'><p style = 'margin:0; font-weight:normal;font-size: 13px;'> {8} </p></th></tr>",
                    lineItemNumber, lineItemSupplierCode, lineItemProductCode, lineItemDescription, lineItemQuantity, lineItemUnits, lineItemUnitPrice.ToString("0.00"), lineItemTotal.ToString("0.00"), lineItemTax.ToString("0.00")
                    );

                sb.Append(htmlFormat);
            }

            htmlTemplate = htmlTemplate.Replace("##RequiredDate##", requiredDate);
            htmlTemplate = htmlTemplate.Replace("##OrderDate##", orderDate);
            htmlTemplate = htmlTemplate.Replace("##OrderNumber##", orderNumber);
            htmlTemplate = htmlTemplate.Replace("##SupplierCode##", supplierCode);
            htmlTemplate = htmlTemplate.Replace("##ReferenceNumber##", referenceNumber);
            htmlTemplate = htmlTemplate.Replace("##ReplaceBodyContent##", sb.ToString());

            htmlTemplate = htmlTemplate.Replace("##SubTotal##", subTotal.ToString("0.00"));
            htmlTemplate = htmlTemplate.Replace("##TaxTotal##", taxTotal.ToString("0.00"));
            htmlTemplate = htmlTemplate.Replace("##CompleteTotal##", completeTotal.ToString("0.00"));
            htmlTemplate = htmlTemplate.Replace("##Instruments##", purchaseOrderItem.Supplier.SupplierName);
            htmlTemplate = htmlTemplate.Replace("##Comments##", purchaseOrderItem.Comments);

            System.IO.File.WriteAllText(tempHtmlTemplate, htmlTemplate);

            SelectPdf.HtmlToPdf pdfFile = new SelectPdf.HtmlToPdf();
            pdfFile.Options.MarginRight = 5;
            pdfFile.Options.MarginRight = 5;

            SelectPdf.PdfDocument document = pdfFile.ConvertUrl(tempHtmlTemplate);

            string directory = path + "//Purchase Orders";

            if (!System.IO.Directory.Exists(directory))
            {
                System.IO.Directory.CreateDirectory(directory);
            }

            string pdfDocument = directory + "//Purchase Order_" + purchaseOrderItem.OrderNumber + "_" + DateTime.Now.ToString("yyyy.dd.MM").Replace("/", ".") + "-" + purchaseOrderItem.Supplier.SupplierName.Replace("/", "_") + ".pdf";

            document.Save(pdfDocument);
            document.Close();
        }
Exemple #30
0
    private bool GenerateHTML_TO_PDF1(string HtmlString, bool ResponseShow, string Path, bool SaveFileDir, string QuoteNumber)
    {
        try
        {
            string pdf_page_size           = "A4";
            SelectPdf.PdfPageSize pageSize = (SelectPdf.PdfPageSize)Enum.Parse(typeof(SelectPdf.PdfPageSize),
                                                                               pdf_page_size, true);

            string pdf_orientation = "Portrait";
            SelectPdf.PdfPageOrientation pdfOrientation =
                (SelectPdf.PdfPageOrientation)Enum.Parse(typeof(SelectPdf.PdfPageOrientation),
                                                         pdf_orientation, true);

            int webPageWidth  = 1024;
            int webPageHeight = 0;

            // instantiate a html to pdf converter object
            SelectPdf.HtmlToPdf converter = new SelectPdf.HtmlToPdf();

            // set converter options
            converter.Options.PdfPageSize        = pageSize;
            converter.Options.PdfPageOrientation = pdfOrientation;
            converter.Options.WebPageWidth       = webPageWidth;
            converter.Options.WebPageHeight      = webPageHeight;

            // create a new pdf document converting an url
            SelectPdf.PdfDocument doc = converter.ConvertHtmlString(HtmlString, "");

            // save pdf document

            //if (!SaveFileDir)
            //    doc.Save(Response, ResponseShow, Path);
            //else
            //    doc.Save(Path);

            string FileName = Path + "/" + QuoteNumber + ".pdf";

            if (!Directory.Exists(Path))
            {
                Directory.CreateDirectory(Path);
            }
            else
            {
                if (File.Exists(FileName))
                {
                    File.Delete(FileName);
                }
            }

            doc.Save(FileName);

            //doc.Close();

            //doc.Save(FileName);


            string    FilePath   = FileName;
            WebClient User       = new WebClient();
            Byte[]    FileBuffer = User.DownloadData(FilePath);
            if (FileBuffer != null)
            {
                Response.ContentType = "application/pdf";
                Response.AddHeader("content-length", FileBuffer.Length.ToString());
                Response.BinaryWrite(FileBuffer);
            }


            //if (FileName != "")
            //    doc.Save(FileName);

            doc.Close();

            return(true);
        }
        catch
        { return(false); }
    }