Example #1
0
        public ActionResult ConvertToPDF(string viewName, object model, bool inline=false)
        {
            var v = new SautinSoft.PdfVision();
            v.PageStyle.PageSize.A4();

            string html = RenderViewToString(viewName, model);

            var pdfBytes = v.ConvertHtmlStringToPDFStream(html);
            //if(inline)
            //{
                Response.AppendHeader("Content-Disposition", "inline");
            //}
            return File(pdfBytes, "application/pdf", "Portfolio.pdf");
        }
Example #2
0
        static void Main(string[] args)
        {
            // Convert HTML string to PDF bytes.
            SautinSoft.PdfVision v = new SautinSoft.PdfVision();

            //v.Serial = "XXXXXXXXXXXXXXX";

            // Set "Edge mode" to support all modern CSS.
            SautinSoft.PdfVision.TrySetBrowserModeEdgeInRegistry();

            // Specify some converting options.
            v.PageStyle.PageSize.Auto();
            //v.PageStyle.PageMarginLeft.Inch(1);
            //v.ImageStyle.Heightmm(150);
            //v.ImageStyle.WidthInch(10);

            // Specify top and bottom page margins
            v.PageStyle.PageMarginTop.Mm(5f);
            v.PageStyle.PageMarginBottom.Mm(5f);

            string inpHtml = "<html><body><p style=\"text-align: center; font-size: 45px;\">Hello my Friend!</p></body></html>";

            // Convert HTML string to PDF bytes.
            byte[] pdfBytes = v.ConvertHtmlStringToPDFStream(inpHtml);

            // Save PDF data to a file and open it for demonstration purposes.
            if (pdfBytes != null)
            {
                FileInfo outFile = new FileInfo(@"Result.pdf");

                using (FileStream fs = new FileStream(outFile.FullName, FileMode.Create, FileAccess.Write))
                {
                    fs.Write(pdfBytes, 0, pdfBytes.Length);
                }
                // Open the resulting PDF document in a default PDF Viewer.
                System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile.FullName)
                {
                    UseShellExecute = true
                });
            }
        }
Example #3
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        SautinSoft.PdfVision v = new SautinSoft.PdfVision();

        // Set "Edge mode" to support all modern CSS.
        SautinSoft.PdfVision.TrySetBrowserModeEdgeInRegistry();

        // Specify top and bottom page margins
        v.PageStyle.PageMarginTop.Mm(5f);
        v.PageStyle.PageMarginBottom.Mm(5f);

        v.PageStyle.PageSize.A4();

        // Be sure that your HTML string has full paths to images and *.css
        // Correct: <img src="http://www.mysite.com/image1.jpg">
        // Incorrect: <img src="../images/image1.jpg">

        string html = ReadFileString(Path.Combine(Server.MapPath(""), "test.htm"));

        byte[] pdfBytes = null;

        // convert html string to pdf stream
        pdfBytes = v.ConvertHtmlStringToPDFStream(html);

        // show PDF
        if (pdfBytes != null)
        {
            Response.Buffer = true;
            Response.Clear();
            Response.ContentType = "application/PDF";
            //Response.AddHeader("content-disposition", "attachment; filename=Result.pdf");
            Response.AddHeader("content-disposition", "inline; filename=Result.pdf");
            Response.BinaryWrite(pdfBytes);
            Response.Flush();
            Response.End();
        }
    }