0

不确定如何在“离开申请”标题下加下划线。我正在使用 itextsharp 将 webgrid 导出为 pdf。我想插入一个需要下划线的标题,如果可能的话,还有一张图片,该图片将用于公司徽标。我的代码如下:

public FileStreamResult ExporttoPdf()
{
    List<EmployeeLeaveApplicationView> viewModelList = new List<EmployeeLeaveApplicationView>();
    var model = _employeeleaveapplication.GetAllEmployeeLeaveApplications().ToList();

    foreach (var items in model)
    {
        EmployeeLeaveApplicationView objEmployeeLeaveViewModel = new EmployeeLeaveApplicationView();
        //objEmployeeLeaveViewModel.emp_first_name = items.Employee_DetailView.emp_first_name;
        //objEmployeeLeaveViewModel.emp_tel_no = items.Employee_Details.emp_tel_no;
        objEmployeeLeaveViewModel.persal_no = items.persal_no;
        objEmployeeLeaveViewModel.leave_type_id = items.leave_type_id;
        objEmployeeLeaveViewModel.no_of_days = items.no_of_days;
        objEmployeeLeaveViewModel.start_date = items.start_date;
        objEmployeeLeaveViewModel.end_date = items.end_date;
        objEmployeeLeaveViewModel.days_left = items.days_left;
        viewModelList.Add(objEmployeeLeaveViewModel);
    }

    WebGrid grid = new WebGrid(viewModelList, canPage: false, canSort: false);
    string gridHTML = grid.GetHtml(

        columns: grid.Columns
            (
                grid.Column("persal_no", "Persal number"),
                grid.Column("leave_type_id", "Leave type"),
                //grid.Column("emp_first_name", "Name"),
                grid.Column("no_of_days", "No of days"),
                grid.Column("start_date", "Start date"),
                grid.Column("end_date", "End date"),
                grid.Column("days_left", "Days left")
                //grid.Column("emp_tel_no", "Contact number")
            )).ToString();

    string exportData = String.Format("<html><head>{0}</head><body>{1}</body></html>",
        "<style> <h2><span>Leave Applications</span></h2> 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>",
        gridHTML);

    var bytes = Encoding.UTF8.GetBytes(exportData);

    using (var input = new MemoryStream(bytes))
    {
        var output = new MemoryStream();

        var document = new Document(PageSize.A4, 50, 50, 50, 50);

        var writer = PdfWriter.GetInstance(document, output);

        writer.CloseStream = false;

        document.Open();

        var xmlWorker = XMLWorkerHelper.GetInstance();

        xmlWorker.ParseXHtml(writer, document, input, Encoding.UTF8);

        document.Close();

        output.Position = 0;

        return new FileStreamResult(output, "application/pdf");
    }
}
4

0 回答 0