Ejemplo n.º 1
0
        public string generateFile()
        {
            _writer.AddAttribute(HtmlTextWriterAttribute.Class, "container");
            _writer.RenderBeginTag(HtmlTextWriterTag.Div);             // open container

            header();
            head();
            persons();
            products();

            _writer.RenderEndTag();             // close container


            //string fileName = HttpContext.Current.Server.MapPath("~/newFile.html");
            string fileName = Guid.NewGuid().ToString() + "_" + _idUser + "_" + _nr.Replace('/', '-');
            string htmlFile = HttpContext.Current.Server.MapPath("~/" + fileName + ".html");

            File.WriteAllText(htmlFile, _stringWriter.ToString());

            HtmlToPdf render = new IronPdf.HtmlToPdf();

            render.PrintOptions.PaperSize = PdfPrintOptions.PdfPaperSize.A4;
            PdfDocument invoicePDF = render.RenderHTMLFileAsPdf(htmlFile);

            string pdfFile = HttpContext.Current.Server.MapPath("~/" + fileName + ".pdf");

            invoicePDF.SaveAs(pdfFile);

            File.Delete(htmlFile);

            return(pdfFile);
        }
        protected void lbn_exportToPdf_Click(object sender, EventArgs e)
        {
            using (FileStream fs = new FileStream("C:/Users/Barti/Downloads/Studenti.htm", FileMode.Create))
            {
                using (StreamWriter w = new StreamWriter(fs, Encoding.UTF8)) {
                    w.WriteLine("<!DOCTYPE html>");
                    w.WriteLine("<html>");
                    w.WriteLine("<body>");
                    w.WriteLine("<div style='padding:10px; border-style: groove; margin:-10px;'>");
                    w.WriteLine("<img src =\"C:/Users/Barti/Desktop/prova1/ProjektiFinal-1/ProjektiFinal/images/ut.jpg\"  style='float: left; width:142px; height:186px; padding-top:30px' />");
                    w.WriteLine("<img src=\"C:/Users/Barti/Desktop/prova1/ProjektiFinal-1/ProjektiFinal/images/fakulteti-i-ekonomise.jpg\" style ='float: right; width:150px; height:122px;margin-top:20px; padding-top:37px; '/>");
                    w.WriteLine("<h1 style='text-align:center; margin-right:100px;padding-top:50px;'>Universiteti i Tiranës </ h1 > ");
                    w.WriteLine("<h2 style='text-align:center; margin-bottom:80px; margin-right:100px; margin-top:28px;'>Fakulteti i Ekonomisë</h2>");
                    w.WriteLine("<h3 > Vërtetim i të dhënave tuaja nga regjistrimi:</h3>");
                    w.WriteLine("<p>Ky dokument lëshohet për qëllim verifikimi dhe regjistrimi nga FEUT. Të dhënat që sapo futët janë si këto më poshtë. Ju urojmë një vit akademik të suksesshëm. Ruajeni këtë dokument në pdf dhe dërgojeni në emailin tuaj.</p>");
                    w.WriteLine("<p>Stafi i Fakultetit të Ekonomisë !</p>");
                    w.WriteLine("</br><p style='font-size:28px; color:red; margin:auto; text-decoration: underline; text-align:center;'>Të dhënat e studentit: </p>");
                    w.WriteLine("<h4 style='background-color:Tomato; text-align:center;;'>Emri:" + txt_emri.Text + "</h4>");
                    w.WriteLine("<h4 style='background-color:Orange; text-align:center; '>Mbiemri: " + txt_mbiemri.Text + "</h4>");
                    w.WriteLine("<h4 style='background-color:MediumSeaGreen; text-align:center;' >Gjinia: " + rdb_gjinia.SelectedItem + "</h4>");
                    w.WriteLine("<h4 style='background-color:Gray; text-align:center;'>Koha e plotesimit: " + cal_koha.SelectedDate.ToString("dddd, dd MMMM yyyy") + "</h4>");
                    w.WriteLine("<h4 style='background-color:LightGray; text-align:center;'>Dega: " + ddl_dega.SelectedItem + "</h4>");

                    w.WriteLine("</br><p style='font-size:20px; color:green; margin:auto; text-decoration: underline; margin-bottom:30px;' > Të dhënat e gjeneruara në formë tabelare: </p> ");
                    w.WriteLine("<table style='border-collapse:collapse; table-layout:auto;' border = '3' opacity:'0.95' background-color:'grey';>");
                    w.WriteLine("<tbody>");
                    w.WriteLine("<tr>");
                    w.WriteLine("<td style='background-color:# 70000; color:blue; text-align:center; font-size:26px;'>Emri</td>");
                    w.WriteLine("<td style='background-color:# 70000; color:blue; text-align:center; font-size:26px;'>Mbiemri</td>");
                    w.WriteLine("<td style='background-color:# 70000; color:blue; text-align:center; font-size:26px;'>Gjinia</td>");
                    w.WriteLine("<td style='background-color:# 70000; color:blue; text-align:center; font-size:26px;'>Koha e plotësimit</td>");
                    w.WriteLine("<td style='background-color:# 70000; color:blue; text-align:center; font-size:26px;'>Dega</td>");
                    w.WriteLine("</tr>");
                    w.WriteLine("<tr>");
                    w.WriteLine("<td style='color:brown; text-align:center; font-size:19px;'>" + txt_emri.Text + "</td>");
                    w.WriteLine("<td style='color:brown; text-align:center; font-size:19px;'>" + txt_mbiemri.Text + "</td>");
                    w.WriteLine("<td style='color:brown; text-align:center; font-size:19px;'>" + rdb_gjinia.SelectedItem + "</td>");
                    w.WriteLine("<td style='color:brown; text-align:center; font-size:19px;'>" + cal_koha.SelectedDate.ToString("dddd, dd MMMM yyyy") + "</td>");
                    w.WriteLine("<td style='color:brown; text-align:center; font-size:19px;'>" + ddl_dega.SelectedItem + "</td>");
                    w.WriteLine("</tr>");
                    w.WriteLine("</tbody>");
                    w.WriteLine("</table>");
                    w.WriteLine("</br><a href='http://www.feut.edu.al/'>Faqja Kryesore e Fakultetit</a>");
                    w.WriteLine("<table style='width:100%;'>");
                    w.WriteLine("<tr><td><h3>Sekretarja</h3></td><td><h3> Dekani </h3></td><td><h3> Zv.Dekani </h3></td></tr>");
                    w.WriteLine("<tr><td style='font-size:21px;'>Lindita Zyka</td><td style='font-size:21px;'>Dhori Kule</td><td style='font-size:21px;'>Alban Korbi</td></tr>");
                    w.WriteLine("</table>");
                    w.WriteLine("</br></br></br></br>");
                    w.WriteLine("<hr><ul style='list-style-type: none; '><li>Adresa: Rruga Arben Broci, Tiranë</li><li>Kontakti: [email protected]</li></ul>");
                    w.WriteLine("</div>");
                    w.WriteLine("</body>");
                    w.WriteLine("</html>");
                }
                var Redender   = new IronPdf.HtmlToPdf();
                var PDF        = Redender.RenderHTMLFileAsPdf("C:/Users/Barti/Downloads/Studenti.htm");
                var OutputPath = "C:/Users/Barti/source/repos/studenti.pdf";
                PDF.SaveAs(OutputPath);
                System.Diagnostics.Process.Start("C:/Users/Barti/source/repos/studenti.pdf");
            }
        }
Ejemplo n.º 3
0
        public void getPDF()
        {
            var path = AppDomain.CurrentDomain.BaseDirectory;
            //var PDF = Renderer.RenderHtmlAsPdf("<h1>Hello IronPdf</h1>");
            var PDF        = Renderer.RenderHTMLFileAsPdf(path + "HTMLTemplate.html");
            var OutputPath = @"C:\Users\Actek\Documents\test\HtmlToPDF.pdf";

            PDF.SaveAs(OutputPath);
            // This neat trick opens our PDF file so we can see the result in our default PDF viewer
            //System.Diagnostics.Process.Start(OutputPath);
        }
Ejemplo n.º 4
0
        public void createInvoice(List <Ingressos> newIngressos, order newOrder)
        {
            string fileName = htmlBuilder.createInvoiceHTML(newIngressos, newOrder);

            var PDF = Renderer.RenderHTMLFileAsPdf(fileName + ".html");

            PDF.SaveAs(fileName + ".pdf");
            System.Diagnostics.Process.Start(fileName + ".pdf");
        }
Ejemplo n.º 5
0
        public void generePDF()
        {
            StringWriter stringWriter = new StringWriter();

            using (HtmlTextWriter writer = new HtmlTextWriter(stringWriter))
            {
                writer.Write(
                    "<!DOCTYPE html><html><head>" +
                    "<style>" +
                    "#calc {" +
                    "top: 350px;" +
                    "position: relative;" +
                    "}" +
                    "aside {" +
                    "border: 1px solid;" +
                    "padding: 0 10px 10px;" +
                    "position: absolute;" +
                    "}" +
                    "aside ul {" +
                    "list-style-type: none;" +
                    "margin: 0;" +
                    "padding: 0;" +
                    "}" +
                    "table {" +
                    "width: 100%;" +
                    "}" +
                    "table td[colspan] {" +
                    "text-align: right;" +
                    "padding: 0 20px;" +
                    "}" +
                    "table tfoot tr td:last-child {" +
                    "font-weight: bold;" +
                    "}" +
                    "#client {" +
                    "min-width: 150px;" +
                    "max-width: 500px;" +
                    "top: 10px;" +
                    "left: 10px;" +
                    "}" +
                    "#devis {" +
                    "min-width: 300px;" +
                    "max-width: 500px;" +
                    "top: 150px;" +
                    "right: 10px;" +
                    "}" +
                    "#sign-client {" +
                    "width: 200px;" +
                    "height: 150px;" +
                    "top: 800px;" +
                    "left: 10px;" +
                    "}" +
                    "#sign-commer {" +
                    "width: 200px;" +
                    "height: 150px;" +
                    "top: 800px;" +
                    "right: 10px;" +
                    "}" +
                    "#logo {" +
                    "position: absolute;" +
                    "top: 0;" +
                    "right: 0;" +
                    "}" +
                    "#logo img { width: 250px; }" +

                    ".right {" +
                    "display: inline-block;" +
                    "position: absolute;" +
                    "right: 1em;" +
                    "}" +
                    "/* bordure pour le tableau générale */" +
                    "table {" +
                    "border-collapse: collapse;" +
                    "}" +
                    "table tr {" +
                    "border-bottom: 1px solid #8a8787;" +
                    "}" +
                    "table td:last-child {" +
                    "text-align: right;" +
                    "border-left: 1px solid #8a8787;" +
                    "}" +

                    "/* bordure des totaux */" +
                    "tfoot::before {" +
                    "content: '';" +
                    "display: block;" +
                    "height: 18px;" +
                    "}" +
                    "table tfoot {" +
                    "margin-top: 20px;" +
                    "}" +
                    "table tfoot td {" +
                    "/*border-bottom: none;*/" +
                    "border: 1px solid #8a8787;" +
                    "}" +
                    "table tfoot tr, table tfoot td[colspan] {" +
                    "border: none;" +
                    "}" +
                    "</style>" +
                    "</head>" +
                    "<body>" +
                    "<section id=\"info\">" +

                    "<aside id=\"client\">" +
                    "<h2> Client</h2>" +
                    "<ul>" +
                    "<li><b>" + this.devClient.cliNom + "</b> " + this.devClient.cliPrenom + "</li>" +
                    "<li>" + this.devClient.cliNumRue + " " + this.devClient.cliRue + "</li>" +
                    "<li>" + this.devClient.cliCp + " <span class=\"right\">" + this.devClient.cliVille + "</span> </li>" +
                    "</ul>" +
                    "</aside>" +

                    "<aside id=\"devis\">" +

                    "<h2> Devis </h2>" +

                    "<ul>" +

                    "<li>N° de devis<span class=\"right\">5</span> </li>" +
                    "<li>Date de cr&eacute;ation : <span class=\"right\">" + this.devDateCreation.ToShortDateString() + "</span></li>" +
                    "<li> validité<span class=\"right\">25/07/2019</span> </li>" +
                    "</ul>" +
                    "</aside>" +

                    "<figure id=\"logo\">" +

                    "<img src='http://madera-construction.fr/images/site/logo.png'/>" +
                    "</figure>" +
                    "</section>" +

                    "<section id=\"calc\">" +

                    "<table>" +

                    "<thead>" +

                    "<tr>" +

                    "<th> N° </th>" +
                    "<th> Description</th>" +
                    "<th> Unité</th>" +
                    "<th> Prix</th>" +
                    "</tr>" +
                    "</thead>" +
                    "<tbody>");
                double total = 0;
                foreach (Module module in BDDExterne.GetModulesByDevis(this.devId.ToString()))
                {
                    writer.Write("<tr><td>" + module.num_module + "</td>");
                    writer.Write("<td>" + module.modLibele + "</td>");
                    writer.Write("<td>" + module.uniteUsage + "</td>");
                    writer.Write("<td>" + module.prixBase + " €</td></tr>");
                    total += module.prixBase;
                }
                writer.Write("<tr></tr></tbody>" +
                             "<tfoot>" +
                             "<tr>" +
                             "<td colspan=\"2\"></td>" +
                             "<td>Hors taxes</td>" +
                             "<td>" + total + " €</td>" +
                             "</tr>" +
                             "<tr>" +
                             "<td colspan=\"2\"></td>" +
                             "<td>Taxe valeur ajoutée</td>" +
                             "<td>20%</td>" +
                             "</tr>" +
                             "<tr>" +
                             "<td colspan=\"2\"></td>" +
                             "<td>Toutes taxes comprises</td>" +
                             "<td>" + total * 1.2 + " €</td>" +
                             "</tr>" +
                             "</tfoot>" +
                             "</table>" +
                             "</section>" +
                             "<aside id=\"sign-client\"><h2>Bon pour accord</h2>Signature du Client</aside>" +
                             "<aside id=\"sign-commer\"><h2>Bon pour accord</h2>Signature du Commercial</aside>" +
                             "</body></html>");

                //writer.AddAttribute(HtmlTextWriterAttribute.Src, @"C:\Users\maxna\source\repos\PFR-Madera\Madera\Resources\logo.png");
                //writer.AddAttribute(HtmlTextWriterAttribute.Alt, "Madera");
                //writer.RenderBeginTag(HtmlTextWriterTag.Img); // Begin #3
                //writer.RenderEndTag(); // End #3

                /*writer.Write(
                 *      "Client : " + this.devClient.cliNom + " " + this.devClient.cliPrenom + "<br>" +
                 *      "<br>" + this.devDateCreation.ToString() +
                 *      "<br><br> Modules associés au projet : <br>"
                 * );
                 * foreach (Module module in BDDExterne.GetModulesByDevis(this.devId.ToString()))
                 * {
                 *      writer.Write(module.modLibele + " " + module.uniteUsage + "<br>");
                 *      foreach (Parametre param in module.modParametres)
                 *      {
                 *              writer.Write(param.parNom + " " + param.parValeur + "<br>");
                 *      }
                 *      writer.Write("<br><br>");
                 * }*/
            }

            System.IO.File.WriteAllText(@"C:\Users\Public\WriteText.html", stringWriter.ToString());

            var    Renderer    = new IronPdf.HtmlToPdf();
            var    PDF         = Renderer.RenderHTMLFileAsPdf(@"C:\Users\Public\WriteText.html");
            string Outpath     = @"C:\Users\Public\";
            string OutpathView = "C:/Users/Public";

            PDF.SaveAs(Outpath + "Devis_du_" + DateTime.Now.Year + DateTime.Now.Month + DateTime.Now.Day + "_" + DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second + ".pdf");

            System.Windows.Forms.MessageBox.Show("Votre PDF a été généré dans le dossier " + OutpathView);
        }