public void CreatePDF(Empresa empresa, User user, Pedido pedido, List <PedidoItem> items, string logFile, string prefijo, Stream file, OfertaMargin margin) { //using (var fileStream= new FileStream(file, FileMode.Create)){ Document document = new Document(PageSize.LETTER.Rotate(), margin.Left, margin.Right, margin.Top, margin.Bottom); using (PdfWriter PDFWriter = PdfWriter.GetInstance(document, file)) { PDFWriter.ViewerPreferences = PdfWriter.PageModeUseOutlines; PDFWriter.CloseStream = false; // Our custom Header and Footer is done using Event Handler OfertaPdfEventHandler PageEventHandler = new OfertaPdfEventHandler() { LogoFile = logFile, Empresa = empresa, Pedido = pedido, Prefijo = prefijo, //FontFamilyName= FontFamilyName, F10 = f10, F7 = f7, F8 = f8 }; PDFWriter.PageEvent = PageEventHandler; document.Open(); PdfPTable solicitadPor = new PdfPTable(1); PdfPCell cell = new PdfPCell(new Phrase("Solicitado Por:", f8)); cell.HorizontalAlignment = PdfPCell.ALIGN_CENTER; solicitadPor.AddCell(cell); cell = new PdfPCell(new Phrase(pedido.NombreCliente, f8)); cell.Border = PdfPCell.NO_BORDER; solicitadPor.AddCell(cell); cell = new PdfPCell(new Phrase(pedido.NitCliente, f8)); cell.Border = PdfPCell.NO_BORDER; solicitadPor.AddCell(cell); cell = new PdfPCell(new Phrase(pedido.NombreContacto, f8)); cell.Border = PdfPCell.NO_BORDER; solicitadPor.AddCell(cell); cell = new PdfPCell(new Phrase(pedido.MailContacto, f8)); cell.Border = PdfPCell.NO_BORDER; solicitadPor.AddCell(cell); PdfPTable destinatario = new PdfPTable(1); cell = new PdfPCell(new Phrase("Destinatario:", f8)); cell.HorizontalAlignment = PdfPCell.ALIGN_CENTER; destinatario.AddCell(cell); cell = new PdfPCell(new Phrase(pedido.NombreDestinatario, f10)); cell.Border = PdfPCell.NO_BORDER; destinatario.AddCell(cell); cell = new PdfPCell(new Phrase(pedido.CargoDestinatario, f8)); cell.Border = PdfPCell.NO_BORDER; destinatario.AddCell(cell); cell = new PdfPCell(new Phrase(pedido.DireccionDestinatario + "-" + pedido.NombreCiudad, f8)); cell.Border = PdfPCell.NO_BORDER; destinatario.AddCell(cell); cell = new PdfPCell(new Phrase(string.Format("{0}{1}", pedido.TelefonoDestinatario, (!pedido.TelefonoDestinatario.IsNullOrEmpty() && !pedido.FaxDestinatario.IsNullOrEmpty())? "-" + pedido.FaxDestinatario: pedido.FaxDestinatario) + "-" + pedido.CelularDestinatario, f8)); cell.Border = PdfPCell.NO_BORDER; destinatario.AddCell(cell); cell = new PdfPCell(new Phrase(pedido.MailDestinatario, f8)); cell.Border = PdfPCell.NO_BORDER; destinatario.AddCell(cell); PdfPTable solicitadoDestinatario = new PdfPTable(2); solicitadoDestinatario.WidthPercentage = 95; cell = new PdfPCell(solicitadPor); cell.Padding = 10; cell.Border = PdfPCell.NO_BORDER; solicitadoDestinatario.AddCell(cell); cell = new PdfPCell(destinatario); cell.Padding = 10; cell.Border = PdfPCell.NO_BORDER; solicitadoDestinatario.AddCell(cell); document.Add(solicitadoDestinatario); ConstruirTablaItems(document, items); ConstruirResumen(document, items); //ConstruirNotaGastosEnvio(document, pedido); ConstruirCondiciones(document, empresa, user); ConstruirObservacion(document, empresa, pedido, user); ConstruirFirma(document, empresa, user); document.Close(); } //} }
public void CreatePDF(Empresa empresa, User user, Pedido pedido, List<PedidoItem> items, string logFile, string prefijo, Stream file, OfertaMargin margin) { //using (var fileStream= new FileStream(file, FileMode.Create)){ Document document = new Document(PageSize.LETTER.Rotate(), margin.Left, margin.Right, margin.Top, margin.Bottom ); using (PdfWriter PDFWriter= PdfWriter.GetInstance(document,file)) { PDFWriter.ViewerPreferences = PdfWriter.PageModeUseOutlines; PDFWriter.CloseStream=false; // Our custom Header and Footer is done using Event Handler OfertaPdfEventHandler PageEventHandler = new OfertaPdfEventHandler(){ LogoFile=logFile, Empresa = empresa, Pedido = pedido, Prefijo = prefijo, //FontFamilyName= FontFamilyName, F10=f10, F7=f7, F8=f8 }; PDFWriter.PageEvent = PageEventHandler; document.Open(); PdfPTable solicitadPor = new PdfPTable(1); PdfPCell cell = new PdfPCell(new Phrase("Solicitado Por:",f8)); cell.HorizontalAlignment= PdfPCell.ALIGN_CENTER; solicitadPor.AddCell(cell); cell = new PdfPCell(new Phrase(pedido.NombreCliente,f8)); cell.Border= PdfPCell.NO_BORDER; solicitadPor.AddCell(cell); cell = new PdfPCell(new Phrase(pedido.NitCliente,f8)); cell.Border= PdfPCell.NO_BORDER; solicitadPor.AddCell(cell); cell = new PdfPCell(new Phrase(pedido.NombreContacto,f8)); cell.Border= PdfPCell.NO_BORDER; solicitadPor.AddCell(cell); cell = new PdfPCell(new Phrase(pedido.MailContacto,f8)); cell.Border= PdfPCell.NO_BORDER; solicitadPor.AddCell(cell); PdfPTable destinatario = new PdfPTable(1); cell = new PdfPCell(new Phrase("Destinatario:", f8)); cell.HorizontalAlignment= PdfPCell.ALIGN_CENTER; destinatario.AddCell(cell); cell = new PdfPCell(new Phrase(pedido.NombreDestinatario, f10)); cell.Border= PdfPCell.NO_BORDER; destinatario.AddCell(cell); cell = new PdfPCell(new Phrase(pedido.CargoDestinatario,f8)); cell.Border= PdfPCell.NO_BORDER; destinatario.AddCell(cell); cell = new PdfPCell(new Phrase(pedido.DireccionDestinatario+"-"+pedido.NombreCiudad,f8)); cell.Border= PdfPCell.NO_BORDER; destinatario.AddCell(cell); cell = new PdfPCell(new Phrase(string.Format("{0}{1}", pedido.TelefonoDestinatario, (!pedido.TelefonoDestinatario.IsNullOrEmpty() && !pedido.FaxDestinatario.IsNullOrEmpty())? "-"+pedido.FaxDestinatario: pedido.FaxDestinatario)+ "-" + pedido.CelularDestinatario ,f8)); cell.Border= PdfPCell.NO_BORDER; destinatario.AddCell(cell); cell = new PdfPCell(new Phrase(pedido.MailDestinatario,f8)); cell.Border= PdfPCell.NO_BORDER; destinatario.AddCell(cell); PdfPTable solicitadoDestinatario = new PdfPTable(2); solicitadoDestinatario.WidthPercentage=95; cell= new PdfPCell(solicitadPor); cell.Padding=10; cell.Border= PdfPCell.NO_BORDER; solicitadoDestinatario.AddCell(cell); cell= new PdfPCell(destinatario); cell.Padding=10; cell.Border= PdfPCell.NO_BORDER; solicitadoDestinatario.AddCell(cell); document.Add(solicitadoDestinatario); ConstruirTablaItems(document,items); ConstruirResumen(document, items); ConstruirNotaGastosEnvio(document, pedido); ConstruirCondiciones(document, empresa, user); ConstruirObservacion(document, empresa, pedido, user); ConstruirFirma(document, empresa, user); document.Close(); } //} }