我设计了一份水晶报告,当我将其发送到打印机时,会浪费大量纸张。所以我认为如果可以转换crystalreport并将其发送到打印机然后我可以保存我的论文。 如果无法做到这一点,请帮我用c#设计一个文本文档。
这是我打印crystalReport的代码
private void textBox1_TextChanged(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|Store.mdf;Integrated Security=True;User Instance=True;MultipleActiveResultSets=true;";
con.Open();
SqlDataAdapter da3 = new SqlDataAdapter("select * from finalbill where billno='" + textBox1.Text + "' order by slno", con);
DataSet ds3 = new DataSet();
da3.Fill(ds3, "finalbill");
BillPrintReport abc = new BillPrintReport();
crystalReportViewer1.ReportSource = abc;
System.Drawing.Printing.PrintDocument printDoc = new System.Drawing.Printing.PrintDocument();
int i;
int rawKind = 0;
for (i = 0; i < printDoc.PrinterSettings.PaperSizes.Count; i++)
{
if (printDoc.PrinterSettings.PaperSizes[i].PaperName == "4x6")
{
rawKind = (int)GetField(printDoc.PrinterSettings.PaperSizes[i], "kind");
}
}
abc.PrintOptions.PaperSize = (CrystalDecisions.Shared.PaperSize)rawKind;
abc.PrintToPrinter(1, true, 0, 0);
crystalReportViewer1.Refresh();
this.Close();
}
private object GetField(Object obj, String fieldName)
{
System.Reflection.FieldInfo fi = obj.GetType().GetField(fieldName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
return fi.GetValue(obj);
}