1. Install NuGet
-install Package Doddlereport
-install Package Doddlereport.itextsharp
2. Instance Code
static void Main (string[] args) {var query = GetAll (); var report = new report (query. Toreportsource ()); Report. Textfields.title = "Graduate Student report"; Report. Textfields.subtitle = "Sample Header"; Report. Textfields.footer = "Sample Footer"; Report. Textfields.header = string. Format (@ "report Generated: {0} total Students: {1}", DateTime.Now, 100); Report. Renderhints.booleancheckboxes = true; Report. datafields["Id"]. Hidden = true; var stream = new MemoryStream (); var writer = new Pdfreportwriter (); Writer. Writereport (report, stream); Const string Path = "C:\\test"; if (! Directory.Exists (Path)) {directory.createdirectory (path); } file.writeallbytes (String. Format (path+ "/studentreport_{0}.pdf", DateTime.Now.ToString ("Dd-mm-yyyy_hh-mm-ss")), stream. GetBuffer ()); Console.wriTeline ("Done"); public class Student {public int Id {get; set;} public string Name {get; set;} public bool Ispass {get; set;} public int score {get; set;} Public DateTime graduateat {get; set;} } public static list<student> GetAll () {var rand = new Random (); Return Enumerable.range (1, 1000). Select (i = new Student {Id = i, Name = "Product" + I, Score = rand. Next (+), graduateat = DateTime.Now}). ToList (); }
3. View the results in the C:\test folder
The above is C # use Dogglereport to generate PDF report content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!