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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Shape with text

Thread ID:

Created:

Updated:

Platform:

Replies:

90783 Oct 17,2009 09:34 AM UTC Aug 7,2018 04:58 AM UTC WinForms 3
loading
Tags: PDF
Andreas Hirtzel
Asked On October 17, 2009 09:34 AM UTC

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.

Sri Subhashini M [Syncfusion]
Replied On 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

Haikal Khair
Replied On August 6, 2018 08:23 AM UTC

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

KarthikeyanC [Syncfusion]
Replied On 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 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;