당신은 마이크로 소프트 보고서 뷰어 http://www.microsoft.com/en-us/download/details.aspx?id=3841 프로젝트에 DLL을 추가 사용해야합니다 Microsoft.ReportViewer.Common 및 Microsoft.ReportViewer.WinForms 당신이 가진 * .rdlc 파일을 작성해야합니다 있도록 디자인을 변경할 수 있습니다 귀하의 보고서. 마지막으로 저장하려면 다음 중 하나를 수행하십시오.
public static void PrintArticles(ICollectionView Articles)
{
try
{
var articlesRows = new DataTable("Articles");
articlesRows.Columns.Add("Id");
articlesRows.Columns.Add("Description");
var arts = Articles.Cast<Article>();
foreach (var art in arts)
{
articlesRows.Rows.Add(art.Id, art.Description);
}
ReportViewer reporter = new ReportViewer();
reporter.LocalReport.DisplayName = "Report1";
reporter.LocalReport.ReportPath = Path.Combine(Program.BasePath + "PrintArticles.rdlc");
reporter.LocalReport.DataSources.Clear();
reporter.LocalReport.DataSources.Add(new ReportDataSource("Project1", articlesRows));
byte[] report = reporter.LocalReport.Render("PDF");
reporter.LocalReport.ReleaseSandboxAppDomain();
string pdfpath = Path.Combine(Program.BasePath, "file.pdf");
if (File.Exists(pdfpath))
File.Delete(Path.Combine(Program.BasePath, "file.pdf"));
FileStream writer = new FileStream(pdfpath, FileMode.Create);
writer.Write(report, 0, report.Length);
writer.Close();
Process ar = Process.Start(pdfpath);
}
catch (Exception e)
{
}
}