title: Printing an RDLC file in ASP.NET MVC 3 not working
body: <p>I'm trying to create a pdf file from what the user entered. It is entered in a database file fine; however it is not been printed on the pdf file. When I try to debug it shows that it does have data. I'm not sure if it is because of the stored procedure that pulls the data. Is there a possibility that someone can assist me with this question; the issue is this line DataSet ds = dbdata.GetReceipt(getIssue.requisitionNumber); but rather than using a stored procedure; i would like to know how else I can show the data entered on the pdf file.  Whenever I try to execute the pdf file this is what I get <a href="https://i.stack.imgur.com/49nvc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/49nvc.png" alt="enter image description here"></a></p>
  
  <pre><code>&lt;input type="button" id="ReceiptPrint" value="Print/Issue" name="Print/Issue" class="btn btn-default col-md-4" /&gt;
  
   $m(document).ready(function () {
              $m('#ReceiptPrint').click(function () {
                  window.open("ReceiptPrint");
              });
          });
  
   public DataSet GetReceipt(string req_num)
          {
              SqlConnection connection = new SqlConnection(connectionString);
              SqlCommand command = new SqlCommand();
              command.CommandText = "issue_sp_getreceipt";
              command.CommandType = CommandType.StoredProcedure;
              command.Parameters.Add("@reqnum", SqlDbType.VarChar).Value = req_num;
              command.Connection = connection;
              SqlDataAdapter adapter = new SqlDataAdapter(command);
              DataSet ds = new DataSet("Receipt");
  
              try
              {
                  connection.Open();
                  adapter.Fill(ds);
              }
              catch (Exception ex)
              {
  
                  throw ex;
              }
  
  
              return ds;
          }
  
  
      ALTER PROCEDURE [dbo].[issue_sp_getreceipt] 
  
      @reqnum varchar (16)
      AS
      BEGIN
      SET NOCOUNT ON;
  
      SELECT empiitem.*, b.ACTNUMBR_1+ '-' +b.ACTNUMBR_2 + '/' + b.ACTDESCR [Expense_Account], c.ACTNUMBR_1+ '-' +c.ACTNUMBR_2 + '/' + c.ACTDESCR [Inventory_Account], 
                  empiitem.CURRCOST*quantity [extended_Cost]
      FROM 
          (
              SELECT empdata.*, b.ITEMDESC  from
              (   
                  Select *
                  from 
                  (Select Right(a.doc_num,12) [receipt_num], a.requisition_num, a.department, ab.expense_acc, a.inventory_acc_indx, a.issuer_id, ab.itemnum, ab.quantity, a.trans_date,
                          b.emp_firstname as [deptrepfname], b.emp_lastname [deptreplname], c.emp_firstname [Issuerfname],c.emp_lastname [Issurelname], ab.cost [CURRCOST], ab.uofm 
                      from [dbo].Issue a Inner Join dbo.IssueItem ab
                      on a.doc_num= ab.doc_num Left Outer Join [dbo].[Employee] b
                               on cast(a.dept_rep_id as int) = b.employee_id
                               Left join Employee c
                               on cast(a.issuer_id as int)= c.employee_id
                               where doc_type = 'Issue'
                  ) as emp
              ) empdata 
              Inner Join [TWCL].[dbo].[IV00101] b
                  on empdata.itemnum = b.ITEMNMBR
          ) empiitem 
          Inner Join [TWCL].[dbo].[GL00100] b
              on empiitem.expense_acc = b.ACTINDX
          Inner Join [TWCL].[dbo].[GL00100] c 
              on empiitem.inventory_acc_indx = c.ACTINDX
      WHERE requisition_num  = @reqnum
  
  
  
  END 
  
  
  public ActionResult ReceiptPrint(Issue issue)
      {
          IssueDAO dbdata = new IssueDAO();
          dbdata.connectionString = ConfigurationManager.ConnectionStrings["TWCL_OPERATIONSConnectionString"].ConnectionString;
          getIssue.transactionDate = DateTime.Now; //Sets the transaction date to current date
          getIssue.status = -1;
          Item item = new Item();
          try
          {
              dbdata.createIssue(getIssue, item);//Creates the issue in the database
          }
          catch (Exception ex)
          {
              LogWrite logWriter = new LogWrite(ex.ToString());
              ViewBag.errorMessage = "Unable to complete the Issue. Please see Log file for more Information";
              return View("IssueItem", getIssue);
  
          }
  
  
          DataSet ds = dbdata.GetReceipt(getIssue.requisitionNumber);
          LocalReport localreport = new LocalReport();
          localreport.ReportPath = Request.MapPath(Request.ApplicationPath) + @"Reports\Reciept.rdlc";
          localreport.DataSources.Add(new ReportDataSource("Receipt_Data", ds.Tables[0]));
          localreport.SetParameters(new ReportParameter("Req_num", getIssue.requisitionNumber));
          string reporttype = "PDF";
          string mimeType;
          string encoding;
          string fileNameExtension = "pdf";
          string deviceInfo = @"&lt;DeviceInfo&gt;              
                   &lt;OutputFormat&gt;PDF&lt;/OutputFormat&gt;              
                   &lt;PageWidth&gt;8.5in&lt;/PageWidth&gt;              
                   &lt;PageHeight&gt;11in&lt;/PageHeight&gt;          
                   &lt;MarginTop&gt;0.25in&lt;/MarginTop&gt;          
                   &lt;MarginLeft&gt;0.45in&lt;/MarginLeft&gt;            
                   &lt;MarginRight&gt;0.45in&lt;/MarginRight&gt;       
                   &lt;MarginBottom&gt;0.25in&lt;/MarginBottom&gt;&lt;/DeviceInfo&gt;";
          Warning[] warnings;
          string[] streams;
          byte[] renderedBytes;
          renderedBytes = localreport.Render(
           reporttype, deviceInfo, out mimeType, out encoding, out fileNameExtension,
           out streams, out warnings);
  
  
          var doc = new Document();
          var reader = new PdfReader(renderedBytes);
          using (FileStream fs = new FileStream(Server.MapPath("~/Receipt" +
               Convert.ToString(Session["CurrentUserName"]) + ".pdf"), FileMode.Create))
          {
              PdfStamper stamper = new PdfStamper(reader, fs);
              string Printer = "Xerox Phaser 3635MFP PCL6";
              // This is the script for automatically printing the pdf in acrobat viewer
              stamper.JavaScript = "var pp = getPrintParams();pp.interactive =pp.constants.interactionLevel.automatic; pp.printerName = " +
                             Printer + ";print(pp);\r";
              stamper.Close();
          }
          reader.Close();
          FileStream fss = new FileStream(Server.MapPath("~/Receipt.pdf"), FileMode.Open);
          byte[] bytes = new byte[fss.Length];
          fss.Read(bytes, 0, Convert.ToInt32(fss.Length));
          fss.Close();
          System.IO.File.Delete(Server.MapPath("~/Receipt.pdf"));
  
          //Here we returns the file result for view(PDF)
          //ModelState.Clear();
          //Session.Clear(); //Clears the session variable for reuse 
          return File(bytes, "application/pdf");
      }
  </code></pre>