title: Generating a PDF File using MVC
body: <p>I'm trying to generate a PDF using MVC, the problem I have is that I'm not sure how to display or make it work at the end, I'm using an ActionResult where I execute a Stored Procedure and fill a datatable with the result, which I later "try" to use in the PDF generator, so far it goes well, the problem is when I send the result to the View, where I get a error and don't know how to solve it, this is a life situation so I'd be very grateful if you could help me, sorry for my bad english.</p>
  
  <p>ActionResult:</p>
  
  <pre><code>public ActionResult PDFGenerator(string id
          )
  
      {
          using (Document document = new Document())
          {
              string idpago = "2";
              //while (id != null)
              int identificacionpago = Convert.ToInt32(idpago);
              DataTable dt = new DataTable();
              Database conex = Conexion.getInstancia();
              dt = conex.ExecuteDataSet("Usp_TraerPago", identificacionpago).Tables[0];
              string pago = dt.Rows[0]["ValorPago"].ToString();
              string aniopago = dt.Rows[0]["AnioPago"].ToString();
              DateTime fechapago = Convert.ToDateTime(dt.Rows[0]["FechaPago"]);
              //int pag = Convert.ToInt32(ViewBag.datos);
              int idusuario = Convert.ToInt32(dt.Rows[0]["IdUsuario"].ToString());
  
              DataTable dt1 = new DataTable();
              dt1 = conex.ExecuteDataSet("Usp_UsuarioPago", idusuario).Tables[0];
              string Numid = dt1.Rows[0]["NumIdentificacion"].ToString();
              string Tipoid = dt1.Rows[0]["TipoIdentificacion"].ToString();
              string Nombre = dt1.Rows[0]["NombresUsuario"].ToString();
              string apellidos = dt1.Rows[0]["ApellidosUsuario"].ToString();
              MemoryStream workStream = new MemoryStream();
              // Document document = new Document();
              PdfWriter.GetInstance(document, workStream).CloseStream = false;
  
              document.Open();
  
              document.Add(new Paragraph("                                                                                                                     " + DateTime.Now.ToString()));
              document.Add(new Paragraph("Certificado de participación"));
              document.Add(new Paragraph("  "));
              document.Add(new Paragraph("  "));
  
              document.Add(new Paragraph("                               por el año " + aniopago));
              document.Add(new Paragraph("El suscrito a  " + Nombre + " " + apellidos + " identificado con " + Tipoid + " " + Numid + " " + " En la fecha " + fechapago.Year + "/" + fechapago.Month + "/" + fechapago.Day + aniopago));
              document.Add(new Paragraph("  "));
              document.Add(new Paragraph("  "));
              document.Add(new Paragraph("  "));
              document.Add(new Paragraph("  "));
              document.Add(new Paragraph("  "));
              document.Add(new Paragraph("  "));
              document.Add(new Paragraph("  "));
              document.Add(new Paragraph("  "));
              document.Add(new Paragraph("___________________________ "));
              document.Add(new Paragraph("Firma del Revisor Fiscal   "));
  
              //document.SaveAs(workStream);
              document.Close();
  
              byte[] byteInfo = workStream.ToArray();
              workStream.Write(byteInfo, 0, byteInfo.Length);
              workStream.Position = 0;
  
              return File(workStream, "application/pdf");
          }
      }
  </code></pre>
  
  <p>Partial View:</p>
  
  <pre><code>     function generarpdf(value) {
  
       $.ajax({
           url: '@Url.Action("PDFGenerator", "Home")',
           type: 'POST',
           async: false,
           data: { "id": value },
           dataType: "application/pdf",
           success: function (data) {
               var file = new Blob([data], { type: 'application/pdf' });
               var fileURL = URL.createObjectURL(file);
               window.open(fileURL);
           }
       });
  </code></pre>
  
  <p>};</p>
  
  <p>It's called by this URL Action.</p>
  
  <pre><code>    &lt;a id="libro" href='@Url.Action("PDFGenerator","Home")'&gt;&lt;/a&gt;
  </code></pre>
  
  <p>When I execute it, the console shows this error:</p>
  
  <p>jquery-3.2.1.min.js:4 [Deprecation] Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check <a href="https://xhr.spec.whatwg.org/" rel="nofollow noreferrer">https://xhr.spec.whatwg.org/</a>.</p>