/// <summary> /// Defines page setup, headers, and footers /// </summary> /// <param name="document">MigraDoc document created via Documents.CreateDocument()</param> public static void DefineContentSection(Document document) { Section section = document.AddSection(); section.PageSetup.TopMargin = "5cm"; section.PageSetup.StartingNumber = 1; section.PageSetup.Orientation = Orientation.Landscape; // Create header HeaderFooter header = section.Headers.Primary; // Add logo Image image = header.AddImage(Report.logoPath); image.Width = "8cm"; image.WrapFormat.Style = WrapStyle.Through; // Add company name Paragraph h1 = new Paragraph(); h1.AddText(Report.companyName); h1.Format.Font.Color = Colors.SlateGray; h1.Format.Font.Size = 24; h1.Format.Font.Bold = true; header.Add(h1); // Add report name Paragraph h2 = new Paragraph(); h2.Format.Font.Color = Colors.SlateGray; h2.AddText("Welfare Check Breach Report"); h2.Format.Font.Size = 18; h2.Format.Borders.Width = 0; h2.Format.Borders.Bottom.Width = 1; h2.Format.Borders.Color = Colors.LightSlateGray; h2.Format.Borders.Distance = 4; header.Add(h2); // Add current date Paragraph h3 = new Paragraph(); h3.Format.Font.Size = 12; h3.Format.Font.Italic = true; h3.Format.Borders.Distance = 6; h3.AddDateField(); header.Add(h3); // Create a paragraph with centered page number. See definition of style "Footer". Paragraph footer = new Paragraph(); footer.Format.Borders.Width = 0; footer.Format.Borders.Top.Width = 1; footer.Format.Borders.Color = Colors.LightSlateGray; footer.Format.Borders.Distance = 10; footer.AddPageField(); // Add paragraph to footer section.Footers.Primary.Add(footer); }
/// <summary> /// Render a title into a header or footer /// </summary> public override void RenderInto(HeaderFooter headerFooter) { MigraDoc.DocumentObjectModel.Paragraph title = new MigraDoc.DocumentObjectModel.Paragraph(); title.Style = "Heading1"; this.RenderTextInto(title); headerFooter.Add(title); }
private HeaderFooter AddHeaderFooter(HeaderFooter hf, object left, object centered, object right, bool clear) { if (clear) { hf.Elements.Clear(); hf.Format.TabStops.ClearAll(); var bodywidth = BodyWidth(); hf.Format.TabStops.AddTabStop(bodywidth / 2, TabAlignment.Center); hf.Format.TabStops.AddTabStop(bodywidth, TabAlignment.Right); } Paragraph paragraph = null; if (left != null) { AddHeaderFooterItem(ref paragraph, left); } if (centered != null || right != null) { paragraph = paragraph ?? new Paragraph(); paragraph.AddTab(); AddHeaderFooterItem(ref paragraph, centered); if (right != null) { paragraph.AddTab(); AddHeaderFooterItem(ref paragraph, right); } } if (paragraph != null) { hf.Add(paragraph); } return(hf); }
static void Cabecera(Document document, Documento doc, List <Detalle> listadetalle) { Section section = document.AddSection(); section.PageSetup.PageFormat = PageFormat.A4; section.PageSetup.TopMargin = new Unit(10, UnitType.Millimeter); section.PageSetup.LeftMargin = new Unit(10, UnitType.Millimeter); section.PageSetup.RightMargin = new Unit(10, UnitType.Millimeter); section.PageSetup.OddAndEvenPagesHeaderFooter = false; section.PageSetup.StartingNumber = 1; HeaderFooter header = section.Headers.Primary; //header.AddParagraph("\tOdd Page Header"); //string ii = Path.Combine(cr, "logo.jpg"); string cr = @"E:\ProgramaC#\senddocs\logo.jpg"; if (File.Exists(cr)) { Section sectionlogo = document.LastSection; TextFrame logo = new TextFrame(); logo.RelativeHorizontal = RelativeHorizontal.Margin; logo.RelativeVertical = RelativeVertical.Margin; var serienn = doc.serienumero.Substring(0, 1); if (doc.tipodocumento == "01") { logo.WrapFormat.DistanceTop = new Unit(-230); } else if (doc.tipodocumento == "03") { logo.WrapFormat.DistanceTop = new Unit(-180); } else if (doc.tipodocumento == "07") { logo.WrapFormat.DistanceTop = new Unit(-200); } var im = logo.AddImage(@"E:\ProgramaC#\senddocs\logo.jpg"); im.Width = new Unit(75); section.Add(logo); } TextFrame textFrame = new TextFrame(); //textFrame.MarginTop = new Unit(100, UnitType.Millimeter); textFrame.Width = new Unit(200); textFrame.Height = new Unit(100); textFrame.RelativeHorizontal = RelativeHorizontal.Margin; textFrame.RelativeVertical = RelativeVertical.Margin; textFrame.WrapFormat.DistanceLeft = new Unit(320); if (doc.tipodocumento == "01") { textFrame.WrapFormat.DistanceTop = new Unit(-260); } else if (doc.tipodocumento == "03") { textFrame.WrapFormat.DistanceTop = new Unit(-210); } else if (doc.tipodocumento == "07") { textFrame.WrapFormat.DistanceTop = new Unit(-230); } textFrame.LineFormat.Width = new Unit(1); textFrame.LineFormat.Color = MigraDoc.DocumentObjectModel.Colors.Black; //textFrame.FillFormat.Color = MigraDoc.DocumentObjectModel.Colors.Green; var texto = textFrame.AddParagraph("RUC:" + doc.rucempresa); texto.Format.Alignment = ParagraphAlignment.Center; texto.Style = "Heading1"; if (doc.tipodocumento == "01") { texto = textFrame.AddParagraph("FACTURA ELECTRÓNICA"); texto.Format.Alignment = ParagraphAlignment.Center; texto.Style = "Heading1"; } else if (doc.tipodocumento == "03") { texto = textFrame.AddParagraph("BOLETA ELECTRÓNICA"); texto.Format.Alignment = ParagraphAlignment.Center; texto.Style = "Heading1"; } else if (doc.tipodocumento == "07") { texto = textFrame.AddParagraph("Nota de Credito Electronica"); texto.Format.Alignment = ParagraphAlignment.Center; texto.Style = "Heading1"; } texto = textFrame.AddParagraph("\n" + doc.serienumero); texto.Format.Alignment = ParagraphAlignment.Center; texto.Style = "Heading1"; header.Add(textFrame); //string cr = @"E:\ProgramaC#\senddocs\logo.jpg"; var paragraph = header.AddParagraph(doc.razonsocialempresa); paragraph.Style = "Heading2"; paragraph = header.AddParagraph(); if (!File.Exists(cr)) { paragraph.AddText(doc.direccionempresa + "\n"); paragraph.AddText(doc.departamentoempresa + "," + doc.provinciaempresa + "," + doc.distritoempresa + "\n"); paragraph.AddText(doc.telefono1Empresa + "\n"); } else { TextFrame tflogo = new TextFrame(); var tl = tflogo.AddParagraph(); tflogo.Width = new Unit(250); tflogo.Height = new Unit(100); //tflogo.RelativeHorizontal = RelativeHorizontal.Margin; //tflogo.RelativeVertical = RelativeVertical.Margin; tflogo.WrapFormat.DistanceTop = new Unit(-10); tflogo.WrapFormat.DistanceLeft = new Unit(80); tflogo.WrapFormat.DistanceBottom = new Unit(-60); tflogo.AddParagraph(doc.direccionempresa + "\n"); tflogo.AddParagraph(doc.departamentoempresa + "," + doc.provinciaempresa + "," + doc.distritoempresa + "\n"); tflogo.AddParagraph(doc.telefono1Empresa + "\n"); //paragraph.AddText(doc.direccionempresa + "\n"); //paragraph.AddText(doc.departamentoempresa + "," + doc.provinciaempresa + "," + doc.distritoempresa + "\n"); //paragraph.AddText(doc.telefono1Empresa + "\n"); header.Add(tflogo); } if (doc.tipodocumento == "03") { paragraph = header.AddParagraph("\n\n\n"); paragraph.Style = "TOC"; paragraph.AddFormattedText("\nSEÑOR(es)\t", TextFormat.Bold); paragraph.AddText(doc.razonsocialcliente); paragraph.AddFormattedText("\nDNI No\t", TextFormat.Bold); paragraph.AddText(doc.numerodocumentocliente); paragraph.AddFormattedText("\nDIRECCIÓN\t", TextFormat.Bold); paragraph.AddText(doc.direccioncliente); paragraph.AddFormattedText("\nPARTIDA\t", TextFormat.Bold); paragraph.AddText(doc.puntopartida); } else if (doc.tipodocumento == "01") { paragraph = header.AddParagraph("\n\n\n"); paragraph.Style = "TOC"; paragraph.AddFormattedText("\nSEÑOR(es)\t", TextFormat.Bold); paragraph.AddText(doc.razonsocialcliente); paragraph.AddFormattedText("\nRUC No\t", TextFormat.Bold); paragraph.AddText(doc.numerodocumentocliente); paragraph.AddFormattedText("\nDIRECCIÓN\t", TextFormat.Bold); paragraph.AddText(doc.direccioncliente); paragraph.AddFormattedText("\nPARTIDA\t", TextFormat.Bold); paragraph.AddText(doc.puntopartida); paragraph.AddFormattedText("\nLLEGADA\t", TextFormat.Bold); paragraph.AddText(doc.puntollegada); paragraph.AddFormattedText("\nTRASNPORTE\t", TextFormat.Bold); paragraph.AddText(doc.codigochofer); paragraph.AddFormattedText("\nCOD.VEND\t", TextFormat.Bold); paragraph.AddText(doc.codigovendedor); paragraph.AddFormattedText("\nNOM.VEND\t", TextFormat.Bold); paragraph.AddText(doc.nombrevendedor); } if (doc.tipodocumento == "07") { paragraph = header.AddParagraph("\n\n\n"); paragraph.Style = "TOC"; paragraph.AddFormattedText("\nSEÑOR(es)\t", TextFormat.Bold); paragraph.AddText(doc.razonsocialcliente); paragraph.AddFormattedText("\nRUC No\t", TextFormat.Bold); paragraph.AddText(doc.numerodocumentocliente); paragraph.AddFormattedText("\nDIRECCIÓN\t", TextFormat.Bold); paragraph.AddText(doc.direccioncliente); paragraph.AddFormattedText("\nDOC.AFECTADO\t", TextFormat.Bold); paragraph.AddText(doc.serienumeroafectado + "\n"); paragraph.AddText(doc.sustentonotacredeb); } //Agregar Tabla paragraph.AddText("\n"); header.AddParagraph(""); Table table = new Table(); table.Borders.Width = 0.75; Column column = table.AddColumn(Unit.FromCentimeter(4)); column = table.AddColumn(Unit.FromCentimeter(4)); column = table.AddColumn(Unit.FromCentimeter(4)); column = table.AddColumn(Unit.FromCentimeter(4)); column.Format.Alignment = ParagraphAlignment.Center; table.AddColumn(Unit.FromCentimeter(4)); Row row = table.AddRow(); row.Shading.Color = Colors.LightGray; row.Format.Alignment = ParagraphAlignment.Center; Cell cell = row.Cells[0]; cell.AddParagraph("NO INTERNO"); cell = row.Cells[1]; cell.AddParagraph("FECHA EMISION"); cell = row.Cells[2]; cell.AddParagraph("FECHA VENCIMIENTO"); cell = row.Cells[3]; cell.AddParagraph("CONDICIONES"); cell = row.Cells[4]; cell.AddParagraph("GUIA REMISION"); row = table.AddRow(); row.Format.Alignment = ParagraphAlignment.Center; cell = row.Cells[0]; cell.AddParagraph(); cell = row.Cells[1]; cell.AddParagraph(doc.fechaemision); cell = row.Cells[2]; cell.AddParagraph(); cell = row.Cells[3]; cell.AddParagraph(doc.condicion); cell = row.Cells[4]; cell.AddParagraph(); //table.SetEdge(0, 0, 2, 3, Edge.Box, BorderStyle.Single, 1.5, Colors.Black); //string cr = @"E:\ProgramaC#\senddocs\logo.jpg"; //if (File.Exists(cr)) //{ // Section sectionlogo = document.LastSection; // TextFrame logo = new TextFrame(); // logo.WrapFormat.DistanceTop = new Unit(-475); // var im = logo.AddImage(@"E:\ProgramaC#\senddocs\logo.jpg"); // im.Width = new Unit(75); // section.Add(logo); //} header.Add(table); }
/// <summary> /// Render a paragraph into a header or footer /// </summary> public override void RenderInto(HeaderFooter headerFooter) { MigraDoc.DocumentObjectModel.Paragraph paragraph = this.Create(); headerFooter.Add(paragraph); }
/// <summary> /// Render a image into a header or footer /// </summary> public void RenderInto(HeaderFooter headerFooter) { MigraDoc.DocumentObjectModel.Shapes.Image image = this.CreateImage(); headerFooter.Add(image); }
private Document DocumentoEpicrisisGabinete() { Document document = new Document(); if (TxtNumExpediente.Text.Trim() != "") { if (lstConsultasPaciente.Items.Count > 0) { if (oCEmpresa.LeeDatosEmpresa() == true && oCPacientes.LeeDatosPaciente(TxtNumExpediente.Text.Trim()) == true) { Section section = document.AddSection(); #region Encabezado (Fecha, Título, Datos Personales y Detalle Opcional) Table tableHeader = document.LastSection.AddTable(); tableHeader.Borders.Visible = true; tableHeader.Borders.Width = 0; Column columnHeader = tableHeader.AddColumn("8cm"); columnHeader.Format.Alignment = ParagraphAlignment.Right; columnHeader = tableHeader.AddColumn("8cm"); columnHeader.Format.Alignment = ParagraphAlignment.Center; Row rowHeader = tableHeader.AddRow(); tableHeader.AddRow(); tableHeader.AddRow(); tableHeader.AddRow(); #region Fecha Paragraph oParagraphDate = rowHeader.Cells[0].AddParagraph(DateTime.Now.Date.ToLongDateString()); oParagraphDate.Format.Font = new MigraDoc.DocumentObjectModel.Font("Arial", 10); rowHeader.Cells[0].MergeRight = 1; #endregion #region Título rowHeader = tableHeader.AddRow(); rowHeader.Cells[0].MergeRight = 1; Paragraph oParagraphTitle = rowHeader.Cells[0].AddParagraph("Epicrisis"); oParagraphTitle.Format.Alignment = ParagraphAlignment.Center; oParagraphTitle.Format.Font = new MigraDoc.DocumentObjectModel.Font("Arial", 26); #endregion tableHeader.AddRow(); tableHeader.AddRow(); tableHeader.AddRow(); #region Datos Personales (Nombre y Cédula) rowHeader = tableHeader.AddRow(); Paragraph oParagraphNombre = rowHeader.Cells[0].AddParagraph(); FormattedText oFormattedTextNombre = oParagraphNombre.AddFormattedText("Nombre: "); oFormattedTextNombre.Bold = true; oFormattedTextNombre.Font.Name = "Segoe UI"; oFormattedTextNombre.Font.Size = 11; oParagraphNombre.Format.Font = new MigraDoc.DocumentObjectModel.Font("Arial", 9); oParagraphNombre.AddText(oCPacientes.Nombre.Trim() + " " + oCPacientes.Apellidos.Trim()); oParagraphNombre.Format.Alignment = ParagraphAlignment.Left; Paragraph oParagraphCedula = rowHeader.Cells[1].AddParagraph(); FormattedText oFormattedTextCedula = oParagraphCedula.AddFormattedText("Cédula: "); oFormattedTextCedula.Bold = true; oFormattedTextCedula.Font.Name = "Segoe UI"; oFormattedTextCedula.Font.Size = 11; oParagraphCedula.Format.Font = new MigraDoc.DocumentObjectModel.Font("Arial", 9); oParagraphCedula.AddText(oCPacientes.Cedula); oParagraphCedula.Format.Alignment = ParagraphAlignment.Left; #endregion tableHeader.AddRow(); tableHeader.AddRow(); #region Detalle Opcional rowHeader = tableHeader.AddRow(); rowHeader.Cells[0].MergeRight = 1; Paragraph oParagraphDetalleOpcional = rowHeader.Cells[0].AddParagraph(); FormattedText oFormattedDetalleOpcional = oParagraphDetalleOpcional.AddFormattedText(textBox1.Text.Trim()); oFormattedDetalleOpcional.Font.Name = "Arial"; oFormattedDetalleOpcional.Font.Size = 10; oParagraphDetalleOpcional.Format.Alignment = ParagraphAlignment.Left; #endregion tableHeader.AddRow(); tableHeader.AddRow(); tableHeader.AddRow(); #endregion #region Tabla de Datos de Consultas if (rdNoIncluirDetallesConsultas.Checked == false) { Table tableData = document.LastSection.AddTable(); tableData.Borders.Visible = true; tableData.Borders.Width = 0.74; tableData.Borders.Color = new MigraDoc.DocumentObjectModel.Color(192, 80, 77); Column columnData = tableData.AddColumn("2.8cm"); columnData.Format.Alignment = ParagraphAlignment.Center; columnData = tableData.AddColumn("3.5cm"); columnData.Format.Alignment = ParagraphAlignment.Center; columnData = tableData.AddColumn("3.5cm"); columnData.Format.Alignment = ParagraphAlignment.Center; columnData = tableData.AddColumn("3.7cm"); columnData.Format.Alignment = ParagraphAlignment.Center; columnData = tableData.AddColumn("3.7cm"); columnData.Format.Alignment = ParagraphAlignment.Center; Row rowData = tableData.AddRow(); rowData.Borders.Top.Clear(); rowData.Borders.Left.Clear(); rowData.Borders.Right.Clear(); rowData.Borders.Bottom.Width = Unit.FromMillimeter(1); Paragraph oParagraphDataHeader = new Paragraph(); //oParagraphDataHeader = rowData.Cells[0].AddParagraph("Fecha de Consulta"); //oParagraphDataHeader.Format.Font = new MigraDoc.DocumentObjectModel.Font("Times New Roman", 13); //oParagraphDataHeader.Format.Font.Bold = true; oParagraphDataHeader = rowData.Cells[0].AddParagraph("Detalle de la Consulta"); oParagraphDataHeader.Format.Font = new MigraDoc.DocumentObjectModel.Font("Times New Roman", 13); oParagraphDataHeader.Format.Font.Bold = true; oParagraphDataHeader = rowData.Cells[1].AddParagraph("Diagnóstico"); oParagraphDataHeader.Format.Font = new MigraDoc.DocumentObjectModel.Font("Times New Roman", 13); oParagraphDataHeader.Format.Font.Bold = true; oParagraphDataHeader = rowData.Cells[2].AddParagraph("Tratamiento"); oParagraphDataHeader.Format.Font = new MigraDoc.DocumentObjectModel.Font("Times New Roman", 13); oParagraphDataHeader.Format.Font.Bold = true; oParagraphDataHeader = rowData.Cells[3].AddParagraph("Exámenes Prescritos"); oParagraphDataHeader.Format.Font = new MigraDoc.DocumentObjectModel.Font("Times New Roman", 13); oParagraphDataHeader.Format.Font.Bold = true; oParagraphDataHeader = rowData.Cells[4].AddParagraph("Gabinete"); oParagraphDataHeader.Format.Font = new MigraDoc.DocumentObjectModel.Font("Times New Roman", 13); oParagraphDataHeader.Format.Font.Bold = true; Paragraph oParagraphData = new Paragraph(); ArrayList oArregloDetallesConsultaEpicrisis = new ArrayList(); int alternateColor = 0; bool continuar = false; foreach (ListViewItem oItem in lstConsultasPaciente.Items) { if (rdTodas.Checked == true) { continuar = true; } else if (rdSeleccionar.Checked == true) { if (oItem.Checked == true) { continuar = true; } else { continuar = false; } } if (continuar == true) { oArregloDetallesConsultaEpicrisis = oCConsultas.DetallesConsultaEpicrisis(oItem.SubItems[1].Text.Trim()); rowData = tableData.AddRow(); //if (alternateColor == 0) // rowData.Shading.Color = new MigraDoc.DocumentObjectModel.Color(239, 211, 210); //else rowData.Shading.Color = Colors.White; string consultaHeader = Convert.ToDateTime(oItem.SubItems[3].Text).ToShortDateString(); oParagraphData = rowData.Cells[0].AddParagraph(consultaHeader); oParagraphData.Format.Font = new MigraDoc.DocumentObjectModel.Font("Times New Roman", 12); oParagraphData.Format.Font.Bold = true; oParagraphData.Format.Font.Color = new MigraDoc.DocumentObjectModel.Color(36, 64, 97); oParagraphData.Format.Alignment = ParagraphAlignment.Left; rowData.Cells[0].Shading.Color = Colors.White; oParagraphData = rowData.Cells[0].AddParagraph(""); oParagraphData = rowData.Cells[0].AddParagraph(oArregloDetallesConsultaEpicrisis[0].ToString().Trim()); oParagraphData.Format.Font.Bold = false; oParagraphData.Format.Font = new MigraDoc.DocumentObjectModel.Font("Arial", 8); oParagraphData.Format.Alignment = ParagraphAlignment.Left; string oTratamiento = oArregloDetallesConsultaEpicrisis[1].ToString().Trim(); int c = 0; while (oTratamiento.Contains("{") || oTratamiento.Contains("}")) { if (c == 0) { oTratamiento = Metodos_Globales.CortaSeccionDeTexto(oTratamiento, "{", "}", ""); } else { oTratamiento = Metodos_Globales.CortaSeccionDeTexto(oTratamiento, "{", "}", ", "); } c++; } oParagraphData = rowData.Cells[1].AddParagraph(oTratamiento.Trim()); oParagraphData.Format.Font.Bold = false; oParagraphData.Format.Font = new MigraDoc.DocumentObjectModel.Font("Arial", 8); oParagraphData.Format.Alignment = ParagraphAlignment.Left; oParagraphData = rowData.Cells[2].AddParagraph(oArregloDetallesConsultaEpicrisis[2].ToString().Trim()); oParagraphData.Format.Font.Bold = false; oParagraphData.Format.Font = new MigraDoc.DocumentObjectModel.Font("Arial", 8); oParagraphData.Format.Alignment = ParagraphAlignment.Left; string detalleExamen = ""; DataSet ds = oCExamenesConsulta.ConsultarSinParametros(oItem.SubItems[1].Text.Trim()); if (ds != null) { if (ds.Tables[0].Rows.Count > 0) { foreach (DataRow dr in ds.Tables[0].Rows) { if (Convert.ToBoolean(dr[3]) == true) { detalleExamen = "• " + oCExamenesConsulta.NombreExamen(dr[0].ToString().Trim()) + "(" + dr[5].ToString().Trim() + ")."; } else { detalleExamen = "• " + oCExamenesConsulta.NombreExamen(dr[0].ToString().Trim()) + "(\"Pendiente de resultados\")."; } oParagraphData = rowData.Cells[3].AddParagraph(detalleExamen.Trim()); oParagraphData.Format.Font.Bold = false; oParagraphData.Format.Font = new MigraDoc.DocumentObjectModel.Font("Arial", 8); oParagraphData.Format.Alignment = ParagraphAlignment.Left; oParagraphData.AddLineBreak(); } } ds.Dispose(); } string gabinete = ""; DataSet ds1 = oCGabineteConsulta.ConsultarSinParametros(oItem.SubItems[1].Text.Trim()); if (ds1 != null) { if (ds1.Tables[0].Rows.Count > 0) { foreach (DataRow dr in ds1.Tables[0].Rows) { if (Convert.ToBoolean(dr[3]) == true) { gabinete = "• " + oCGabineteConsulta.NombreGabinete(dr[0].ToString().Trim()) + "(" + dr[5].ToString().Trim() + ")."; } else { gabinete = "• " + oCGabineteConsulta.NombreGabinete(dr[0].ToString().Trim()) + "(\"Pendiente de resultados\")."; } oParagraphData = rowData.Cells[4].AddParagraph(gabinete.Trim()); oParagraphData.Format.Font.Bold = false; oParagraphData.Format.Font = new MigraDoc.DocumentObjectModel.Font("Arial", 8); oParagraphData.Format.Alignment = ParagraphAlignment.Left; oParagraphData.AddLineBreak(); } } ds1.Dispose(); } if (alternateColor == 0) { alternateColor = 1; } else { alternateColor = 0; } rowData.Borders.Top.Clear(); rowData.Borders.Left.Clear(); //rowData.Borders.Bottom.Clear(); } } } #endregion #region Agrega Footer Section section2 = document.LastSection; section2.PageSetup.OddAndEvenPagesHeaderFooter = false; HeaderFooter footer = new HeaderFooter(); Paragraph paraFooter = new Paragraph(); MigraDoc.DocumentObjectModel.Font ofont = new MigraDoc.DocumentObjectModel.Font("Arial", 8); paraFooter.AddLineBreak(); ofont.Color = Colors.Black; string nombreEmp = oCEmpleados.ObtieneNombreEmpleado(Program.oIdUsuario); string codEmpleado = oCEmpleados.ObtieneCodigoColegiado(Program.oIdUsuario); string footerText = "________________________________" + Environment.NewLine + nombreEmp.Trim() + Environment.NewLine + "Cód. " + codEmpleado.Trim(); paraFooter.AddFormattedText(footerText, ofont); paraFooter.Format.Alignment = ParagraphAlignment.Right; footer.Add(paraFooter); //section2.Footers.Primary = footer; document.LastSection.Footers.Primary = footer; #endregion #region Crea el documento pdfRenderer = new PdfDocumentRenderer(false, PdfFontEmbedding.Always); pdfRenderer.Document = document; pdfRenderer.RenderDocument(); #endregion } } } oDocument = document; return(document); }
public static byte[] GeneratePdf(Consignment co) { // Create a MigraDoc document Document document = new Document(); document.DefaultPageSetup.LeftMargin = Unit.FromCentimeter(1); document.DefaultPageSetup.RightMargin = Unit.FromCentimeter(1); MigraDoc.DocumentObjectModel.Style style = document.Styles["Normal"]; style.Font.Name = "Arial"; style.Font.Size = 10; Unit pageWidth = document.DefaultPageSetup.PageWidth; pageWidth -= document.DefaultPageSetup.LeftMargin + document.DefaultPageSetup.RightMargin; Section section = document.AddSection(); section.PageSetup.HeaderDistance = Unit.FromMillimeter(5); section.PageSetup.TopMargin = Unit.FromCentimeter(7.5); // Add header section.PageSetup.StartingNumber = 1; HeaderFooter header = section.Headers.Primary; Paragraph title = new Paragraph(); title.Format.Alignment = ParagraphAlignment.Center; title.Format.Font.Bold = true; title.Format.Font.Size = 32; title.AddText("CONSIGNMENT NOTE"); header.Add(title); Table tableHeader = new Table(); tableHeader.Borders.Width = 0.75; tableHeader.TopPadding = "1mm"; tableHeader.BottomPadding = "1mm"; tableHeader.AddColumn("7cm"); tableHeader.AddColumn("4.2cm"); tableHeader.AddColumn("2cm"); tableHeader.AddColumn("2.2cm"); tableHeader.AddColumn("3cm"); Row headerRow = tableHeader.AddRow(); tableHeader.AddRow(); tableHeader.AddRow(); tableHeader.AddRow(); tableHeader.AddRow(); tableHeader.AddRow(); tableHeader.AddRow(); headerRow.Cells[0].MergeDown = 6; headerRow.Cells[1].MergeRight = 1; headerRow.Cells[3].MergeRight = 1; tableHeader.Rows[1].Cells[1].MergeRight = 3; tableHeader.Rows[2].Cells[2].MergeRight = 2; tableHeader.Rows[3].Cells[2].MergeRight = 1; tableHeader.Rows[4].Cells[1].MergeRight = 3; tableHeader.Rows[5].Cells[1].MergeRight = 3; tableHeader.Rows[6].Cells[1].MergeRight = 3; //Paragraph logo = new Paragraph(); //logo.Format.Alignment = ParagraphAlignment.Left; //logo.AddImage(HttpContext.Current.Server.MapPath("~/Images/MyImage.png")).Width = "7cm"; //headerRow.Cells[0].Add(logo); Paragraph campus = headerRow.Cells[1].AddParagraph(); campus.AddFormattedText("Campus: ", TextFormat.Bold); campus.AddText(co.Campus); Paragraph locality = headerRow.Cells[3].AddParagraph(); locality.AddFormattedText("Locality: ", TextFormat.Bold); locality.AddText(co.Locality); Paragraph contactName = tableHeader.Rows[1].Cells[1].AddParagraph(); contactName.AddFormattedText("Contact Name: ", TextFormat.Bold); contactName.AddText(co.ContactName); Paragraph phone = tableHeader.Rows[2].Cells[1].AddParagraph(); phone.AddFormattedText("Phone: ", TextFormat.Bold); phone.AddText(""); Paragraph email = tableHeader.Rows[2].Cells[2].AddParagraph(); email.AddFormattedText("Email: ", TextFormat.Bold); email.AddText(co.Email); Paragraph dateSent = tableHeader.Rows[3].Cells[1].AddParagraph(); dateSent.AddFormattedText("Date sent: ", TextFormat.Bold); dateSent.AddText(co.DispatchDate.ToString("dd/MM/yyyy")); Paragraph returnBy = tableHeader.Rows[3].Cells[2].AddParagraph(); returnBy.AddFormattedText("Return by: ", TextFormat.Bold); returnBy.AddText(co.ReturnBy.ToString("dd/MM/yyyy")); Paragraph refNum = tableHeader.Rows[3].Cells[4].AddParagraph(); refNum.AddFormattedText("Ref: ", TextFormat.Bold); refNum.AddText(co.ID.ToString()); Paragraph deliveredTo = tableHeader.Rows[4].Cells[1].AddParagraph(); deliveredTo.AddFormattedText("Delivered to: ", TextFormat.Bold); deliveredTo.AddText(co.CompanyName ?? ""); tableHeader.Rows[5].Cells[1].AddParagraph().AddFormattedText("Unsold goods to be returned to Widgets Co", TextFormat.Bold); tableHeader.Rows[6].Cells[1].AddParagraph(@"Queries to [email protected] Unsold goods to be returned to Widgets Co Returns"); header.Add(tableHeader); // Add main body Table tableItems = new Table(); tableItems.Borders.Width = 0.75; tableItems.AddColumn("3cm"); tableItems.AddColumn("8cm"); tableItems.AddColumn("2.5cm"); tableItems.AddColumn("1.5cm"); tableItems.AddColumn("1.5cm"); tableItems.AddColumn("1.5cm"); tableItems.TopPadding = "3mm"; tableItems.BottomPadding = "3mm"; Row itemsHeader = tableItems.AddRow(); itemsHeader.Format.Alignment = ParagraphAlignment.Center; itemsHeader.Format.Font.Bold = true; itemsHeader[0].AddParagraph("CODE"); itemsHeader[1].AddParagraph("DESCRIPTION"); itemsHeader[2].AddParagraph("PRICE"); itemsHeader[3].AddParagraph("QTY"); itemsHeader[4].AddParagraph("???"); itemsHeader[5].AddParagraph("???"); // Add each item foreach (var item in co.ConsignmentItems) { Row itemRow = tableItems.AddRow(); itemRow[2].Format.Alignment = ParagraphAlignment.Right; itemRow[3].Format.Alignment = ParagraphAlignment.Center; itemRow[0].AddParagraph(item.StockCode ?? ""); itemRow[1].AddParagraph(item.Description ?? ""); itemRow[2].AddParagraph(item.UnitPrice.ToString("£#,##0.00")); itemRow[3].AddParagraph(item.Quantity.ToString()); } section.Add(tableItems); PdfDocumentRenderer renderer = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.Always); renderer.Document = document; renderer.RenderDocument(); MemoryStream ms = new MemoryStream(); renderer.PdfDocument.Save(ms); return(ms.ToArray()); }