Esempio n. 1
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        //Get HTML from temporary file which we've created in the overridden method Render()
        string html = File.ReadAllText(Path.Combine(Server.MapPath("Temp"), "temp.htm"), Encoding.UTF8);

        string url = System.Web.HttpContext.Current.Request.Url.AbsoluteUri;

        if (html.Length > 0)
        {
            SautinSoft.PdfMetamorphosis p = new SautinSoft.PdfMetamorphosis();
            //After purchasing the license, please insert your serial number here to activate the component
            //p.Serial = "XXXXXXXXXXX";

            p.HtmlSettings.BaseUrl = url;

            byte[] pdf = p.HtmlToPdfConvertStringToByte(html);

            //show PDF
            if (pdf != null)
            {
                Response.Buffer = true;
                Response.Clear();
                Response.ContentType = "application/PDF";
                Response.AddHeader("content-disposition", "attachment; filename=Result.pdf");
                Response.BinaryWrite(pdf);
                Response.Flush();
                Response.End();
            }
        }
    }
Esempio n. 2
0
        static void Main(string[] args)
        {
            SautinSoft.PdfMetamorphosis p = new SautinSoft.PdfMetamorphosis();

            // After purchasing the license, please insert your serial number here to activate the component
            // p.Serial = "XXXXXXXXXXX";

            if (p != null)
            {
                string htmlPath   = @"..\..\example.htm";
                string pdfPath    = Path.ChangeExtension(htmlPath, ".pdf");
                string htmlString = "";

                // The easiest way is using the method 'HtmlToPdfConvertFile':
                // int ret = p.HtmlToPdfConvertFile(htmlPath,pdfPath);
                // or :
                // 1. Get HTML content.
                htmlString = ReadFromFile(htmlPath);

                // 2. Converting HTML to PDF
                // Specify BaseUrl to help converter find a full path for relative images, CSS.
                p.HtmlSettings.BaseUrl = Path.GetDirectoryName(Path.GetFullPath(htmlPath));
                byte[] pdfBytes = p.HtmlToPdfConvertStringToByte(htmlString);

                if (pdfBytes != null)
                {
                    // 3. Save the PDF document to a file for a viewing purpose.
                    File.WriteAllBytes(pdfPath, pdfBytes);
                    System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(pdfPath)
                    {
                        UseShellExecute = true
                    });
                }
                else
                {
                    System.Console.WriteLine("An error occurred during converting HTML to PDF!");
                }
            }
        }
Esempio n. 3
0
        private void buttonConvert_Click(object sender, EventArgs e)
        {
            SautinSoft.PdfMetamorphosis p = new SautinSoft.PdfMetamorphosis();

            //After purchasing the license, please insert your serial number here to activate the component
            //p.Serial = "XXXXXXXXXXX";

            if (p != null)
            {
                string htmlPath   = @"..\..\example.htm";
                string pdfPath    = @"..\..\test.pdf";
                string htmlString = "";

                // The easiest way is using the method 'HtmlToPdfConvertFile':
                // int ret = p.HtmlToPdfConvertFile(htmlPath,pdfPath);
                // or :
                //1. Get HTML content
                htmlString = ReadFromFile(htmlPath);

                //2. Converting HTML to PDF
                //specify BaseUrl to help converter find a full path for relative images, CSS
                p.HtmlSettings.BaseUrl = Path.GetDirectoryName(Path.GetFullPath(htmlPath));
                byte[] pdfBytes = p.HtmlToPdfConvertStringToByte(htmlString);

                if (pdfBytes != null)
                {
                    //3. Save pdfBytes to PDF file
                    File.WriteAllBytes(pdfPath, pdfBytes);
                    System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(pdfPath)
                    {
                        UseShellExecute = true
                    });
                }
                else
                {
                    MessageBox.Show("An error occurred during converting HTML to PDF!");
                }
            }
        }
    protected void Button1_Click(object sender, EventArgs e)
    {
        SautinSoft.PdfMetamorphosis p = new SautinSoft.PdfMetamorphosis();

        // After purchasing the license, please insert your serial number here to activate the component
        //p.Serial = "XXXXXXXXXXX";

        // Let's set page numbers
        p.PageSettings.Numbering.Text = "Page {page} of {numpages}";

        // Set page header within HTML string
        p.PageSettings.Header.FromString("<table border=\"1\"><tr><td>We added this header using the property \"Header.Html\"</td></tr></table>", SautinSoft.PdfMetamorphosis.HeadersFooters.InputFormat.Html);

        // Add page footer from HTML file
        p.PageSettings.Footer.FromFile(Path.Combine(Server.MapPath(""), @"footer.htm"), SautinSoft.PdfMetamorphosis.HeadersFooters.InputFormat.Html);

        // Get content of the ASPX page as HTML document
        string htmlString = GetHtmlFromAspx(Path.Combine(Server.MapPath(""), @"Default.aspx"));

        p.HtmlSettings.BaseUrl = Server.MapPath("");

        byte[] pdfBytes = p.HtmlToPdfConvertStringToByte(htmlString);

        //show PDF
        if (pdfBytes != null)
        {
            Response.Buffer = true;
            Response.Clear();
            Response.ContentType = "application/PDF";
            Response.BinaryWrite(pdfBytes);
            Response.Flush();
            Response.End();
        }
        else
        {
            Result.Text = "Converting failed!";
        }
    }