Pdf margins

i want to give margin to pdf and it works very well for all the pages

i given example code below

                              PdfLoadedDocument ldoc = new PdfLoadedDocument(PDFfileNames[ijk]);

                            //Create a new instance of PdfDocument class
                            Syncfusion.Pdf.PdfDocument document = new Syncfusion.Pdf.PdfDocument();
                            //Set increasing value of the page margin as margin of the PDF document
                            document.PageSettings.Margins.Left = 10;
                            document.PageSettings.Margins.Right = 10;
                            document.PageSettings.Margins.Top = 10;
                            document.PageSettings.Margins.Bottom = 10;

                            for (int i = 0; i < ldoc.Pages.Count; i++)
                            {
                                //Get loaded page as template
                                Syncfusion.Pdf.Graphics.PdfTemplate template = ldoc.Pages[i].CreateTemplate();
                                //Create new page
                                Syncfusion.Pdf.PdfPage pages = document.Pages.Add();
                                //Create Pdf graphics for the page
                                PdfGraphics g = pages.Graphics;
                                //Draw template with the size as loaded page size
                              
                                    g.DrawPdfTemplate(template, new PointF(0, 0), new SizeF(pages.GetClientSize().Width, pages.GetClientSize().Height));
                                    IsChangeSize = true;
                                
                            }

                                document.Save(PDFfileNames[ijk]);

                            document.Close(true);
                            ldoc.Dispose();

but what i need is,

I want to give margin to each page but not same margin 

1st page margin left =10f  means
2nd page margin left=25f 

Is it Possible in syncfusion,
if possible means give me the sample code

Thanks you
regards
Raman P

1 Reply 1 reply marked as answer

SL Sowmiya Loganathan Syncfusion Team February 15, 2021 12:48 PM UTC

Hi Raman,  
  
Thank you for contacting Syncfusion support.   
  
We can able to set “Different margin on different pages of the PDF document” using PdfSection (i.e., first page contains margin as 10, second page contains margin as 30, etc). Please refer the below code snippet for more details,   
  
  
//Load PDF document   
 PdfLoadedDocument ldoc = new PdfLoadedDocument("../../Data/Essential_Pdf.pdf");  
  
 //Create a new instance of PdfDocument class  
 Syncfusion.Pdf.PdfDocument document = new Syncfusion.Pdf.PdfDocument();  
  
 int margin = 10;  
  
 for (int i = 0; i < ldoc.Pages.Count; i++)  
 {  
     //Get loaded page as template  
     Syncfusion.Pdf.Graphics.PdfTemplate template = ldoc.Pages[i].CreateTemplate();  
  
     //Create section for PDF documet  
     PdfSection section = document.Sections.Add();  
  
     //Create new page  
     Syncfusion.Pdf.PdfPage pages = section.Pages.Add();  
  
     //Set increasing value of the page margin as margin of the PDF document  
     section.PageSettings.Margins.Left = margin;  
     section.PageSettings.Margins.Right = margin;  
     section.PageSettings.Margins.Top = margin;  
     section.PageSettings.Margins.Bottom = margin;  
  
     //Create Pdf graphics for the page  
     PdfGraphics g = pages.Graphics;  
  
     //Draw template with the size as loaded page size  
     g.DrawPdfTemplate(template, new PointF(0, 0), new SizeF(pages.GetClientSize().Width, pages.GetClientSize().Height));  
  
     margin += 20;  
  
 }  
  
We have created the sample to illustrates the same and please find the download link from below,   
  
Please try the above sample in your end and let us know the result.   
  
Regards,  
Sowmiya Loganathan  
  
 


Marked as answer
Loader.
Up arrow icon