We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Shape with text

Hi,

I'd like to draw a rectangle grey shape with bold text in it, but can't find any sample. Can someone help me, please?

Thanks.

3 Replies

SS Sri Subhashini M Syncfusion Team October 21, 2009 10:06 AM UTC

Hi Andreas,

Thank you for your interest in Essential PDF.

Drawing Text inside rectangle

We can draw text inside the rectangle with the help of DrawRectangle and DrawString methods. Kindly refer the below sample which demonstrates drawing text inside the rectangle.

http://files.syncfusion.com/samples/PDF.Windows/PDF_Win_F90783.zip

Please let me know if you need any further assistance.

Regards,
Suba


HK Haikal Khair August 6, 2018 08:23 AM UTC

Could you please update that example to a newer VS version. I can't open it.


KC Karthikeyan Chandrasekar Syncfusion Team August 7, 2018 04:58 AM UTC

Hi Haikal, 
I have attached the sample, code snippet and the output PDF for your reference. 



Code snippet 
//Create a new document 
PdfDocument doc = new PdfDocument(); 
//Add a page 
PdfPage page = doc.Pages.Add(); 
 
//Create Pdf graphics for the page 
PdfGraphics g = page.Graphics; 
 
//Create a solid brush 
PdfBrush brush = new PdfSolidBrush(Color.Black); 
 
//Set the font with bold 
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 10f, PdfFontStyle.Bold); 
 
//Draw the rectangle with Gray color 
g.DrawRectangle(new PdfPen(PdfBrushes.Gray, 1), PdfBrushes.White, new RectangleF(100, 200, 100, 50)); 
 
//Draw the text 
g.DrawString("Hello world!", font, brush, new PointF(120, 220)); 
 
//Save and close the document 
doc.Save("Sample.pdf"); 
doc.Close(true); 

Output: 
 
Regards, 
Karthikeyan 


Loader.
Live Chat Icon For mobile
Up arrow icon