Looh example in this url:
https://elicat-my.sharepoint.com/:i:/g/personal/gianfranco_facchini_elicat_net/Ec8pwKRIY_RJoz06qd9pTJwB2KXGCtgoRqbKs64X1Vy38w?e=vcbOrM
This is my code :
- Code: Select all
rect = find.Bounds;
float hRect = rect.Height;
float yRect = rect.Y;
rect.Height = (rect.Height - 0.5).ToFloat(); // per evitare che sovvrascriva delle righe bordi di tabella in cui è il testo
page.Canvas.DrawRectangle(PdfBrushes.White, rect); // pulisco il testo precedente
rect.Height = hRect; // memorizza altezza rettancolo testo originale
SizeF size = font.MeasureString(newText); // recupera la dimensione del nuovo testo in base al nuovo font da impostare
float widthstring = size.Width > rect.Width ? (size.Width) : rect.Width; // imposta nuova larghezza
float heightstring = size.Height> rect.Height ? (size.Height+1) : rect.Height; // imposta nuova altezza
// se la nuova altezza del etsto è maggiore della precedete allora reimposto posizione verticale
float diffHeigth = (size.Height - rect.Height);
if (diffHeigth > 0) rect.Y = (rect.Y - (diffHeigth/2));
RectangleF textRect = new RectangleF(rect.X, rect.Y, widthstring, heightstring);
page.Canvas.DrawString(newText, font, brush, textRect);