Tech
Forums
Jobs
Books
Events
Videos
Live
More
Interviews
Certification
Training
Career
Members
News
Blogs
Contribute
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
1
Answer
How to fix column width by itext pdf in webgrid
Madhav Sharma
7y
166
1
Reply
How to fix column width by itext pdf in webgrid
https://ibb.co/gFHnnm
public
FileStreamResult GETPdf(FilterModel model)
{
var userContactId = (
int
?)Session[
"UserContactId"
];
var userCompanyId = (
int
?)Session[
"UserCompanyId"
];
var contact = Session[
"Contact"
]
as
Contact;
var contactName = contact.FirstName;
model.Page = model.Page == 0 ? 1 : model.Page;
model.PageSize = model.PageSize == 0 ? 1000 : model.PageSize;
model.SearchText =
string
.IsNullOrEmpty(model.SearchText) ? model.SearchText : model.SearchText.Trim();
model.Sort =
string
.IsNullOrEmpty(model.Sort) ?
"dateEntered"
: model.Sort;
model.Sortdir =
string
.IsNullOrEmpty(model.Sortdir) ?
"desc"
: model.Sortdir;
var temp1 = Session[
"DateEnter1"
];
var temp2 = Session[
"DateEnter2"
];
var sd = temp1.ToString();
var ed = temp2.ToString();
var todate =
new
DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day).ToString(
"yyyy-MM-dd"
);
model.sdate =
string
.IsNullOrEmpty(model.sdate) ? sd : todate;
model.edate =
string
.IsNullOrEmpty(model.edate) ? ed : todate;
var tickets = cwContact.getExportToPDFTickets(contact, userCompanyId,
true
, model);
var totalTicket = cwContact.totalTicket;
model.TicketReportDataModel = tickets;
WebGrid grid =
new
WebGrid(model.TicketReportDataModel, rowsPerPage: model.PageSize, canPage:
true
);
string
gridData = grid.GetHtml(
columns: grid.Columns(
grid.Column(columnName:
"ticketNo"
, header:
"Ticket#"
, canSort:
false
),
grid.Column(columnName:
"Summary"
, header:
"Title"
, canSort:
false
),
grid.Column(columnName:
"Contact_Name"
, header:
"Contact"
, canSort:
false
),
grid.Column(columnName:
"SR_Status"
, header:
"Status"
, canSort:
false
),
grid.Column(columnName:
"Site_Name"
, header:
"Site Name"
, canSort:
false
),
grid.Column(columnName:
"SR_Type_Description"
, header:
"Type"
, canSort:
false
),
grid.Column(columnName:
"Company"
, header:
"Company"
, canSort:
false
),
grid.Column(columnName:
"Board"
, header:
"Board"
, canSort:
false
),
grid.Column(columnName:
"Discussion"
, header:
"Discussion"
, canSort:
false
),
grid.Column(columnName:
"Date_Entered"
, header:
"Date Entered"
, canSort:
false
),
grid.Column(columnName:
"DateResponded"
, header:
"Date Respond"
, canSort:
false
),
grid.Column(columnName:
"Date_Resolved"
, header:
"Date Resolved"
, canSort:
false
),
grid.Column(columnName:
"Date_Closed"
, header:
"Date Closed"
, canSort:
false
)
)).ToString();
string
exportData = String.Format(
"<html><head>{0}</head><body>{1}</body></html>"
,
"<style>table{ border-spacing: 10px; border-collapse: collapse; border: solid; }"
+ "td{border-color: #191970; border-width: 1px 1px 0 0;
border-style: solid; margin: 0; padding: 4px;
background-color: #E0FFFF;}</style>", gridData);
var bytes = System.Text.Encoding.UTF8.GetBytes(exportData.ToString());
using
(var input =
new
MemoryStream(bytes))
{
var output =
new
MemoryStream();
var document =
new
iTextSharp.text.Document(PageSize.A4, 10, 10, 10, 10);
var writer = PdfWriter.GetInstance(document, output);
writer.CloseStream =
false
;
document.Open();
var xmlWorker = iTextSharp.tool.xml.XMLWorkerHelper.GetInstance();
xmlWorker.ParseXHtml(writer, document, input, System.Text.Encoding.UTF8);
document.Close();
output.Position = 0;
//return new FileStreamResult(output, "application/pdf");
return
File(output,
"application/pdf"
,
"TicketList.pdf"
);
}
}
Post
Reset
Cancel
Answers (
1
)
Next Recommended Forum
How to devide aspx page on 2 parts in asp.net
[HttpException (0x80004005): Failed to Execute URL.]