Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            HtmlToPdf   HtmlToPdf = new IronPdf.HtmlToPdf();
            PdfResource PDF       = HtmlToPdf.RenderUrlAsPdf(new Uri("http://amazon.com"));

            PDF.SaveAs(@"File.Pdf");
        }
Ejemplo n.º 2
0
        public ConvertToIronPdf(string str, int i)
        {
            string    filename   = @"C:/Users/arnom/Desktop/TestHTML/test";
            Program   p          = new Program();
            string    findBase64 = @"[^a-zA-Z0-9\+\/=]";
            Regex     rgx64      = new Regex(findBase64);
            HtmlToPdf converter  = new HtmlToPdf();

            var html = toHTML(str);
            //File.WriteAllText(filename + ".html", html.ToString());
            //HtmlToPdf.RenderHtmlAsPdf(html).SaveAs(filename + (i + 1) + ".pdf");
            HtmlToPdf   HtmlToPdf = new IronPdf.HtmlToPdf();
            PdfResource PDF       = HtmlToPdf.RenderHtmlAsPdf(html);

            PDF.SaveAs(filename + i + ".pdf");
            //HtmlToPdf.ConvertUrl(filename + (i + 1) + ".html", pdfname + (i + 1) + ".pdf");
        }
Ejemplo n.º 3
0
        public FileInfo CreatePdf(IResultsViewModel model)
        {
            if (model == null || (string.IsNullOrEmpty(model.FullName) && string.IsNullOrEmpty(model.Photo) && model.Height <= 0))
            {
                return(null);
            }

            string file = Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, $@"App_Data\{model.FullName ?? "unkown"}.pdf");
            string page = ModelToHTML(model);

            if (!string.IsNullOrEmpty(page))
            {
                var htmlToPdf = new HtmlToPdf(new PdfPrintOptions()
                {
                    PaperSize = PdfPrintOptions.PdfPaperSize.A4
                });
                PdfResource pdf = htmlToPdf.RenderHtmlAsPdf(page);
                if (File.Exists(file))
                {
                    for (int i = 1; ; ++i)
                    {
                        var s = file.Insert(file.Length - 4, $" ({i.ToString()})");
                        if (File.Exists(s))
                        {
                            continue;
                        }
                        else
                        {
                            file = s;
                            break;
                        }
                    }
                }
                pdf.SaveAs(file);
            }
            var fileinfo = new FileInfo(file);

            return(fileinfo.Exists ? fileinfo : null);
        }