I'm using .rdlc report in my **web application**, exporting report to pdf & print it works great but now i wanted to print report automatically(i,e on click of print button.)
Is it possible to print rdlc report automatically?
please send me code how to print report on click of print button.
Please help me,
.................
protected void Print_Click(object sender, EventArgs e)
{
string recordIdCount = "201";
Print(recordIdCount);
Warning[] warnings;
string[] streamids;
string mimeType;
string encoding;
string extension;
byte[] bytes = RptVisitorMaster.LocalReport.Render("PDF", null, out mimeType,
out encoding, out extension, out streamids, out warnings);
FileStream fs = new FileStream(HttpContext.Current.Server.MapPath("SchoolData/image/output.pdf"), FileMode.Create);
fs.Write(bytes, 0, bytes.Length);
fs.Close();
//Open exsisting pdf
Document document = new Document(PageSize.LETTER);
PdfReader reader = new PdfReader(HttpContext.Current.Server.MapPath("SchoolData/image/output.pdf"));
//Getting a instance of new pdf wrtiter
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(HttpContext.Current.
Server.MapPath("SchoolData/image/Print.pdf"), FileMode.Create));
document.Open();
PdfContentByte cb = writer.DirectContent;
int i = 0;
int p = 0;
int n = reader.NumberOfPages;
Rectangle psize = reader.GetPageSize(1);
float width = psize.Width;
float height = psize.Height;
//Add Page to new document
while (i < n)
{
document.NewPage();
p++;
i++;
PdfImportedPage page1 = writer.GetImportedPage(reader, i);
cb.AddTemplate(page1, 0, 0);
}
//Attach javascript to the document
PdfAction jAction = PdfAction.JavaScript("this.print(true);\r", writer);
writer.AddJavaScript(jAction);
document.Close();
//Attach pdf to the iframe
frmPrint.Attributes["src"] = "SchoolData/image/Print.pdf";
}