internal static void FillFormattedParagraph(Paragraph par)
 {
     for (int idx = 0; idx <= 140; ++idx)
     {
         if (idx < 60)
         {
             FormattedText formText = par.AddFormattedText((idx).ToString(), TextFormat.Bold);
             formText.Font.Size = 16;
             formText.AddText(" ");
         }
         else if (idx < 100)
         {
             par.AddText((idx).ToString());
             par.AddText(" ");
         }
         else
         {
             FormattedText formText = par.AddFormattedText((idx).ToString(), TextFormat.Italic);
             formText.Font.Size = 6;
             formText.AddText(" ");
         }
         if (idx % 50 == 0)
             par.AddLineBreak();
     }
     par.AddText(" ...ready.");
 }
Exemple #2
0
        public string pdfRapportoAgentePlus(string autore, string emailAutore, string periodoRiferimento, Single acconto, Single recupero, Single daRiportare, Single monete, Single carta, string targa, List <cCostanti.tOperazione> info)
        {
            cCostanti costanti = new cCostanti();
            string    testo = "";
            string    fileName, pathFileName;
            string    pageFooterText = "";

            DateTime  currentTime     = DateTime.Now;
            Document  document        = new Document();
            Table     table           = new MigraDoc.DocumentObjectModel.Tables.Table();
            Paragraph infoPremilinari = new MigraDoc.DocumentObjectModel.Paragraph();
            Column    colonna;

            FormattedText ftextTarga = new FormattedText();

            fileName     = ("pdf_" + emailAutore).Replace(" ", "").Replace(".", "_").Replace("@", "_") + ".pdf";
            pathFileName = HttpContext.Current.Server.MapPath(costanti.pathRemoto + "/" + fileName);

            Style style = document.Styles["Normal"];

            style.Font.Name = "Arial Unicode MS";
            style.Font.Size = 12;
            style.Font.Bold = false;


            //table Style
            style           = document.Styles.AddStyle("tabella", "Normal");
            style.Font.Name = "Verdana";
            style.Font.Size = 12;
            style.Font.Bold = false;

            style           = document.Styles.AddStyle("rigaBold", "Normal");
            style.Font.Name = "Verdana";
            style.Font.Size = 12;
            style.Font.Bold = true;

            style           = document.Styles.AddStyle("riga24", "Normal");
            style.Font.Name = "Verdana";
            style.Font.Size = 24;
            style.Font.Bold = true;

            style           = document.Styles.AddStyle("testoBold", "Normal");
            style.Font.Name = "Verdana";
            style.Font.Size = 12;
            style.Font.Bold = true;

            style            = document.Styles.AddStyle("testoRosso", "Normal");
            style.Font.Name  = "Verdana";
            style.Font.Size  = 14;
            style.Font.Bold  = true;
            style.Font.Color = Colors.OrangeRed;

            style            = document.Styles.AddStyle("testoBlu", "Normal");
            style.Font.Name  = "Verdana";
            style.Font.Size  = 14;
            style.Font.Bold  = true;
            style.Font.Color = Colors.DarkBlue;

            style            = document.Styles.AddStyle("testoLightBlu", "Normal");
            style.Font.Name  = "Verdana";
            style.Font.Size  = 12;
            style.Font.Bold  = false;
            style.Font.Color = Colors.DarkBlue;

            style            = document.Styles.AddStyle("testoNero", "Normal");
            style.Font.Name  = "Verdana";
            style.Font.Size  = 14;
            style.Font.Bold  = true;
            style.Font.Color = Colors.Black;

            style            = document.Styles.AddStyle("Titolo", "Normal");
            style.Font.Name  = "Verdana";
            style.Font.Size  = 16;
            style.Font.Bold  = true;
            style.Font.Color = Colors.Orange;

            Section page = document.AddSection();

            //header
            Paragraph header = page.Headers.Primary.AddParagraph();

            header.AddText("Money BOX");
            header.Format.Alignment = ParagraphAlignment.Left;
            header.Style            = "Titolo";
            testo  = string.Format("{0}, {1}, targa: ", autore, emailAutore);
            header = page.Headers.Primary.AddParagraph();
            header.AddText(testo);
            ftextTarga.AddText(targa.ToUpper());
            ftextTarga.Color = Colors.Red;
            header.Add(ftextTarga);
            header.AddText("\n");
            header.Format.Alignment = ParagraphAlignment.Left;

            //footer
            pageFooterText = string.Format(" report del {0} ", currentTime.ToShortDateString()) + "\n";
            Paragraph footer = page.Footers.Primary.AddParagraph();

            footer.AddText(pageFooterText);
            footer.Format.Alignment = ParagraphAlignment.Center;

            table.Style               = "tabella";
            table.Borders.Color       = Colors.Black;
            table.Borders.Width       = 0.25;
            table.Borders.Left.Width  = 0.5;
            table.Borders.Right.Width = 0.5;
            table.Rows.LeftIndent     = 0;

            colonna = table.AddColumn("6cm");
            colonna.Format.Alignment = ParagraphAlignment.Left;
            colonna = table.AddColumn("3.5cm");
            colonna.Format.Alignment = ParagraphAlignment.Left;
            colonna = table.AddColumn("3.5cm");
            colonna.Format.Alignment = ParagraphAlignment.Left;
            colonna = table.AddColumn("3.5cm");
            colonna.Format.Alignment = ParagraphAlignment.Left;

            infoPremilinari.AddText("\nPeriodo di riferimento: ");
            infoPremilinari.AddFormattedText(periodoRiferimento, TextFormat.Bold);
            infoPremilinari.AddText("\n\n");


            page.Add(infoPremilinari);
            Row riga = table.AddRow();

            riga.Style = "rigaBold";
            riga.Cells[0].AddParagraph("Locale");
            riga.Cells[1].AddParagraph("acconto");
            riga.Cells[2].AddParagraph("recupero \n da riportare");
            riga.Cells[3].AddParagraph("da Riportare");
            riga.Cells[0].Format.Alignment = ParagraphAlignment.Left;
            riga.Cells[1].Format.Alignment = ParagraphAlignment.Right;
            riga.Cells[2].Format.Alignment = ParagraphAlignment.Right;
            riga.Cells[3].Format.Alignment = ParagraphAlignment.Right;

            foreach (var value in info)
            {
                riga = table.AddRow();
                int position = value.data.IndexOf(" ");

                if (value.acconto == 0 && value.recupero == 0 && value.daRiportare == 0)
                {
                    riga.Cells[0].AddParagraph(value.nomeLocale + "\n" + value.data.Substring(0, position));
                    riga.Cells[0].Style = "testoLightBlu";
                    riga.Cells[1].AddParagraph("*** OPERAZIONE GENERICA ***");
                    riga.Cells[1].Format.Alignment = ParagraphAlignment.Left;
                    riga.Cells[1].MergeRight       = 2;
                }
                else
                {
                    riga.Cells[0].AddParagraph(value.nomeLocale + "\n" + value.data.Substring(0, position));
                    if (value.acconto == 0)
                    {
                        riga.Cells[1].AddParagraph("");
                    }
                    else
                    {
                        riga.Cells[1].AddParagraph(String.Format("{0:0,0.00}", value.acconto));
                    }

                    if (value.recupero == 0)
                    {
                        riga.Cells[2].AddParagraph("");
                    }
                    else
                    {
                        riga.Cells[2].AddParagraph(String.Format("{0:0,0.00}", value.recupero));
                    }
                    if (value.daRiportare == 0)
                    {
                        riga.Cells[3].AddParagraph("");
                    }
                    else
                    {
                        riga.Cells[3].AddParagraph(String.Format("{0:0,0.00}", value.daRiportare));
                    }
                    riga.Cells[0].Format.Alignment = ParagraphAlignment.Left;
                    riga.Cells[1].Format.Alignment = ParagraphAlignment.Right;
                    riga.Cells[2].Format.Alignment = ParagraphAlignment.Right;
                    riga.Cells[3].Format.Alignment = ParagraphAlignment.Right;
                }
            }

            riga       = table.AddRow();
            riga.Style = "rigaBold";
            riga.Cells[0].AddParagraph("\nFlusso acconti\n\n");
            riga.Cells[1].AddParagraph("\n" + String.Format("{0:0,0.00}", acconto));
            riga.Cells[2].AddParagraph("");
            riga.Cells[2].MergeRight       = 1;
            riga.Cells[0].Format.Alignment = ParagraphAlignment.Left;
            riga.Cells[1].Format.Alignment = ParagraphAlignment.Right;
            riga.Cells[2].Format.Alignment = ParagraphAlignment.Right;
            riga.Cells[0].Style            = "testoNero";
            riga.Cells[1].Style            = "testoBlu";

            riga       = table.AddRow();
            riga.Style = "rigaBold";
            riga.Cells[0].AddParagraph("Flusso di cassa");
            riga.Cells[0].MergeRight = 1;
            riga.Cells[2].AddParagraph(String.Format("{0:0,0.00}", recupero));
            riga.Cells[3].AddParagraph(String.Format("{0:0,0.00}", daRiportare));
            riga.Cells[0].Format.Alignment = ParagraphAlignment.Left;
            riga.Cells[2].Format.Alignment = ParagraphAlignment.Right;
            riga.Cells[3].Format.Alignment = ParagraphAlignment.Right;


            riga       = table.AddRow();
            riga.Style = "rigaBold";
            riga.Cells[0].AddParagraph("Monete");
            riga.Cells[0].MergeRight = 1;
            riga.Cells[2].AddParagraph(String.Format("{0:0,0.00}", monete));
            riga.Cells[0].Format.Alignment = ParagraphAlignment.Right;
            riga.Cells[2].Format.Alignment = ParagraphAlignment.Right;
            riga.Cells[3].MergeDown        = 3;

            riga       = table.AddRow();
            riga.Style = "rigaBold";
            riga.Cells[0].AddParagraph("Carta");
            riga.Cells[0].MergeRight = 1;
            riga.Cells[2].AddParagraph(String.Format("{0:0,0.00}", carta));
            riga.Cells[0].Format.Alignment = ParagraphAlignment.Right;
            riga.Cells[2].Format.Alignment = ParagraphAlignment.Right;

            riga       = table.AddRow();
            riga.Style = "rigaBold";
            riga.Cells[0].AddParagraph("Tot. cassa");
            riga.Cells[0].MergeRight = 1;
            riga.Cells[2].AddParagraph(String.Format("{0:0,0.00}", monete + carta + recupero));
            riga.Cells[0].Format.Alignment = ParagraphAlignment.Right;
            riga.Cells[2].Format.Alignment = ParagraphAlignment.Right;
            riga.Cells[0].Style            = "testoNero";
            riga.Cells[2].Style            = "testoNero";

            riga       = table.AddRow();
            riga.Style = "rigaBold";
            riga.Cells[0].AddParagraph("\nFlusso di cassa\n\n");
            riga.Cells[0].MergeRight = 1;
            riga.Cells[2].AddParagraph("\n" + String.Format("{0:0,0.00}", monete + carta + recupero - daRiportare));
            riga.Cells[3].AddParagraph("\n");
            riga.Cells[0].Format.Alignment = ParagraphAlignment.Right;
            riga.Cells[2].Format.Alignment = ParagraphAlignment.Right;
            riga.Cells[3].Format.Alignment = ParagraphAlignment.Right;
            riga.Cells[0].Style            = "testoNero";
            riga.Cells[2].Style            = "testoRosso";

            riga       = table.AddRow();
            riga.Style = "rigaBold";
            riga.Cells[0].AddParagraph("\nCassa Generale\n\n");
            riga.Cells[0].MergeRight = 1;
            riga.Cells[2].AddParagraph("\n" + String.Format("{0:0,0.00}", acconto + monete + carta + recupero - daRiportare));
            riga.Cells[3].AddParagraph("\n");
            riga.Cells[0].Format.Alignment = ParagraphAlignment.Right;
            riga.Cells[2].Format.Alignment = ParagraphAlignment.Right;
            riga.Cells[3].Format.Alignment = ParagraphAlignment.Right;
            riga.Cells[0].Style            = "testoNero";
            riga.Cells[2].Style            = "testoNero";

            page.Add(table);

            PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(true);

            pdfRenderer.Document = document;
            pdfRenderer.RenderDocument();
            pdfRenderer.PdfDocument.Save(pathFileName);

            //Process.Start(fileName);
            return(fileName);
        }
 /// <summary>
 /// Adds the text to an existing paragraph setting format to bold and italic
 /// </summary>
 public void AddTo(MigraDoc.DocumentObjectModel.Paragraph paragrapgh)
 {
     paragrapgh.AddFormattedText(this.text, TextFormat.Bold | TextFormat.Italic);
 }
        /// <summary>
        /// Writes the figure text.
        /// </summary>
        /// <param name="f">The f.</param>
        /// <param name="pa">The paragraph.</param>
        protected void WriteEndFigure(Figure f, Paragraph pa)
        {
            if (f.FigureText == null)
            {
                return;
            }

            pa.AddLineBreak();
            pa.AddFormattedText(f.GetFullCaption(this.style), "FigureText");
        }
Exemple #5
0
        public IActionResult OnGet(string pdf)
        {
            //get the session first!
            UserName  = HttpContext.Session.GetString(SessionKeyName1);
            FirstName = HttpContext.Session.GetString(SessionKeyName2);
            SessionID = HttpContext.Session.GetString(SessionKeyName3);


            DatabaseConnect dbstring     = new DatabaseConnect();     //creating an object from the class
            string          DbConnection = dbstring.DatabaseString(); //calling the method from the class

            Console.WriteLine(DbConnection);
            SqlConnection conn = new SqlConnection(DbConnection);

            conn.Open();

            using (SqlCommand command = new SqlCommand())
            {
                command.Connection  = conn;
                command.CommandText = @"SELECT EmployeeID,
                                        EmpFName + ' ' + EmpLName AS EmployeeName,
                                        EmpDoB AS EmployeeBornOn,
                                        EmpHireDate AS EmployedOn
                                        FROM EmployeesTable;";

                var reader = command.ExecuteReader();

                Employee = new List <Employee>();
                while (reader.Read())
                {
                    Employee Row = new Employee(); //each record found from the table
                    Row.EmployeeId        = reader.GetInt32(0);
                    Row.EmployeeFirstName = reader.GetString(1);
                    Row.EmployeeDoB       = reader.GetDateTime(2);
                    Row.EmployeeDateHired = reader.GetDateTime(3);
                    Employee.Add(Row);
                }
            }


            //PDF code here!
            if (pdf == "1")
            {
                //Create an object for pdf document
                Document  doc  = new Document();
                Section   sec  = doc.AddSection();
                Paragraph para = sec.AddParagraph();

                para.Format.Font.Name  = "Arial";
                para.Format.Font.Size  = 14;
                para.Format.Font.Color = Color.FromCmyk(0, 0, 0, 100); //black colour
                para.AddFormattedText("List of Employees", TextFormat.Bold);
                para.Format.SpaceAfter = "1.0cm";

                para.AddFormattedText();

                //Table
                Table tab = new Table();
                tab.Borders.Width = 0.75;
                tab.TopPadding    = 5;
                tab.BottomPadding = 5;

                //Column
                Column col = tab.AddColumn(Unit.FromCentimeter(3));
                col.Format.Alignment = ParagraphAlignment.Center;
                tab.AddColumn(Unit.FromCentimeter(3));
                tab.AddColumn(Unit.FromCentimeter(3));
                tab.AddColumn(Unit.FromCentimeter(3));
                //tab.AddColumn(Unit.FromCentimeter(3));


                //Row
                Row row = tab.AddRow();
                row.Shading.Color = Colors.Coral;//select your preference colour!

                //Cell for header
                Cell cell = new Cell();
                cell = row.Cells[0];
                cell.AddParagraph("EmployeeID");
                cell = row.Cells[1];
                cell.AddParagraph("Employee First Name");
                cell = row.Cells[2];
                cell.AddParagraph("Employee Date of Birth");
                cell = row.Cells[3];
                cell.AddParagraph("Employee Hire Date");

                //Add data to table
                for (int i = 0; i < Employee.Count; i++)
                {
                    row  = tab.AddRow();
                    cell = row.Cells[0];
                    cell.AddParagraph(Convert.ToString(i + 1));
                    cell = row.Cells[1];
                    cell.AddParagraph(Employee[i].EmployeeFirstName);
                    cell = row.Cells[2];
                    cell.AddParagraph(Convert.ToString(Employee[i].EmployeeDateHired));
                    cell = row.Cells[3];
                    cell.AddParagraph(Convert.ToString(Employee[i].EmployeeDoB));
                }

                tab.SetEdge(0, 0, 4, (Employee.Count + 1), Edge.Box, BorderStyle.Single, 1.5, Colors.Black);
                sec.Add(tab);

                //Rendering
                PdfDocumentRenderer pdfRen = new PdfDocumentRenderer();
                pdfRen.Document = doc;
                pdfRen.RenderDocument();

                //Create a memory stream
                MemoryStream stream = new MemoryStream();
                pdfRen.PdfDocument.Save(stream); //saving the file into the stream

                Response.Headers.Add("content-disposition", new[] { "inline; filename = ListofEmployees.pdf" });
                return(File(stream, "application/pdf"));
            }
            return(Page());
        }
 /// <summary>
 /// The write end figure.
 /// </summary>
 /// <param name="f">
 /// The f.
 /// </param>
 /// <param name="pa">
 /// The pa.
 /// </param>
 public void WriteEndFigure(Figure f, Paragraph pa)
 {
     pa.AddLineBreak();
     pa.AddFormattedText(f.GetFullCaption(this.style), "FigureText");
 }
Exemple #7
0
 /// <summary>
 /// The write end figure.
 /// </summary>
 /// <param name="f">
 /// The f.
 /// </param>
 /// <param name="pa">
 /// The pa.
 /// </param>
 public void WriteEndFigure(Figure f, Paragraph pa)
 {
     pa.AddLineBreak();
     pa.AddFormattedText(f.GetFullCaption(this.style), "FigureText");
 }
        private void addServiceToWaterMark(Paragraph lineOne, string serviceText, Boolean includeSeparator)
        {
            MigraDoc.DocumentObjectModel.FormattedText serviceFormatted = lineOne.AddFormattedText(serviceText);
            serviceFormatted.Font.Size = 11;
            serviceFormatted.Font.Name = "Impact";
            serviceFormatted.Font.Bold = true;
            serviceFormatted.Color = mttPurple;

            if (includeSeparator)
            {
                MigraDoc.DocumentObjectModel.FormattedText lineSeparator = lineOne.AddFormattedText(" | ");
                lineSeparator.Font.Size = 10;
                lineSeparator.Color = separatorGrey;
            }
        }
Exemple #9
0
        private void CreatePage()
        {
            // Each MigraDoc document needs at least one section.
            MigraDoc.DocumentObjectModel.Section section = this.document.AddSection();

            // Put a logo in the header
            Image image = section.Headers.Primary.AddImage("Image_Icons/logo1.png");

            image.Height             = "2.5cm";
            image.Width              = "5cm";
            image.LockAspectRatio    = true;
            image.RelativeVertical   = RelativeVertical.Line;
            image.RelativeHorizontal = RelativeHorizontal.Margin;
            image.Top              = ShapePosition.Top;
            image.Left             = ShapePosition.Right;
            image.WrapFormat.Style = WrapStyle.Through;

            // Create the text frame for the address
            this.addressFrame                    = section.AddTextFrame();
            this.addressFrame.Height             = "8.0cm";
            this.addressFrame.Width              = "10.0cm";
            this.addressFrame.Left               = ShapePosition.Left;
            this.addressFrame.RelativeHorizontal = RelativeHorizontal.Margin;
            this.addressFrame.Top                = "4cm";
            this.addressFrame.RelativeVertical   = RelativeVertical.Page;

            this.PriceFrame                    = section.AddTextFrame();
            this.PriceFrame.Height             = "5.0cm";
            this.PriceFrame.Width              = "5.0cm";
            this.PriceFrame.Left               = ShapePosition.Right;
            this.PriceFrame.RelativeHorizontal = RelativeHorizontal.Margin;
            this.PriceFrame.Top                = "4.0cm";
            this.PriceFrame.RelativeVertical   = RelativeVertical.Page;

            // Put sender in address frame
            //= addressFrame.AddParagraph("ul.Pralki 5, 13-342 Lodówka");
            //paragraph.Format.Font.Name = "Times New Roman";
            //paragraph.Format.Font.Size = 7;
            //paragraph.Format.SpaceAfter = 3;

            // Add the print date field
            MigraDoc.DocumentObjectModel.Paragraph paragraph = section.AddParagraph();
            paragraph.Format.SpaceBefore = "8cm";
            paragraph.Style = "Reference";
            paragraph.AddFormattedText($"Faktura nr {order.Date.Year}/{order.Id}", TextFormat.Bold);
            paragraph.AddTab();
            paragraph.AddText("Białystok, ");
            paragraph.AddDateField("dd.MM.yyyy");

            paragraph = section.Footers.Primary.AddParagraph();
            paragraph.AddText($"\u00a9 2021 RTV&AGD \n ul.Pralki 5, 13-342 Lodówka \n Data wydruku: {DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss")} ");
            paragraph.Format.Font.Size = 9;
            paragraph.Format.Alignment = ParagraphAlignment.Center;

            // Create the item table
            this.table                = section.AddTable();
            table.Format.Alignment    = ParagraphAlignment.Justify;
            table.Borders.Color       = MigraDoc.DocumentObjectModel.Colors.Black;
            table.Borders.Width       = 0.25;
            table.Borders.Left.Width  = 0.5;
            table.Borders.Right.Width = 0.5;
            table.Rows.LeftIndent     = 5;
            table.TopPadding          = 10;
            table.BottomPadding       = 10;

            // Before you can add a row, you must define the columns
            Column column = this.table.AddColumn("7.5cm");

            column.Format.Alignment = ParagraphAlignment.Center;

            column = this.table.AddColumn("1.5cm");
            column.Format.Alignment = ParagraphAlignment.Right;

            column = this.table.AddColumn("3.5cm");
            column.Format.Alignment = ParagraphAlignment.Right;

            column = this.table.AddColumn("3.5cm");
            column.Format.Alignment = ParagraphAlignment.Right;


            // Create the header of the table
            Row row = table.AddRow();

            row.HeadingFormat    = true;
            row.Format.Alignment = ParagraphAlignment.Left;
            row.Format.Font.Bold = true;
            row.Shading.Color    = TableBlue;
            row.Cells[0].AddParagraph("Nazwa");
            row.Cells[0].Format.Font.Bold  = true;
            row.Cells[0].Format.Alignment  = ParagraphAlignment.Left;
            row.Cells[0].VerticalAlignment = MigraDoc.DocumentObjectModel.Tables.VerticalAlignment.Center;

            row.Cells[1].AddParagraph("Ilość");
            row.Cells[1].Format.Alignment = ParagraphAlignment.Left;

            row.Cells[2].AddParagraph("Cena/szt");
            row.Cells[2].Format.Alignment  = ParagraphAlignment.Left;
            row.Cells[2].VerticalAlignment = MigraDoc.DocumentObjectModel.Tables.VerticalAlignment.Center;

            row.Cells[3].AddParagraph("Wartosc");
            row.Cells[3].Format.Alignment  = ParagraphAlignment.Left;
            row.Cells[3].VerticalAlignment = MigraDoc.DocumentObjectModel.Tables.VerticalAlignment.Center;



            this.table.SetEdge(0, 0, 4, 1, Edge.Box, BorderStyle.Single, 0.75, MigraDoc.DocumentObjectModel.Color.Empty);
        }
Exemple #10
0
        public void VisitRun(Run element)
        {
            var runText = element.InnerText;

            _pdfText = _pdfParagraph.AddFormattedText(GetTextFragment(runText));
        }
Exemple #11
0
        public void CreateCharacterCertificatePDF(string[] CertificateData, string admNo, int admYear)
        {
            if (CertificateData.Length != 5)
            {
                return;
            }
            else
            {
                // Generate nmhs-nexap directory in my document folder
                string containerfolder  = this.GenerateDocumentBaseDirectory();
                MigraModel.Document doc = new MigraModel.Document();
                MigraModel.Section  sec = doc.AddSection();
                sec.PageSetup           = doc.DefaultPageSetup.Clone();
                sec.PageSetup.TopMargin = ".7cm";

                MigraDoc.DocumentObjectModel.Shapes.TextFrame tframe = sec.AddTextFrame();
                tframe.AddImage("nmhs-logo.jpg");
                tframe.Left               = "-.5cm";
                tframe.Top                = "0.7cm";
                tframe.RelativeVertical   = MigraModel.Shapes.RelativeVertical.Page;
                tframe.RelativeHorizontal = MigraModel.Shapes.RelativeHorizontal.Margin;

                MigraModel.Paragraph paraSchoolName = sec.AddParagraph();
                paraSchoolName.Format.Font.Name  = "Times New Roman";
                paraSchoolName.Format.Alignment  = MigraModel.ParagraphAlignment.Center;
                paraSchoolName.Format.Font.Size  = 25;
                paraSchoolName.Format.Font.Color = MigraDoc.DocumentObjectModel.Colors.DarkBlue;
                string schoolName = "NAIMOUZA HIGH SCHOOL";
                paraSchoolName.AddFormattedText(schoolName, MigraModel.TextFormat.Bold);

                MigraModel.Paragraph paraSchoolAddress = sec.AddParagraph();
                paraSchoolAddress.Format.Font.Size = 14;
                paraSchoolAddress.Format.Alignment = MigraModel.ParagraphAlignment.Center;
                string addrs = "Vill. & P.O. Sujapur, Dist. Malda, 732206";
                paraSchoolAddress.AddText(addrs);

                MigraModel.Paragraph paraSchoolMeta = sec.AddParagraph();
                paraSchoolMeta.Format.Font.Size = 10;
                paraSchoolMeta.Format.Alignment = MigraModel.ParagraphAlignment.Center;
                string meta = "INDEX NO. - R1-110, CONTACT NO. - 03512-246525";
                paraSchoolMeta.AddFormattedText(meta, MigraModel.TextFormat.NotBold);

                MigraModel.Paragraph paraAdmissionMeta = sec.AddParagraph();
                paraAdmissionMeta.Format.Font.Size = 10;
                paraAdmissionMeta.Format.Alignment = MigraModel.ParagraphAlignment.Right;
                string admYr = (admYear != 0) ? admYear.ToString() : "0000";
                string ameta = "Admission Sl. " + admNo + " of " + admYr;
                paraAdmissionMeta.AddFormattedText(ameta, MigraModel.TextFormat.Bold);

                MigraModel.Paragraph paraCertificateType = sec.AddParagraph();
                paraCertificateType.Format.Font.Size = 18;
                paraCertificateType.Format.Alignment = MigraModel.ParagraphAlignment.Center;
                paraCertificateType.AddLineBreak();
                string ctype = "CHARACTER CERTIFICATE";
                paraCertificateType.AddFormattedText(ctype, MigraModel.TextFormat.NotBold);

                MigraModel.Paragraph para_a = sec.AddParagraph();
                para_a.Format.Font.Name  = "Lucida Handwriting";
                para_a.Format.Font.Size  = 16;
                para_a.Format.Font.Color = MigraModel.Colors.DarkBlue;
                para_a.Format.Alignment  = MigraModel.ParagraphAlignment.Justify;
                para_a.AddLineBreak();
                para_a.AddLineBreak();
                para_a.AddLineBreak();
                para_a.AddLineBreak();
                para_a.AddTab();

                string para_aText, para_aTextb, paraTextc, paraTextd, stdName;
                para_aText  = CertificateData[0].Trim();
                para_aTextb = CertificateData[1].Trim();
                paraTextc   = CertificateData[2].Trim();
                paraTextd   = CertificateData[3].Trim();
                stdName     = CertificateData[4].Trim();

                para_a.AddText(para_aText);

                MigraModel.Paragraph para_b = sec.AddParagraph();
                para_b.Format.Font.Name  = "Lucida Handwriting";
                para_b.Format.Font.Size  = 16;
                para_b.Format.Font.Color = MigraModel.Colors.DarkBlue;
                para_b.Format.Alignment  = MigraModel.ParagraphAlignment.Justify;
                para_b.AddLineBreak();
                para_b.AddTab();
                para_b.AddText(para_aTextb);

                MigraModel.Paragraph para_c = sec.AddParagraph();
                para_c.Format.Font.Name  = "Lucida Handwriting";
                para_c.Format.Font.Size  = 16;
                para_c.Format.Font.Color = MigraModel.Colors.DarkBlue;
                para_c.Format.Alignment  = MigraModel.ParagraphAlignment.Justify;
                para_c.AddLineBreak();
                para_c.AddTab();
                para_c.AddText(paraTextc);

                MigraModel.Paragraph para_d = sec.AddParagraph();
                para_d.Format.Font.Name  = "Lucida Handwriting";
                para_d.Format.Font.Size  = 16;
                para_d.Format.Font.Color = MigraModel.Colors.DarkBlue;
                para_d.Format.Alignment  = MigraModel.ParagraphAlignment.Justify;
                para_d.AddLineBreak();
                para_d.AddTab();
                para_d.AddText(paraTextd);


                MigraDoc.DocumentObjectModel.Shapes.TextFrame tframeHMaster = sec.AddTextFrame();
                MigraModel.Paragraph paraHMaster = tframeHMaster.AddParagraph();
                paraHMaster.Format.Font.Size = "14";
                paraHMaster.Format.Alignment = MigraModel.ParagraphAlignment.Center;
                string txt1 = "Headmaster";
                string txt2 = "Naimuza High School";
                string txt3 = "Sujapur, Malda";
                paraHMaster.AddText(txt1);
                paraHMaster.AddLineBreak();
                paraHMaster.AddText(txt2);
                paraHMaster.AddLineBreak();
                paraHMaster.AddText(txt3);
                tframeHMaster.Width              = "6cm";
                tframeHMaster.Left               = "10cm";
                tframeHMaster.Top                = "19cm";
                tframeHMaster.RelativeVertical   = MigraModel.Shapes.RelativeVertical.Page;
                tframeHMaster.RelativeHorizontal = MigraModel.Shapes.RelativeHorizontal.Margin;

                MigraDoc.Rendering.PdfDocumentRenderer docRend = new MigraDoc.Rendering.PdfDocumentRenderer(false);
                docRend.Document = doc;
                try
                {
                    docRend.RenderDocument();
                }
                catch (Exception e)
                {
                    System.Windows.MessageBox.Show(e.Message);
                    return;
                }
                string fname      = "CHR_" + stdName + DateTime.Now.ToString("yyyy-MM-dd HHmmss") + ".pdf";
                string pathString = Path.Combine(containerfolder, fname);
                docRend.PdfDocument.Save(pathString);

                System.Diagnostics.ProcessStartInfo processInfo = new System.Diagnostics.ProcessStartInfo();
                processInfo.FileName = pathString;
                System.Diagnostics.Process.Start(processInfo);
            }
        }
Exemple #12
0
        /// <summary>
        /// Creates the static parts of the invoice.
        /// </summary>
        void CreatePage()
        {
            // Each MigraDoc document needs at least one section.
            Section section = this.document.AddSection();

            // Put a logo in the header
            Image image = section.AddImage(path);

            image.Top              = ShapePosition.Top;
            image.Left             = ShapePosition.Left;
            image.WrapFormat.Style = WrapStyle.Through;

            // Create footer
            Paragraph paragraph = section.Footers.Primary.AddParagraph();

            paragraph.AddText("Health And Social Services.");
            paragraph.Format.Font.Size = 9;
            paragraph.Format.Alignment = ParagraphAlignment.Center;

            // Create the text frame for the address
            this.addressFrame                    = section.AddTextFrame();
            this.addressFrame.Height             = "3.0cm";
            this.addressFrame.Width              = "7.0cm";
            this.addressFrame.Left               = ShapePosition.Left;
            this.addressFrame.RelativeHorizontal = RelativeHorizontal.Margin;
            this.addressFrame.Top                = "5.0cm";
            this.addressFrame.RelativeVertical   = RelativeVertical.Page;

            // Put sender in address frame
            paragraph = this.addressFrame.AddParagraph("Karachi,Pakistan");
            paragraph.Format.Font.Name  = "Times New Roman";
            paragraph.Format.Font.Size  = 7;
            paragraph.Format.SpaceAfter = 3;

            // Add the print date field
            paragraph = section.AddParagraph();
            paragraph.Format.SpaceBefore = "6cm";
            paragraph.Style = "Reference";
            paragraph.AddFormattedText("Patients Detail", TextFormat.Bold);
            paragraph.AddTab();
            paragraph.AddText("Date, ");
            paragraph.AddDateField("dd.MM.yyyy");

            // Create the item table
            this.table                     = section.AddTable();
            this.table.Style               = "Table";
            this.table.Borders.Color       = TableBorder;
            this.table.Borders.Width       = 0.25;
            this.table.Borders.Left.Width  = 0.5;
            this.table.Borders.Right.Width = 0.5;
            this.table.Rows.LeftIndent     = 0;



            // Before you can add a row, you must define the columns
            Column column;

            foreach (DataColumn col in dt.Columns)
            {
                column = this.table.AddColumn(Unit.FromCentimeter(3));
                column.Format.Alignment = ParagraphAlignment.Center;
            }

            // Create the header of the table
            Row row = table.AddRow();

            row.HeadingFormat    = true;
            row.Format.Alignment = ParagraphAlignment.Center;
            row.Format.Font.Bold = true;
            row.Shading.Color    = TableBlue;


            for (int i = 0; i < dt.Columns.Count; i++)
            {
                row.Cells[i].AddParagraph(dt.Columns[i].ColumnName);
                row.Cells[i].Format.Font.Bold  = false;
                row.Cells[i].Format.Alignment  = ParagraphAlignment.Left;
                row.Cells[i].VerticalAlignment = VerticalAlignment.Bottom;
            }

            this.table.SetEdge(0, 0, dt.Columns.Count, 1, Edge.Box, BorderStyle.Single, 0.75, Color.Empty);
        }