Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.
Wed Feb 18, 2015 6:08 pm
Hi,
I'm drawing a rectangle to contain later some dynamic text from DB.
Is there a way to make the text fit the rectangle to its width?
Is the a way to make the rectangle grow according to the length of text?
i.e.: if the rectangle is defined with 100 for its height and the text overflow it.
Can I scale the rectangle to 300 during runtime?
Thanks
B
-
betz
-
- Posts: 1
- Joined: Wed Feb 18, 2015 5:59 pm
Thu Feb 19, 2015 5:52 am
Hello betz,
Thanks for your inquiry.
For your requirement, please refer to the code below:
- Code: Select all
PdfDocument pdf = new PdfDocument();
PdfPageBase page = pdf.Pages.Add();
PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 10f);
PdfSolidBrush brush = new PdfSolidBrush(Color.Black);
string text = "Hello this is E-iceblue Support Team.";
SizeF size = font.MeasureString(text);
PdfStringFormat format = new PdfStringFormat();
RectangleF rect = new RectangleF(0, 70, size.Width, size.Height);
page.Canvas.DrawRectangle(new PdfPen(Color.LightBlue), rect);
page.Canvas.DrawString(text, font, brush, rect, format);
pdf.SaveToFile("Sample.pdf", FileFormat.PDF);
Best Regards,
Burning
E-iceblue Support Team
-
burning.liu
-
- Posts: 406
- Joined: Mon Aug 04, 2014 6:47 am