|
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using iTextSharp.text;
using iTextTabularReport.Utilities;
using iTextTabularReport.Models;
namespace iTextTabularReport.Controllers
{
[HandleError]
public class HomeController : Controller
{
[HttpGet]
public ActionResult Index()
{
return new RedirectResult("~/Default.htm");
}
[HttpGet]
public void GetPdf()
{
var configuration = new ReportConfiguration();
configuration.PageOrientation = PageSize.LETTER_LANDSCAPE.Rotate();
configuration.LogoPath
= Server.MapPath(Url.Content("~/Content/Images/Logo.jpg"));
configuration.LogImageScalePercent = 50;
configuration.ReportTitle
= "Export Tabular Data in Pdf Format through the Web";
configuration.ReportSubTitle = "Created by iText Report Tool";
var report = new PdfTabularReport();
report.ReportConfiguration = configuration;
List<ReportColumn> columns = new List<ReportColumn>();
columns.Add(new ReportColumn { ColumnName = "Id", Width = 100 });
columns.Add(new ReportColumn { ColumnName = "Name", Width = 100 });
columns.Add(new ReportColumn { ColumnName = "Enrollment", Width = 100 });
columns.Add(new ReportColumn { ColumnName = "Score", Width = 100 });
var stream = report.GetPdf(StudentRepository.GetStudentsTable(1000), columns);
Response.Clear();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition",
"attachment;filename=ExampleReport.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.BinaryWrite(stream.ToArray());
Response.End();
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I have been working in the IT industry for some time. It is still exciting and I am still learning. I am a happy and honest person, and I want to be your friend.