Click here to Skip to main content
15,905,148 members

Comments by j053pepe (Top 1 by date)

j053pepe 29-Nov-16 12:20pm View    
hi, i have other example, show your pdf in new page or div.

/// Call my html and send Id of document

function AbrirArchivo(DocumentoId) {
var url =
"/../WebServices/WS/Beca.asmx/GenerarPDF2?DocumentoId=" + DocumentoId;

var archiv = window;
archiv.open("../Inscritos/Archivos/Archivo.html", "PDF");
archiv.Ruta = url;
}

/*in my Archivo.html i have this code */
<!DOCTYPE html>


<meta charset="utf-8" />
<title>Documento
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta content="" name="description" />
<meta content="" name="author" />
<meta http-equiv="pragma" content="no-cache" />

html, body {
margin: 0;
padding: 0;
border: 0;
height: 100%;
overflow: hidden;
}

iframe {
width: 100%;
height: 100%;
border: 0;
}







$(document).ready(function () {

var Ruta = window.opener.Ruta;
crarPDF();

function crarPDF() {
$('#iframepdf').attr('src', Ruta);
}
});



/* end file */

in my asmx i have function
[WebMethod]
public void GenerarPDF2(string DocumentoId)
{
Stream stream = new MemoryStream(BLLAlumnoInscrito.TraerDocumento(int.Parse(DocumentoId)));
var MemoryStream = new MemoryStream();
stream.CopyTo(MemoryStream);

HttpContext.Current.Response.Expires = 0;
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.ContentType = "application/pdf";
HttpContext.Current.Response.AddHeader("Content-Type", "application/pdf");
HttpContext.Current.Response.AddHeader("Content-Disposition", "inline; filename=" + "Beca" + ".pdf");
HttpContext.Current.Response.BinaryWrite(MemoryStream.ToArray());
HttpContext.Current.Response.Flush();
MemoryStream.Close();
HttpContext.Current.Response.End();
}