-1

我无法使用iTextSharpc# 通过 asp.net 2010 设置 pdf 表格高度。如果我将任何单元格的固定高度设置为 15,则单元格的数据不会显示。在这种情况下,单元格显示没有数据。我想将单元格的高度更改为小于15px并在单元格中显示数据。

private void CreatePDF()
{
    string timestamp = DateTime.Now.ToString("MMddyyyy.HHmmss");
    string pdfFileName = Request.PhysicalApplicationPath + "\\Files\\" + "PDFCreation_Reporting_" + timestamp + ".pdf";
    Document myDocument = new Document(PageSize.A4, 5, 20, 50, 25);
    PdfWriter.GetInstance(myDocument, new FileStream(pdfFileName, FileMode.Create));
    myDocument.Open();
    PdfPTable UpperTable1 = new PdfPTable(3);
    PdfPTable UpperTable2 = new PdfPTable(3);
    PdfPCell utcell1 = new PdfPCell();
    PdfPCell utcell2 = new PdfPCell();
    PdfPCell utcell3 = new PdfPCell();
    PdfPCell utcell4 = new PdfPCell();
    PdfPCell utcell5 = new PdfPCell();
    PdfPCell utcell6 = new PdfPCell();
    utcell1.FixedHeight = 15f;
    utcell2.FixedHeight = 15f;
    utcell3.FixedHeight = 15f;
    utcell1.Padding = 0;
    utcell2.Padding = 0;
    utcell3.Padding = 0;

    utcell4.FixedHeight = 15f;
    utcell5.FixedHeight = 15f;
    utcell6.FixedHeight = 15f;
    utcell4.Padding = 0;
    utcell5.Padding = 0;
    utcell6.Padding = 0;

    float[] colWidthsut1 = { 800, 685, 800 };//35%,30%,35% [2285]
    UpperTable1.SetWidths(colWidthsut1);
    UpperTable1.WidthPercentage = 100;

    float[] colWidthsut2 = { 457, 1028, 800 };//20%,45%,35% [2285]
    UpperTable2.SetWidths(colWidthsut2);
    UpperTable2.WidthPercentage = 100;

    string strTest1 = "Test data";
    string strTest2 = "Test data";
    string strTest3 = "Test Data";
    string strTest4 = "Test data";
    string strTest5 = "";
    string strTest6 = "";

    Phrase phrTest1 = new Phrase();
    Phrase phrTest2 = new Phrase();
    Phrase phrTest3 = new Phrase();
    Phrase phrTest4 = new Phrase();
    Phrase phrTest5 = new Phrase();
    Phrase phrTest6 = new Phrase();

    phrTest1.Font = new Font(Font.FontFamily.TIMES_ROMAN, 6, Font.NORMAL, BaseColor.BLACK);
    phrTest2.Font = new Font(Font.FontFamily.TIMES_ROMAN, 6, Font.NORMAL, BaseColor.BLACK);
    phrTest3.Font = new Font(Font.FontFamily.TIMES_ROMAN, 6, Font.NORMAL, BaseColor.BLACK);
    phrTest4.Font = new Font(Font.FontFamily.TIMES_ROMAN, 6, Font.NORMAL, BaseColor.BLACK);

    phrTest1.Add(strTest1);
    phrTest2.Add(strTest2);
    phrTest3.Add(strTest3);
    phrTest4.Add(strTest4);
    phrTest5.Add(strTest5);
    phrTest6.Add(strTest6);
    utcell1.AddElement(phrTest1);
    utcell2.AddElement(phrTest2);
    utcell3.AddElement(phrTest3);
    utcell4.AddElement(phrTest4);
    utcell5.AddElement(phrTest5);
    utcell6.AddElement(phrTest6);

    PdfPCell[] firstrowCells = { utcell1, utcell2, utcell3 };
    PdfPRow row1 = new PdfPRow(firstrowCells);
    UpperTable1.Rows.Add(row1);
    PdfPCell[] secondrowCells = { utcell4, utcell5, utcell6 };
    PdfPRow row2 = new PdfPRow(secondrowCells);
    UpperTable2.Rows.Add(row2);

    myDocument.Add(UpperTable1);
    myDocument.Add(UpperTable2);
    myDocument.Close();
}
4

2 回答 2

0

也许您可以修改对我有用的边距。另外,什么时候修改单元格?也许您在将其添加到表格后才这样做?那么它可能不会工作......

于 2013-01-10T10:17:57.940 回答
0

FileStream 文件 = new FileStream(newFullPath, FileMode.Create, System.IO.FileAccess.Write); // 创建文件流长度的字节数组
//byte[] ImageData = new byte[file.Length]; //从流中读取字节块到字节数组
中 //file.Read(ImageData, 0, System.Convert.ToInt32(file.Length)); //关闭文件流

    //  string appPath = HttpContext.Current.Request.ApplicationPath;
    CheckBox1.Visible = false;
    Response.ContentType = "application/pdf";
    string appPath = HttpContext.Current.Request.ApplicationPath;
   // FileStream file = new FileStream(Server.MapPath("~/save/") + (Convert.ToInt32(ViewState["cust"])) + "_" + (n++) + ".PDF", FileMode.Create, System.IO.FileAccess.Write);
    StringWriter sw = new StringWriter();
    HtmlTextWriter hw = new HtmlTextWriter(sw);
    pnlPerson.RenderControl(hw);

    StringReader sr = new StringReader(sw.ToString());
    Document pdfDoc = new Document(PageSize.A4, 5, 20, 50, 25);
    HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
    //   MemoryStream ms = new MemoryStream();
    PdfWriter.GetInstance(pdfDoc, file);
    PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
    pdfDoc.Open();
    htmlparser.Parse(sr);
    hw.Close();
    sw.Close();
    pdfDoc.Close();
    sr.Close();
    file.Close();
    htmlparser.Close();
于 2016-02-02T10:05:24.920 回答