Esempio n. 1
0
        //public ActionResult ExcelDownload()
        //{
        //    string conn = ConfigurationManager.ConnectionStrings["testDBConn"].ToString();
        //    SqlConnection con = new SqlConnection(conn);
        //    SqlCommand cmd = new SqlCommand("allusers", con);
        //    SqlDataAdapter scmd = new SqlDataAdapter(cmd);
        //    DataSet ds = new DataSet();

        //    scmd.Fill(ds);
        //    string AppLocation = "";
        //    AppLocation = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase);
        //    AppLocation = AppLocation.Replace("file:\\", "");
        //    string file = AppLocation + "\\Files\\SampleReport.xlsx";

        //    List<UserData> lstStudents = new List<UserData>(){
        //    new UserData(){UserId = "10",FisrtName = "Naveen1"},
        //    new UserData(){UserId = "20",FisrtName = "Naveen2"},
        //    new UserData(){UserId = "30", FisrtName= "Naveen3"},
        //    new UserData(){UserId = "40", FisrtName= "Naveen4"}
        //};
        //    var lstuds = lstStudents.Select(s => new { Name = s.FisrtName, s.UserId }).ToList();
        //    //DataTable dt1 = new DataTable();
        //    DataTable dt = ToDataTable(lstuds);
        //    using (XLWorkbook wb = new XLWorkbook())
        //    {
        //        //wb.Worksheets.Add(ds.Tables[0]);
        //        wb.Worksheets.Add(dt);
        //        wb.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
        //        wb.Style.Font.Bold = true;
        //        wb.SaveAs(file);
        //    }
        //    int status = objAdmin.SendExcelReport("*****@*****.**");
        //    if (status == 1)
        //    {
        //        Response.Write("<script>alert('Mail sent succesfully')</script>");
        //    }
        //    return RedirectToAction("GetAllUsers", "Login");
        //}
        //static DataTable ToDataTable<T>(List<T> items)
        //{
        //    DataTable dataTable = new DataTable(typeof(T).Name);
        //    //Get all the properties by using reflection
        //    PropertyInfo[] Props = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance);
        //    foreach (PropertyInfo prop in Props)
        //    {
        //        //Setting column names as Property names
        //        dataTable.Columns.Add(prop.Name);
        //    }
        //    foreach (T item in items)
        //    {
        //        var values = new object[Props.Length];
        //        for (int i = 0; i < Props.Length; i++)
        //        {

        //            values[i] = Props[i].GetValue(item, null);
        //        }
        //        dataTable.Rows.Add(values);
        //    }

        //    return dataTable;
        //}
        public ActionResult PrintAllReport()
        {
            //var report = new ActionAsPdf("Index");
            //return report;

            var FileName = new Rotativa.UrlAsPdf("http://www.Google.com")
            {
                FileName = "urltest.pdf",
            };

            return(FileName);
        }
        public Byte[] getinvoicePDFdatainbytes(long?invoiceid)
        {
            string authority = System.Web.HttpContext.Current.Request.Url.Authority;
            var    url       = "http://" + authority + "/InvoiceView/Invoice?invoiceId=" + invoiceid;
            //var url = "http://localhost:56113/InvoiceView/Invoice?invoiceId="+invoiceid;
            string customSwitches = string.Format("--footer-html  \"{0}\" " + "--header-html \"{1}\" ", "http://" + authority + "/InvoiceView/Invoicepdffooter", "http://" + authority + "/InvoiceView/Invoicepdfheader");
            var    actionResult   = new Rotativa.UrlAsPdf(url)
            {
                FileName        = "invoice_pdf",
                PageOrientation = Rotativa.Options.Orientation.Portrait,
                PageSize        = Rotativa.Options.Size.A4,
                PageMargins     = new Margins(25, 5, 25, 5),
                CustomSwitches  = customSwitches
            };

            byte[] invoicePDFData = actionResult.BuildPdf(this.ControllerContext);
            return(invoicePDFData);
        }
Esempio n. 3
0
 public void Can_build_the_pdf_binary()
 {
     var localPath = Directory.GetParent(AppDomain.CurrentDomain.BaseDirectory);
     var solutionDir = localPath.Parent.Parent.FullName;
     var wkhtmltopdfPath = Path.Combine(solutionDir, "Rotativa", "Rotativa");
     var actionResult = new UrlAsPdf("https://github.com/webgio/Rotativa")
         {
             WkhtmltopdfPath = wkhtmltopdfPath
         }; 
     var builder = new TestControllerBuilder();
     var controller = new HomeController();
     builder.InitializeController(controller);
     var pdfBinary = actionResult.BuildPdf(controller.ControllerContext);
     var pdfTester = new PdfTester();
     pdfTester.LoadPdf(pdfBinary);
     pdfTester.PdfIsValid.Should().Be.True();
     pdfTester.PdfContains("Rotativa").Should().Be.True();
 }
        //
        // GET: /generate-pdf?url={url}&filename={filename?}
        public ActionResult GeneratePdf()
        {
            var url = Request.QueryString["url"];
            if (string.IsNullOrEmpty(url))
                throw new HttpException((int)HttpStatusCode.BadRequest, "Must specify a URL query parameter");

            // Verify that it is a valid URI
            var dummy = new Uri(url);

            var filename = Request.QueryString["filename"];

            var view = new UrlAsPdf(url);
            if (!string.IsNullOrEmpty(filename))
            {
                view.FileName = filename;
            }
            return view;
        }