private void printDocument2_QueryPageSettings(object sender, System.Drawing.Printing.QueryPageSettingsEventArgs e) { opd opd = new opd(); opd.dailyOPDCount(dateTimePicker1.Value.Date.ToString("yyyy-MM-dd")); int patients = Convert.ToInt32(opd.count); e.PageSettings.PaperSize = new System.Drawing.Printing.PaperSize("A4 (210 x 297 mm)", 827, (55 + (patients * 5) + 13) * 4); e.PageSettings.Margins = new System.Drawing.Printing.Margins(0, 0, 0, 0); }