Sto cercando di capire come ottenere il mio testo all'interno di un PdfPCell da mostrare nel mezzo. Ho provato diverse opzioni, come:iTextsharp, PdfPCell.VerticalAlignment e PdfPCell.Horizontalalignment
myCell.VerticalAlignment = Element.ALIGN_MIDDLE; myCell.VerticalAlignment = PdfPCell.ALIGN_MIDDLE; myCell.VerticalAlignment = Rectangle.ALIGN_MIDDLE;
Niente di tutto questo funziona per me. VerticalAlignment prende un int, così ho cercato di fare un ciclo, per vedere se riuscivo a trovare il numero giusto, ma tutto solo avere lasciato align fondo ..
Document myDocument = new Document(PageSize.A4);
PdfWriter myPdfWriter = PdfWriter.GetInstance(myDocument, new FileStream(strPDFFilePath, FileMode.Create));
myDocument.Open();
myDocument.NewPage();
PdfContentByte myPdfContentByte = myPdfWriter.DirectContent;
PdfPCell myCell;
Paragraph myParagraph;
PdfPTable myTable = new PdfPTable(4);
myTable.WidthPercentage = 100;
myTable.SetWidths(new int[4] { 25, 25, 25, 25 });
myTable.DefaultCell.BorderWidth = 1;
myTable.DefaultCell.BorderColor = BaseColor.RED;
for (int i = -100; i < 100; i++)
{
myParagraph = new Paragraph(String.Format("Alignment: {0}", i));
myParagraph.Font.SetFamily("Verdana");
myParagraph.Font.SetColor(72, 72, 72);
myParagraph.Font.Size = 11;
myCell = new PdfPCell();
myCell.AddElement(myParagraph);
myCell.HorizontalAlignment = i;
myCell.VerticalAlignment = i;
myTable.AddCell(myCell);
}
myDocument.Add(myTable);
myDocument.Add(new Chunk(String.Empty));
myDocument.Close();
Grazie, ha funzionato meglio quando ho iniziato a usare l'espressione anziché al paragrafo – Jimmy