Exemplo n.º 1
0
        public static void GenerateSummary(Voting voting)
        {
            var    Renderer = new IronPdf.HtmlToPdf();
            string path     = $"~/documents/Podsumowanie głosowania {voting.Name}.pdf";

            Renderer.RenderHtmlAsPdf(GenerateHtmlSummary(voting)).SaveAs(path);
        }
Exemplo n.º 2
0
        public static void GenerateCodes(Voting voting)
        {
            var    Renderer = new IronPdf.HtmlToPdf();
            string path     = $"~/documents/Kody głosowania {voting.Name}.pdf";

            Renderer.RenderHtmlAsPdf(GenerateHtmlCodes(voting)).SaveAs(path);
        }
Exemplo n.º 3
0
        public IActionResult GetPdf(int bookId)
        {
            var renderer = new IronPdf.HtmlToPdf();
            var pdf      = renderer.RenderHtmlAsPdf(GetBookAsAString(bookId)).BinaryData;

            return(File(pdf, "application/pdf"));
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            var render = new IronPdf.HtmlToPdf();
            var doc    = render.RenderHtmlAsPdf("<h1>Hello IronPdf</h1>");

            doc.SaveAs($@"{AppDomain.CurrentDomain.BaseDirectory}\HtmlString.pdf");
        }
Exemplo n.º 5
0
        public static void ConvertHtmlStringToPdf(PdfModel model)
        {
            // Render any HTML fragment or document to HTML
            var Renderer = new IronPdf.HtmlToPdf();

            Renderer.PrintOptions.PaperSize        = IronPdf.PdfPrintOptions.PdfPaperSize.A4;
            Renderer.PrintOptions.PaperOrientation = IronPdf.PdfPrintOptions.PdfPaperOrientation.Portrait;
            Renderer.PrintOptions.MarginTop        = 10; //millimeters
            Renderer.PrintOptions.MarginBottom     = 10; //millimeters
            Renderer.PrintOptions.MarginLeft       = 10; //millimeters
            Renderer.PrintOptions.MarginRight      = 10; //millimeters
            Renderer.PrintOptions.CssMediaType     = IronPdf.PdfPrintOptions.PdfCssMediaType.Print;
            Renderer.PrintOptions.Header           = new IronPdf.SimpleHeaderFooter()
            {
                DrawDividerLine = true,
                FontSize        = 16
            };


            string source = model.HtmlString;
            var    pdf    = Renderer.RenderHtmlAsPdf(source);

            if (!Directory.Exists(model.Directory))
            {
                Directory.CreateDirectory(model.Directory);
            }

            pdf.SaveAs(model.RepositoryPath);

            // This neat trick opens our PDF file so we can see the result in our default PDF viewer
            // System.Diagnostics.Process.Start(model.RepositoryPath);
        }
Exemplo n.º 6
0
        // converts the lemma body to a memory stream modified as needed in order to send it as attachment
        private static MemoryStream GetLemmaPDFStream(string lemma)
        {
            IronPdf.HtmlToPdf Renderer = new IronPdf.HtmlToPdf();
            MemoryStream      ms       = Renderer.RenderHtmlAsPdf(lemma).Stream;

            return(ms);
        }
Exemplo n.º 7
0
        public IronPdf.PdfDocument HTMLToPDF(string HTML)
        {
            var Renderer = new IronPdf.HtmlToPdf();
            var PDF      = Renderer.RenderHtmlAsPdf(HTML);

            return(PDF);
        }
Exemplo n.º 8
0
        private async void btnPrint_Click(object sender, EventArgs e)
        {
            var newDate = new DateTime().ToLocalTime();

            IronPdf.HtmlToPdf Renderer = new IronPdf.HtmlToPdf();
            StreamReader      sr       = new StreamReader(@"Pages\Attestation.html");
            var htmlDoc = await sr.ReadToEndAsync();

            htmlDoc = htmlDoc.Replace("@FullArabicName", txtNomAr.Text + " " + txtPrenomAr.Text)
                      .Replace("@FullName", txtNom.Text + " " + txtPrenom.Text)
                      .Replace("@Date", newDate.ToShortDateString())
                      .Replace("@Naiss", dtNaissance.Value.ToShortDateString())
                      .Replace("@CNE", txtCNE.Text)
                      .Replace("@NumAttestation", txtNumInscription.Text + "/" + dtInscription.Value.ToShortDateString());
            sr.Close();
            StreamWriter sw = new StreamWriter(@"Pages\Attestation2.html", false);

            foreach (var item in htmlDoc)
            {
                sw.Write(item);
            }
            sw.Close();
            var            PDF = Renderer.RenderHTMLFileAsPdf(@"Pages\Attestation2.html");
            SaveFileDialog sfd = new SaveFileDialog();

            if (sfd.ShowDialog() == DialogResult.OK)
            {
                var filename = sfd.FileName;
                PDF.SaveAs(Path.GetFullPath(filename));
            }
        }
        static void Main(string[] args)
        {
            if (File.Exists(_path))
            {
                File.Delete(_path);
            }

            var sp     = SharePointProject.Load(@"D:\Projects\MarkDownGenerator\Sones.Portal\deploy\WebApps");
            var appWeb = sp.Structure.WebApplications
                         .First(a => a.Name == "Portal");

            var      contenu = DocumentationRenderer.RenderWebApp(appWeb, new MarkDownRendrer());
            Markdown mark    = new Markdown();
            // Run parser
            string text = mark.Transform(contenu);

            File.AppendAllText(_path, contenu);
            using (var reader = new System.IO.StreamReader(@"D:\readme.md"))
                using (var writer = new System.IO.StreamWriter(@"D:\result.html"))
                {
                    var settings = CommonMarkSettings.Default;

                    CommonMark.CommonMarkConverter.Convert(reader, writer, settings);
                }
            IronPdf.HtmlToPdf Renderer = new IronPdf.HtmlToPdf();
            if (File.Exists(@"D:\html-file.pdf"))
            {
                File.Delete(@"D:\html-file.pdf");
            }
            Renderer.RenderHTMLFileAsPdf(@"D:\result.html").SaveAs(@"D:\html-file.pdf");
        }
Exemplo n.º 10
0
        static void RenderUrlToPdf()
        {
            var render = new IronPdf.HtmlToPdf();
            var doc    = render.RenderUrlAsPdf("https://www.wikipedia.org/");

            doc.SaveAs($@"{AppDomain.CurrentDomain.BaseDirectory}\wiki.pdf");
        }
        public Byte[] HtmlStringToPDF(string html)
        {
            var Renderer = new IronPdf.HtmlToPdf();
            var PDF      = Renderer.RenderHtmlAsPdf(html);

            return(PDF.BinaryData);
        }
Exemplo n.º 12
0
        public void CreatePdfExample(string urlname, string pdfnamed)
        {
            var Renderer = new IronPdf.HtmlToPdf();
            var PDF      = Renderer.RenderUrlAsPdf("" + urlname + "");

            PDF.SaveAs(pdfnamed + ".pdf");
            System.Diagnostics.Process.Start(pdfnamed + ".pdf");
        }
Exemplo n.º 13
0
        public void CreatePDF()
        {
            var Renderer = new IronPdf.HtmlToPdf();

            var PDF = Renderer.RenderHtmlAsPdf(GetHTMLString());

            PDF.SaveAs(Path + FileName);
        }
Exemplo n.º 14
0
        public void DownloadPdf(int id)
        {
            var Renderer   = new IronPdf.HtmlToPdf();
            var PDF        = Renderer.RenderUrlAsPdf("https://localhost:44393/Surveys/Details/" + id.ToString());
            var OutputPath = GetSurveyById(id).Header + ".pdf";

            PDF.SaveAs("C:\\Users\\pelsi\\OneDrive\\Masaüstü\\" + OutputPath);
        }
Exemplo n.º 15
0
        private void CreatePDF()
        {
            var Renderer   = new IronPdf.HtmlToPdf();
            var PDF        = Renderer.RenderHtmlAsPdf("<h1>Hello IronPdf</h1>");
            var OutputPath = "HtmlToPDF.pdf";

            PDF.SaveAs(OutputPath);
        }
Exemplo n.º 16
0
        public byte[] Export(IEnumerable <SettlementDTO> settlements)
        {
            string s = BuildHtml(settlements as ICollection <SettlementDTO>);

            var Renderer = new IronPdf.HtmlToPdf();
            var PDF      = Renderer.RenderHtmlAsPdf(s);

            return(PDF.BinaryData);
        }
        public IActionResult DownloadPdf(int id)
        {
            var Renderer   = new IronPdf.HtmlToPdf();
            var PDF        = Renderer.RenderUrlAsPdf("https://localhost:44393/Surveys/Details/" + id.ToString());
            var OutputPath = surveyService.GetSurveyById(id).Header + ".pdf";

            PDF.SaveAs("C:\\Users\\pelsi\\OneDrive\\Masaüstü\\" + OutputPath);
            return(RedirectToAction(nameof(Details), new { id = id }));
        }
Exemplo n.º 18
0
        static void Main(string[] args)
        {
            var pathToview             = Path.Combine(Environment.CurrentDirectory, "FinalReport.cshtml");
            var htmlWithoutModelForNow = System.IO.File.ReadAllText(pathToview);

            var Renderer   = new IronPdf.HtmlToPdf();
            var outputPath = Path.Combine(Environment.CurrentDirectory, "output.pdf");
            var pdfDoc     = Renderer.RenderHtmlAsPdf(htmlWithoutModelForNow).SaveAs(outputPath);
        }
Exemplo n.º 19
0
        static void Main(string[] args)
        {
            string html = "<p>I can't abide these Jawas. Disgusting creatures. Go on, go on. I can't understand how we got by those troopers.</p>";

            var renderer = new IronPdf.HtmlToPdf();
            var pdf      = renderer.RenderHtmlAsPdf(html);

            pdf.SaveAs("htmlString.pdf");
            Console.WriteLine(pdf.BinaryData);
        }
Exemplo n.º 20
0
        public byte[] Generate(string htmlContent, string fileName)
        {
            CreateDir();
            string filePath = dir + fileName + ".pdf";
            var    Renderer = new IronPdf.HtmlToPdf();

            Renderer.RenderHtmlAsPdf(htmlContent).SaveAs(filePath);
            byte[] bytes = System.IO.File.ReadAllBytes(filePath);
            return(bytes);
        }
Exemplo n.º 21
0
        public void Generate(List <Question> Data)
        {
            AddInfo(Data);

            var Renderer = new IronPdf.HtmlToPdf();
            var PDF      = Renderer.RenderHtmlAsPdf(generate);

            PDF.SaveAs("PDF.pdf");
            Process.Start("PDF.pdf");
        }
Exemplo n.º 22
0
        private static void CreatePDFFromXML(string fullNameXml, string shortname)
        {
            try
            {
                string pXslFile   = @".\config\FoglioStileAssoSoftware.xsl";
                string pFoFile    = System.IO.Path.Combine(LOCAL_PDF_FOLDER, shortname.Replace("xml", "html"));
                string pPdfFile   = System.IO.Path.Combine(LOCAL_PDF_FOLDER, shortname.Replace("xml", "pdf"));
                string lBaseDir   = System.IO.Path.GetDirectoryName(pPdfFile);
                string xsltString = File.ReadAllText(pXslFile);

                //XslCompiledTransform lXslt = new XslCompiledTransform();
                //lXslt.Load(pXslFile);
                //lXslt.Transform(fullNameXml, pFoFile);
                //FileStream lFileInputStreamFo = new FileStream(pFoFile, FileMode.Open);
                //FileStream lFileOutputStreamPDF = new FileStream(pPdfFile, FileMode.Create);
                //FonetDriver lDriver = FonetDriver.Make();
                //lDriver.BaseDirectory = new DirectoryInfo(lBaseDir);
                //lDriver.CloseOnExit = true;
                //lDriver.Render(lFileInputStreamFo, lFileOutputStreamPDF);
                //lFileInputStreamFo.Close();
                //lFileOutputStreamPDF.Close();
                //if (System.IO.File.Exists(pFoFile))
                //    System.IO.File.Delete(pFoFile);

                XslCompiledTransform proc = new XslCompiledTransform();

                proc.Load(pXslFile);

                string result;

                using (StringWriter sw = new StringWriter())

                {
                    proc.Transform(fullNameXml, null, sw);

                    result = sw.ToString();

                    var Renderer   = new IronPdf.HtmlToPdf();
                    var PDF        = Renderer.RenderHtmlAsPdf(result);
                    var OutputPath = pPdfFile;

                    if (System.IO.File.Exists(OutputPath))
                    {
                        System.IO.File.Delete(OutputPath);
                    }

                    PDF.SaveAs(OutputPath);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Exemplo n.º 23
0
        public async Task <ActionResult> Print(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            Invoice invoice = db.Invoices
                              .Include(i => i.Customer)
                              .Include(i => i.InvoiceDetails.Select(p => p.Product))
                              .Where(i => i.Id == id).FirstOrDefault();

            if (invoice == null)
            {
                return(HttpNotFound());
            }

            /// Pdf Section
            ///

            Utilities.ViewRenderer viewRenderer = new Utilities.ViewRenderer(this.ControllerContext);

            string reportContent = viewRenderer.RenderView($@"~/Views/Invoice/Print.cshtml", invoice);


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

            htmlToPdf.PrintOptions = new IronPdf.PdfPrintOptions()
            {
                PaperSize        = IronPdf.PdfPrintOptions.PdfPaperSize.A4,
                PaperOrientation = IronPdf.PdfPrintOptions.PdfPaperOrientation.Portrait,
                MarginBottom     = 0,
                MarginLeft       = 0,
                MarginRight      = 0,
                MarginTop        = 0
            };



            var waterMark = "<h1 style='font-size: 46px !important;' >Umair Enterprise</h1> <small>Developed By Muhammad Shakeel, Contact: 0346-9476404</small>";
            // var document = htmlToPdf.RenderUrlAsPdf($@"http://localhost:49767/Invoice/Details/{id}");
            var document = htmlToPdf.RenderHtmlAsPdf(reportContent);



            document.WatermarkAllPages(waterMark, IronPdf.PdfDocument.WaterMarkLocation.MiddleCenter, 20, -45);

            //return a  pdf document from a view
            var contentLength = document.BinaryData.Length;

            Response.AppendHeader("Content-Length", contentLength.ToString());
            Response.AppendHeader("Content-Disposition", "inline; filename=Invoice_" + id + ".pdf");
            return(await Task.FromResult(File(document.BinaryData, "application/pdf;")));
        }
Exemplo n.º 24
0
        private void button2_Click(object sender, EventArgs e)
        {
            var path     = folderBrowserDialog1.ShowDialog();
            var fullpath = folderBrowserDialog1.SelectedPath + "\\ZinciriKırma.html";
            // Create a PDF from an existing HTML using C#
            var Renderer   = new IronPdf.HtmlToPdf();
            var PDF        = Renderer.RenderHTMLFileAsPdf(fullpath);
            var OutputPath = folderBrowserDialog1.SelectedPath + "\\ZinciriKırma.pdf";

            PDF.SaveAs(OutputPath);
        }
Exemplo n.º 25
0
        public void Pdf()
        {
            //string linki = Link;
            var Renderer = new IronPdf.HtmlToPdf();
            var Link     = "http://*****:*****@"C:\Test\isimkoy.pdf");
            // This neat trick opens our PDF file so we can see the result
            //System.Diagnostics.Process.Start(@"C:\Test\isimkoy.pdf");
        }
Exemplo n.º 26
0
        public byte[] GetPdfBytes(OfferteDTO offerteDto)
        {
            var html = this.FillDocumentTemplate(offerteDto);

            var renderer = new IronPdf.HtmlToPdf();

            var assembly = Assembly.GetExecutingAssembly().Location;

            var filePath = Path.GetDirectoryName(assembly);

            return(renderer.RenderHtmlAsPdf(html, Path.Combine(filePath, "Templates")).Stream.ToArray());
        }
Exemplo n.º 27
0
        public IActionResult GenerateTodaysVisitsToPDF()
        {
            User user = _userService.GetUserByLogin(this.HttpContext.User.Identity.Name);

            if (user == null)
            {
                return(new StatusCodeResult(500));
            }

            var Renderer = new IronPdf.HtmlToPdf();

            String HtmlContent = @"
                                <h1>Dzisiejsze wizyty {0}</h1>
                                <small>Godzina wygenerowania: {1} </small>
                                <div style=""margin:10px;"">
                                    <table width=""100%"" style=""border: 1px solid #000;"">
                                      <tr>
                                        <th>Pacjent</th>
                                        <th>Dzień</th>
                                        <th>Godzina</th>
                                      </tr>
                                      {2}
                                    </table>
                                </div>
            ";

            var doctorVisits = _visitService.GetVisitsDocDate(user, DateTime.Now);

            StringBuilder rowBuilder = new StringBuilder(500);
            String        row        = @"<tr>
                            <td>{0}</td>
                            <td>{1}</td>
                            <td>{2}</td>
                           </tr>";

            foreach (var v in doctorVisits)
            {
                rowBuilder.Append(String.Format(row,
                                                v.Visitor.FullName(),
                                                v.DateTime.ToString("dd-MM-yyyy"),
                                                v.DateTime.ToString("HH:mm"))

                                  );
            }
            var PDF = Renderer.RenderHtmlAsPdf(String.Format(HtmlContent,
                                                             user.FullName(),
                                                             DateTime.Now.ToString("dd-MM-yyyy HH:mm"),
                                                             rowBuilder.ToString()));
            //return a  pdf document from a view
            var contentLength = PDF.BinaryData.Length;

            return(new FileStreamResult(PDF.Stream, "application/pdf"));
        }
Exemplo n.º 28
0
        static void Main(string[] args)
        {
            var renderer = new IronPdf.HtmlToPdf();

            renderer.RenderHTMLFileAsPdfAsync(@"C:\Users\walbe\Desktop\ConsoleApp1\Demo.html").Result.SaveAs("demo.pdf");
            //renderer.RenderHtmlAsPdf("<h1>Html with CSS and Images</h1>").SaveAs("example.pdf");

            var pdf = renderer.RenderHtmlAsPdf("<img src='test.jpg'>", @"C:\Users\walbe\Desktop\ConsoleApp1\");

            pdf.SaveAs("html-with-assets.pdf");
            Console.WriteLine("Hello World!");
        }
Exemplo n.º 29
0
        public bool SendEmail(Mail mail, string html)
        {
            bool        variable    = false;
            MailMessage mailMessage = new MailMessage(mail.MailFrom, mail.MailTo);

            mailMessage.Subject = mail.Subject;
            mailMessage.Body    = mail.Body;
            string header = @"<!DOCTYPE html><html><head><meta charset='utf-8'><meta name='viewport' content='width=device-width, initial-scale=1'><title>Izvjestaj</title></head><body>";
            string footer = @"</body></html>";

            if (html != null)
            {
                string            date         = DateTime.Now.ToString("yyyy-MM-dd");
                DateTime          oDate        = Convert.ToDateTime(date).Date;
                var               completeHTML = header + html + footer;
                IronPdf.HtmlToPdf Renderer     = new IronPdf.HtmlToPdf();
                try
                {
                    var Pdf = Renderer.RenderHtmlAsPdf(completeHTML).SaveAs("C:/Users/HP/Desktop/Izvjestaji/izvjestaj.pdf");
                }
                catch (Exception e)
                {
                }
                string     file = "C:/Users/HP/Desktop/Izvjestaji/izvjestaj.pdf";
                Attachment data = new Attachment(file, System.Net.Mime.MediaTypeNames.Application.Octet);
                mailMessage.Attachments.Add(data);
            }
            else
            {
                string     file = "D:/Haris/NJEMACKI/MOBITEL/ciscenje telefona od slika/GALERIJA/20150101_010134.jpg";
                Attachment data = new Attachment(file, System.Net.Mime.MediaTypeNames.Application.Octet);
                mailMessage.Attachments.Add(data);
            }

            SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587);

            smtpClient.Credentials = new System.Net.NetworkCredential()
            {
                UserName = mail.MailFrom,
                Password = mail.Password
            };
            smtpClient.EnableSsl = true;
            try
            {
                smtpClient.Send(mailMessage);
                variable = true;
            }
            catch (Exception e)
            {
                variable = false;
            }
            return(variable);
        }
Exemplo n.º 30
0
        public ActionResult TicketView(TicketModel model)
        {
            IronPdf.Installation.TempFolderPath = $@"{_host.ContentRootPath}/irontemp/";
            IronPdf.Installation.LinuxAndDockerDependenciesAutoConfig = true;
            var html          = this.RenderViewAsync("_TicketPdf", model);
            var ironPdfRender = new IronPdf.HtmlToPdf();
            var pdfDoc        = ironPdfRender.RenderHtmlAsPdf(html.Result);
            var path          = Path.Combine(
                Directory.GetCurrentDirectory(), "wwwroot");

            //var images = pdfDoc.RasterizeToImageFiles($@"{path}\thumbnail_*.jpg", 100, 80);
            return(File(pdfDoc.Stream.ToArray(), "application/pdf"));
        }