4

iTextSharpを使用して、グリッドビューからPDFへのエクスポートを行いました。グリッドビューの列が多いため、PDF の列は整列されておらず、非常に小さいです。コードビハインドと.aspxページの両方でスタイルを書いてみました。でも大きさは変わらない。

.aspx ページ

 <asp:GridView ID="grdResult" runat="server" AutoGenerateColumns="true" Width="100%"
      CellPadding="3" CellSpacing="3" Font-Size="10pt">
      <HeaderStyle Font-Bold="true" Width="250px" />
 </asp:GridView>

.cs ページ

Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=MARGEmployees.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
HtmlForm frm = new HtmlForm();
grdResult.Parent.Controls.Add(frm);
frm.Attributes["runat"] = "server";
frm.Controls.Add(grdResult);
frm.RenderControl(hw);
grdResult.HeaderRow.Style.Add("width", "15%");
grdResult.HeaderRow.Style.Add("font-size", "10px");
grdResult.Style.Add("font-family", "Tahoma");
grdResult.Style.Add("font-size", "8px");
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A4, 7f, 7f, 7f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();

これについて私を助けてください

4

2 に答える 2

1

コードビハインドでPDFドキュメントのサイズを変更してみてください。

//これらのいずれかを試してください

Document pdfDoc = new Document(PageSize.A3, 7f, 7f, 7f, 0f);
Document pdfDoc = new Document(PageSize.A2, 7f, 7f, 7f, 0f);
Document pdfDoc = new Document(PageSize.A1, 7f, 7f, 7f, 0f);

PDFドキュメントのサイズが設定されているため、列が圧縮されます。サイズを変更すると機能します。

于 2012-12-13T05:27:08.103 に答える
0

GridView は、GridView を XHTML テーブルにレンダリングしながらグリッドを PDF にエクスポートし、その過程でテーブルを PDF ドキュメントに変換することができます。

于 2013-11-13T09:27:12.527 に答える