public HttpResponseMessage Post(SolicitudPdfViewModel datosSolicitud) { if (datosSolicitud == null) { return(new HttpResponseMessage(HttpStatusCode.NotFound)); } if (!datosSolicitud.Datos.Any()) { return(new HttpResponseMessage(HttpStatusCode.OK)); } var stream = new MemoryStream(); stream = DinersClubOnline.Api.Infrastructure.Pdf.CrearPdfHelper.CrearPdfSolicitud(datosSolicitud); return(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StreamContent(new MemoryStream(stream.GetBuffer())) { Headers = { ContentType = new MediaTypeHeaderValue("application/pdf"), ContentDisposition = new ContentDispositionHeaderValue("inline") { FileName = "solicitud" } } } }); }
public static MemoryStream CrearPdfSolicitud(SolicitudPdfViewModel datosSolicitud) { BaseColor colorAzul = new BaseColor(23, 54, 93); Font arialBold = FontFactory.GetFont("Arial", 12, Font.BOLD, colorAzul); Font arialNormal = FontFactory.GetFont("Arial", 12, Font.NORMAL); Font arialAzulNormal = FontFactory.GetFont("Arial", 12, Font.NORMAL, colorAzul); var readPdf = new PdfReader(Resources.DinersSolicitud); MemoryStream output = new MemoryStream(); PdfStamper scratchPdf = new PdfStamper(readPdf, output); PdfContentByte pbover = scratchPdf.GetOverContent(1); //add content to the page using ColumnText ColumnText.ShowTextAligned(pbover, Element.ALIGN_LEFT, new Phrase(datosSolicitud.Socio, arialAzulNormal), 58, 690, 0); ColumnText.ShowTextAligned(pbover, Element.ALIGN_LEFT, new Phrase(string.Format("Adjuntamos el detalle de tu {0}", datosSolicitud.Titulo), arialAzulNormal), 58, 670, 0); var tablaPdf = new PdfPTable(2); tablaPdf.SetTotalWidth(new float[] { 180, 200 }); tablaPdf.WidthPercentage = 70; tablaPdf.HorizontalAlignment = 0; //leave a gap before and after the table tablaPdf.SpacingBefore = 20f; tablaPdf.SpacingAfter = 20f; foreach (var arrDatos in datosSolicitud.Datos) { for (var column = 0; column < 2; column++) { var tipoLetra = column == 0 ? arialBold : arialNormal; var celda = new PdfPCell(new Phrase(arrDatos[column], tipoLetra)); // sin borde y espacio entre celdas celda.BorderWidth = 0; celda.PaddingTop = 7; tablaPdf.AddCell(celda); } } tablaPdf.WriteSelectedRows(0, tablaPdf.Rows.Count, 55, 650, scratchPdf.GetOverContent(1)); scratchPdf.Close(); return(output); }