Exemplo n.º 1
0
        private void ExistingWebURL()
        {
            // Create a PDF from any existing web page
            var Renderer = new IronPdf.HtmlToPdf();
            var PDF      = Renderer.RenderUrlAsPdf("https://en.wikipedia.org/wiki/Portable_Document_Format");

            // Create a PDF from an existing HTML
            Renderer.PrintOptions.MarginTop    = 50; //millimeters
            Renderer.PrintOptions.MarginBottom = 50;
            Renderer.PrintOptions.CssMediaType = PdfPrintOptions.PdfCssMediaType.Print;
            Renderer.PrintOptions.Header       = new SimpleHeaderFooter()
            {
                CenterText      = "{pdf-title}",
                DrawDividerLine = true,
                FontSize        = 16
            };
            Renderer.PrintOptions.Footer = new SimpleHeaderFooter()
            {
                LeftText        = "{date} {time}",
                RightText       = "Page {page} of {total-pages}",
                DrawDividerLine = true,
                FontSize        = 14
            };


            Renderer.PrintOptions.CssMediaType = PdfPrintOptions.PdfCssMediaType.Print;

            Renderer.PrintOptions.EnableJavaScript = true;
            Renderer.PrintOptions.RenderDelay      = 500; //milliseconds

            PDF.SaveAs("wikipedia.pdf");
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            HtmlToPdf   HtmlToPdf = new IronPdf.HtmlToPdf();
            PdfResource PDF       = HtmlToPdf.RenderUrlAsPdf(new Uri("http://amazon.com"));

            PDF.SaveAs(@"File.Pdf");
        }
Exemplo n.º 3
0
        public ActionResult Index(string Link)
        {
            //string linki = Link;
            var Renderer = new IronPdf.HtmlToPdf();
            var PDF      = Renderer.RenderUrlAsPdf(Link);

            PDF.SaveAs(@"C:\Users\serif\Desktop\isimkoy.pdf");
            // This neat trick opens our PDF file so we can see the result
            System.Diagnostics.Process.Start(@"C:\Users\serif\Desktop\isimkoy.pdf");
            return(View("Pdf Kayıtedildi"));
        }
        protected void btnExportar_Click(object sender, EventArgs e)
        {
            Random rdn    = new Random();
            int    a      = rdn.Next(1, 100000);
            String nombre = "Solicitud" + a + ".pdf";

            Response.Write("<script> window.open('" + "http://localhost:63324/Vistas/FrmExportarSolicitud.aspx" + "','_blank'); </script>");
            var Renderer = new IronPdf.HtmlToPdf();

            Renderer.PrintOptions.CreatePdfFormsFromHtml = false;
            Renderer.PrintOptions.MarginTop    = 0; //millimeters
            Renderer.PrintOptions.MarginBottom = 0;
            Renderer.PrintOptions.MarginLeft   = 20;
            Renderer.PrintOptions.MarginRight  = 15;
            var PDF = Renderer.RenderUrlAsPdf("http://localhost:63324/Vistas/FrmExportarSolicitud.aspx");

            PDF.SaveAs(nombre);
            // This neat trick opens our PDF file so we can see the result
            System.Diagnostics.Process.Start(nombre);
        }
Exemplo n.º 5
0
        public ActionResult GeneratePDF()
        {
            //var PDF = Renderer.RenderHTMLFileAsPdf("https://localhost:44335/Home/About.cshtml");
            //var PDF = Renderer.RenderHTMLFileAsPdf("C:/Users/Raghu/Desktop/BMF/IAD/BMFv2/BMFv2/Views/Home/Index.cshtml");
            try
            {
                var Renderer = new IronPdf.HtmlToPdf();
                var PDF      = Renderer.RenderUrlAsPdf("https://localhost:44335/Home/invoice");

                //CHANGE THE FILE PATH TO GENERATE PDF
                //Setting the path location to store the pdf
                var OutputPath = "C:/Users/Raghu/Desktop/Invoice.pdf";
                PDF.SaveAs(OutputPath);
                ViewBag.Message = "PDF generated Successfully";
                return(RedirectToAction("PDFGenS"));
            }
            catch
            {
            }

            return(RedirectToAction("PDFGenF"));
        }
Exemplo n.º 6
0
        public IActionResult Privacy()
        {
            var renderer = new IronPdf.HtmlToPdf()
            {
                PrintOptions = new PdfPrintOptions()
                {
                    FitToPaperWidth  = true,
                    DPI              = 300,
                    PaperSize        = PdfPrintOptions.PdfPaperSize.A4,
                    PaperOrientation = PdfPrintOptions.PdfPaperOrientation.Portrait,
                    Zoom             = 100,
                    EnableJavaScript = true,
                    InputEncoding    = System.Text.Encoding.GetEncoding("UTF-8"),
                }
            };
            var path = System.IO.Path.GetTempFileName();

            renderer.RenderUrlAsPdf("https://www.yahoo.co.jp/").SaveAs(path);

            var stream = new System.IO.FileStream(path, FileMode.Open);

            return(new FileStreamResult(stream, "application/pdf"));
        }
Exemplo n.º 7
0
        public static PdfDocument RenderPdf(int id)
        {
            Members member = MemberServices.GetMember(id);

            if (member == null)
            {
                throw new FileNotFoundException();
            }

            var text       = File.ReadAllText("./Document/Template.html");
            var dateString = member.DateofBap == null ? "" : DateTime.Parse(member.DateofBap.ToString()).ToString("MMMM dd, yyyy");

            text = text.Replace("%%MEMBERNAME%%", member.FirstName + " " + member.LastName).Replace("%%DATEOFBAP%%", dateString);
            File.WriteAllText($"./Document/Member-{id}.html", text);

            //using (var document = DocX.Load("./Document/Template.docx"))
            //{
            //    document.ReplaceText("%%MEMBERNAME%%", member.FirstName, false);
            //    document.ReplaceText("%%DATEOFBAP%%", member.DateofBap.ToString(), false);
            //    //DocX.ConvertToPdf();
            //    document.SaveAs("./Document/Member.docx");
            //}

            // Create a PDF from any existing web page
            var Renderer = new IronPdf.HtmlToPdf();

            Renderer.PrintOptions.PaperOrientation = PdfPrintOptions.PdfPaperOrientation.Landscape;
            //var PDF = Renderer.RenderUrlAsPdf("https://en.wikipedia.org/wiki/Portable_Document_Format");
            var PDF = Renderer.RenderUrlAsPdf($"./Document/Member-{id}.html");

            File.Delete($"./Document/Member-{id}.html");
            // PDF.RotatePage(0, 90);
            //PDF.SaveAs("./output/output_"+id+".pdf");
            // This neat trick opens our PDF file so we can see the result
            //System.Diagnostics.Process.Start("wikipedia.pdf");
            return(PDF);
        }