简体   繁体   中英

Print rdlc report using Response in Asp.net

    byte[] bytes = null;
string strDeviceInfo = "";
string strMimeType = "";
string strEncoding = "";
string strExtension = "";
string[] strStreams = null;
Warning[] warnings = null;

try
{
    ReportDataSource rds = new ReportDataSource("f_MANPOWERREQUISITION");
    ReportViewer rptViewer1 = new ReportViewer();
    rptViewer1.ProcessingMode = ProcessingMode.Local;
    rptViewer1.LocalReport.ReportPath = Server.MapPath("Report.rdlc");
    bytes = rptViewer1.LocalReport.Render(strFormat, strDeviceInfo, out strMimeType, out  strEncoding, out strExtension, out strStreams, out warnings);
    Response.Buffer = true;
    Response.Clear();
    Response.ContentType = strMimeType;
    Response.AddHeader("content-disposition", "attachment; filename=" + strNomFichier + "." + strFormat);
    Response.BinaryWrite(bytes); // create the file
    Response.Flush();
}// send it to the client to download
catch (Exception ex)
{
}

This code use to download the pdf file.. but i want to print the file so output file opens to browser's print preview. So anybody help to print a pdf file in browser....Thanks....

Thanks for posting this code. I just copied and pasted it into my application to successfully download a pdf to the browser. Your issue is very simple to fix. Change attachment; to inline; on the Response.AddHeader line.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM