page margin

How I can set the page margin?

Thank you.

1 Reply

SS Sri Subhashini M Syncfusion Team August 14, 2009 11:05 AM UTC

Hi Pegaso,

Thank you for your interest in Essential PDF.

Setting Margin to PDF document

We can set margin to PDF document not to the PDF pages with the help of the Margins class. Kindly refer the below code snippet which demonstrates setting margin values,


//Create a new document.
PdfDocument doc = new PdfDocument();
// Set margin
doc.PageSettings.Margins.Bottom = 2f;
doc.PageSettings.Margins.Right = 3f;
//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);
float fontSize = 20f;
//Set the font
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, fontSize);
//Draw the text
g.DrawString("Hello world!", font, brush,new PointF(20,20));
doc.Save("Sample.pdf");


Please try the above code snippet and let me know if you need any information.

Regards,
Suba

Loader.
Up arrow icon