Pdfpcell width itextsharp c#

PDFPCell Width in iTextSharp using C#

In iTextSharp, the PDFPCell class is used to represent a cell in a PDF document’s table. The width of a cell in iTextSharp can be set using the PDFPCell.Width property. This property specifies the width of the cell in points (1 point = 1/72 inches).

Here’s an example that demonstrates how to set the width of a PDFPCell using iTextSharp in C#:


using iTextSharp.text;
using iTextSharp.text.pdf;

// Create a new document
Document doc = new Document();

// Create a PDF writer
PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream("output.pdf", FileMode.Create));

// Open the document
doc.Open();

// Create a table with 1 column and 1 row
PdfPTable table = new PdfPTable(1);

// Create a cell
PdfPCell cell = new PdfPCell(new Phrase("This is a cell"));

// Set the width of the cell to 100 points
cell.Width = 100f;

// Add the cell to the table
table.AddCell(cell);

// Add the table to the document
doc.Add(table);

// Close the document
doc.Close();
  

In this example, we create a new Document and a PdfWriter to write the PDF. Then we open the document and create a PdfPTable with 1 column and 1 row. Next, we create a PdfPCell and set its width to 100 points using the cell.Width property. Finally, we add the cell to the table, the table to the document, and close the document.

This example will create a PDF file named “output.pdf” with a table containing a single cell that has a width of 100 points.

Leave a comment