1

私はiTextSharpの初心者です。このコードを記述して、RoundRectangleをPdfPTableに作成し、ページの中央にテーブルを配置します。

 string pdfpath = Server.MapPath("PDFs");
        RoundRectangle rr = new RoundRectangle();

        using (Document document = new Document())
        {
            PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(pdfpath + "/Graphics6.pdf", FileMode.CreateNew));
            document.Open();
            PdfPTable table = new PdfPTable(1);
                           float[] f=new float[]{0.5f};

            table.SetWidths(f);
            PdfPCell cell = new PdfPCell()
            {
                CellEvent = rr,
                Border = PdfPCell.NO_BORDER,

                Phrase = new Phrase("test")
            };
            table.AddCell(cell);
            document.Add(table);

テーブル幅を変更したいコードを変更した

 string pdfpath = Server.MapPath("PDFs");
        RoundRectangle rr = new RoundRectangle();

        using (Document document = new Document())
        {
            PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(pdfpath + "/Graphics6.pdf", FileMode.CreateNew));
            document.Open();
            PdfPTable table = new PdfPTable(1);
            table.TotalWidth = 5;

            int[] w = new int[] { 12};
           table.SetWidths(w);
            PdfPCell cell = new PdfPCell()
            {
                CellEvent = rr,
                Border = PdfPCell.NO_BORDER,

                Phrase = new Phrase("test")
            };
            table.AddCell(cell);
            document.Add(table);

しかし、ページに作業も変更幅の表もありません。私を助けてください。皆さんありがとう

4

1 に答える 1

7

次のように、TotalWidth幅を設定するためのプロパティを使用できます。PdfPTable

string pdfpath = Server.MapPath("PDFs");
RoundRectangle rr = new RoundRectangle();

using (Document document = new Document())
{
    PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(pdfpath + "/Graphics200.pdf", FileMode.CreateNew));
    document.Open();
    PdfPTable table = new PdfPTable(1);
    table.TotalWidth = 144f;

    table.LockedWidth = true;
    PdfPCell cell = new PdfPCell()
    {
        CellEvent = rr,
        Border = PdfPCell.NO_BORDER,
        Phrase = new Phrase("test")
    };
    table.AddCell(cell);
    document.Add(table);
}
于 2012-08-19T12:04:47.187 に答える