Cell width Pdfptable iTextShar MVC 4

Asked

Viewed 1,806 times

2

I’m using the iTextSharp to create PDF’s in my application. However I have to recreate a table, where I have to set the size for a column rather reduced. Follow the image that shows the size with which I want to configure the column:

inserir a descrição da imagem aqui

When the rest of the table creation is all right, I can’t even set this width.

Code:

PdfPTable table = new PdfPTable(2);
table.WidthPercentage = 82.0f;
PdfPCell cell = new PdfPCell(new Phrase("Com a assinatura autógrafa, o signatário desta Auto-declaração garante ter cumprido estas condições:", fontetexto));
cell.PaddingBottom = 10f;
cell.PaddingTop = 10f;
cell.Colspan = 2;
cell.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
table.AddCell(cell);
table.AddCell("1. ");
table.AddCell("Os óleos e gorduras vegetais velhos fornecidos são biomassa conforme o Decreto de biomassa.");

1 answer

3


Problem solved. I saw several solutions on the net where they said to define the table as follows:

PdfPTable table = new PdfPTable(10);
table.HorizontalAlignment = 0;
table.TotalWidth = 500f;
table.LockedWidth = true;
float[] widths = new float[] { 100f, 4000f };
table.SetWidths(widths);

The result was always: 'Corrupt file'. The solution then passed in defining the table size (the array float) right when creating the same:

PdfPTable table = new PdfPTable(new float[] { 30f, 400f });

Browser other questions tagged

You are not signed in. Login or sign up in order to post.