Как сохранить HTML-таблицы правильно выровненными при рендеринге в PDF?
Я хочу, чтобы html-таблицы были правильно выровнены при рендеринге в PDF с помощью Itextsharp. Содержимое таблицы идет вертикально, а не горизонтально для 2 таблиц слева и справа и так далее при рендеринге в формате PDF.
Ниже приведен мой html-код:
<div style="width: 760px"> <table width="760px"><tbody><tr><td align="center"> <asp:Panel ID="pnlGridExport" runat="server" Width="820px" Visible="false"> <table border="1" style="font-family: Arial; font-size: 10pt; width: 400px; float: left" align="left"><tbody><tr><td colspan="2" style="height: 18px; color: black"> Outward </td></tr><tr><td>No: of OCEs</td><td><asp:Label ID="lblOCECount" runat="server"></td></tr><tr><td>Amount</td><td><asp:Label ID="lblOCEAmount" runat="server"></td></tr><tr><td style="color: blue">CR</td></tr></tbody></table> <table border="1" style="font-family: Arial; font-size: 10pt; width: 400px; float: right" align="right"><tbody><tr><td colspan="2" style="height: 18px; color: black"> Inward</td></tr><tr><td>No: of ICEs</td><td><asp:Label ID="lblICECount" runat="server"></td></tr><tr><td>Amount</td><td><asp:Label ID="lblICEAmount" runat="server"></td></tr><tr><td style="color: red">DR</td></tr></tbody></table> <table border="1" style="font-family: Arial; font-size: 10pt; width: 400px; float: left" align="left"><tbody><tr><td colspan="2" style="height: 18px; color: black"> Outward Return</td></tr><tr><td>No: of IREs</td><td><asp:Label ID="lblIRECount" runat="server"></td></tr><tr><td>Amount</td><td><asp:Label ID="lblIREAmount" runat="server"></td></tr><tr><td style="color: red">DR</td></tr></tbody></table> <table border="1" style="font-family: Arial; font-size: 10pt; width: 400px; float: right" align="right"><tbody><tr><td colspan="2" style="height: 18px; color: black"> Inward</td></tr><tr><td>No: of RCEs</td><td><asp:Label ID="lblRCECount" runat="server"></td></tr><tr><td>Amount</td><td><asp:Label ID="lblRCEAmount" runat="server"></td></tr><tr><td style="color: blue">CR</td></tr></tbody></table> <table border="1" style="font-family: Arial; font-size: 10pt; width: 400px; float: left" align="left"><tbody><tr><td colspan="2" style="height: 18px; color: black"> Net of Outward</td></tr><tr><td>No: of Recods</td><td><asp:Label ID="lblNetOutwardRecords" runat="server"></td></tr><tr><td>Amount</td><td><asp:Label ID="lblNetOutwardAmount" runat="server"></td></tr><tr><td style="color: blue">CR</td></tr></tbody></table> <table border="1" style="font-family: Arial; font-size: 10pt; width: 400px; float: right" align="right"><tbody><tr><td colspan="2" style="height: 18px; color: black"> Net of Inward</td></tr><tr><td>No: of Records</td><td><asp:Label ID="lblNetInwardRecords" runat="server"></td></tr><tr><td>Amount</td><td><asp:Label ID="lblNetInwardAmount" runat="server"></td></tr><tr><td style="color: red">DR</td></tr></tbody></table> <table border="1" style="font-family: Arial; font-size: 10pt; width: 400px" align="center"><tbody><tr><td colspan="2" style="height: 18px; color: black"> Net Amount</td><td colspan="2" style="height: 18px; color: black"> <asp:Label ID="lblNetAmount" runat="server"></td></tr></tbody></table> </td></tr></tbody></table> </div>
Что я уже пробовал:
Я рендеринг PDF-файла через itextsharp dll. Код для рендеринга того же самого в PDF выглядит следующим образом:
#region View PDF Report /// <summary> /// populate the report using the search criteria. /// private void ViewPDFReport() { try { BLL_MISReports objMisReport = new BLL_MISReports(); DateTime FromDate = DateTime.ParseExact(txtFromDate.Value.Trim(), "dd/MM/yyyy", CultureInfo.InvariantCulture); DateTime ToDate = DateTime.ParseExact(txtToDate.Value.Trim(), "dd/MM/yyyy", CultureInfo.InvariantCulture); DataSet ds = objMisReport.BusinessDaySettlementReport(FromDate, ToDate, Convert.ToInt32(Session["USER"].ToString())); DataTable dt = new DataTable(); if (ds.Tables[0].Rows.Count > 0) { dt = ds.Tables[0]; pnlGridExport.Visible = true; //Bind Datatable to Labels lblOCECount.Text = dt.Rows[0]["OCERecordCount"].ToString(); lblOCEAmount.Text = dt.Rows[0]["OCEAmount"].ToString(); lblICECount.Text = dt.Rows[0]["ICERecordCount"].ToString(); lblICEAmount.Text = dt.Rows[0]["ICEAmount"].ToString(); lblIRECount.Text = dt.Rows[0]["RCERecordCount"].ToString(); lblIREAmount.Text = dt.Rows[0]["IREAmount"].ToString(); lblRCECount.Text = dt.Rows[0]["RCERecordCount"].ToString(); lblRCEAmount.Text = dt.Rows[0]["RCEAmount"].ToString(); lblNetOutwardRecords.Text = dt.Rows[0]["NetOutWardRecordCount"].ToString(); lblNetOutwardAmount.Text = dt.Rows[0]["NetOutWardAmount"].ToString(); lblNetInwardRecords.Text = dt.Rows[0]["NetInWardRecordCount"].ToString(); lblNetInwardAmount.Text = dt.Rows[0]["NetInWardAmount"].ToString(); lblNetAmount.Text = dt.Rows[0]["NetAmount"].ToString(); Response.ContentType = "application/pdf"; Response.AddHeader("content-disposition", "attachment;filename=BusinessDaySummary_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".pdf"); //Response.Cache.SetCacheability(HttpCacheability.NoCache); StringWriter sw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(sw); pnlGridExport.RenderControl(hw); // grdExport.HeaderStyle.Width = "1"; // grdExport.HeaderRow.Style.Add("font-size", "10px"); //pnlGridExport.Style.Add("text-decoration", "none"); //pnlGridExport.Style.Add("font-family", "Arial, Helvetica, sans-serif;"); //pnlGridExport.Style.Add("font-size", "8px"); //string strHead = strReportHeading + " FOR USER " + drdUserId.SelectedItem.Text.ToString(); string strHead = strReportHeading; StringBuilder strbn = new StringBuilder(); string Imagepath = Common.SITE_URL + "loginLogo.jpg"; strbn.Append("<div style="float: right"></div> <span style="float: right; text-align: right; font-weight: bold">Date:" + DateTime.Today.ToString("dd-MMM-yyyy") + "</span><div style="text-align: center; font-weight: bold; background-color: White; width: 100%; font-size: 20px; text-decoration: underline"> " + strHead + "</div> <br>"); strbn.Append(sw.ToString()); StringReader sr = new StringReader(strbn.ToString()); //Document pdfDoc = new Document(PageSize.A2, 7f, 7f, 7f, 0f); Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0f); HTMLWorker htmlparser = new HTMLWorker(pdfDoc); PdfWriter.GetInstance(pdfDoc, Response.OutputStream); pdfDoc.Open(); htmlparser.Parse(sr); pdfDoc.Close(); Response.Flush(); Response.Write(pdfDoc); Response.Flush(); Response.Close(); } else { pnlGridExport.Visible = false; Common.showMessage("No Records Found", this); return; } } catch (Exception ex) { Common.handleErrorLog(ex); } } #endregion
Suvendu Shekhar Giri
Правильно ли он отображается в вашем браузере?