I want to create dynamic PDF document pages as per my record. Please help me.
I want to print 3 records per page.
string[] collection = {
"vivek", "kashyap", "viral", "darshit", "arpit", "sameer", "vanraj"
};
PdfDocument pdfDoc = new PdfDocument();
int records = collection.Length;
int perpage = 3;
int pages = (int)Math.Ceiling((double)records / (double)perpage);
for (int p = 0; p < pages; p++)
{
PdfPage pdfPage = new PdfPage();
pdfPage.Size = PageSize.Letter;
pdfDoc.Pages.Add(pdfPage);
XFont NormalFont = new XFont("Helvetica", 10, XFontStyle.Regular);
using (var pdfGfx = XGraphics.FromPdfPage(pdfPage))
{
for (int i = 0,next = 100; i < collection.Length; i++)
{
pdfGfx.DrawString( "Name : " + collection[i].ToString()
, NormalFont, XBrushes.Black, 55, next
, XStringFormats.Default);
next += 20;
}
}
}
I assume the code as you have presented it is showing the same top entries? What you need to do is maintain the start of each 3 entries as you move from page to page. I have called this variable idx and updated your code below (note I haven’t actually compiled it except in my head).