コード例 #1
0
ファイル: Title.cs プロジェクト: JuanCruzReines/PDFBuilder
        /// <summary>
        /// Render a title into a section
        /// </summary>
        public override void RenderInto(MigraDoc.DocumentObjectModel.Section section)
        {
            MigraDoc.DocumentObjectModel.Paragraph title = new MigraDoc.DocumentObjectModel.Paragraph();

            title.Style = "Heading1";
            this.RenderTextInto(title);

            section.Add(title);
        }
コード例 #2
0
        /// <summary>
        /// Render a paragraph into a section
        /// </summary>
        public override void RenderInto(MigraDoc.DocumentObjectModel.Section section)
        {
            MigraDoc.DocumentObjectModel.Paragraph paragraph = this.Create();

            section.Add(paragraph);
        }
コード例 #3
0
        /// <summary>
        /// Render a image into a section
        /// </summary>
        public void RenderInto(MigraDoc.DocumentObjectModel.Section section)
        {
            MigraDoc.DocumentObjectModel.Shapes.Image image = this.CreateImage();

            section.Add(image);
        }
コード例 #4
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());
        }
コード例 #5
0
ファイル: MigraDocHelper.cs プロジェクト: nampn/ODental
 public static void DrawGrid(Section section,ODGrid grid)
 {
     //first, calculate width of dummy column that will push the grid over just enough to center it on the page.
     double pageW=0;
     if(CultureInfo.CurrentCulture.Name=="en-US") {
         pageW=850;
     }
     //don't know about Canada
     else {
         pageW=830;
     }
     //in 100ths/inch
     double widthAllColumns=(double)grid.WidthAllColumns/.96;
     double lmargin=section.Document.DefaultPageSetup.LeftMargin.Inch*100;
     double dummyColW=(pageW-widthAllColumns)/2-lmargin;
     Table table=new Table();
     Column col;
     col=table.AddColumn(Unit.FromInch(dummyColW/100));
     for(int i=0;i<grid.Columns.Count;i++){
         col=table.AddColumn(Unit.FromInch((double)grid.Columns[i].ColWidth/96));
         col.LeftPadding=Unit.FromInch(.01);
         col.RightPadding=Unit.FromInch(.01);
     }
     Row row;
     row=table.AddRow();
     row.HeadingFormat=true;
     row.TopPadding=Unit.FromInch(0);
     row.BottomPadding=Unit.FromInch(-.01);
     Cell cell;
     Paragraph par;
     //dummy column:
     cell=row.Cells[0];
     //cell.Shading.Color=Colors.LightGray;
     //format dummy cell?
     MigraDoc.DocumentObjectModel.Font fontHead=new MigraDoc.DocumentObjectModel.Font("Arial",Unit.FromPoint(8.5));
     fontHead.Bold=true;
     for(int i=0;i<grid.Columns.Count;i++){
         cell = row.Cells[i+1];
         par=cell.AddParagraph();
         par.AddFormattedText(grid.Columns[i].Heading,fontHead);
         par.Format.Alignment=ParagraphAlignment.Center;
         cell.Format.Alignment=ParagraphAlignment.Center;
         cell.Borders.Width=Unit.FromPoint(1);
         cell.Borders.Color=Colors.Black;
         cell.Shading.Color=Colors.LightGray;
     }
     MigraDoc.DocumentObjectModel.Font fontBody=null;//=new MigraDoc.DocumentObjectModel.Font("Arial",Unit.FromPoint(8.5));
     bool isBold;
     System.Drawing.Color color;
     int edgeRows=1;
     for(int i=0;i<grid.Rows.Count;i++,edgeRows++){
         row=table.AddRow();
         row.TopPadding=Unit.FromInch(.01);
         row.BottomPadding=Unit.FromInch(0);
         for(int j=0;j<grid.Columns.Count;j++){
             cell = row.Cells[j+1];
             par=cell.AddParagraph();
             if(grid.Rows[i].Cells[j].Bold==YN.Unknown){
                 isBold=grid.Rows[i].Bold;
             }
             else if(grid.Rows[i].Cells[j].Bold==YN.Yes){
                 isBold=true;
             }
             else{// if(grid.Rows[i].Cells[j].Bold==YN.No){
                 isBold=false;
             }
             if(grid.Rows[i].Cells[j].ColorText==System.Drawing.Color.Empty){
                 color=grid.Rows[i].ColorText;
             }
             else{
                 color=grid.Rows[i].Cells[j].ColorText;
             }
             fontBody=CreateFont(8.5f,isBold,color);
             par.AddFormattedText(grid.Rows[i].Cells[j].Text,fontBody);
             if(grid.Columns[j].TextAlign==HorizontalAlignment.Center){
                 cell.Format.Alignment=ParagraphAlignment.Center;
             }
             if(grid.Columns[j].TextAlign==HorizontalAlignment.Left) {
                 cell.Format.Alignment=ParagraphAlignment.Left;
             }
             if(grid.Columns[j].TextAlign==HorizontalAlignment.Right) {
                 cell.Format.Alignment=ParagraphAlignment.Right;
             }
             cell.Borders.Color=new MigraDoc.DocumentObjectModel.Color(180,180,180);
             if(grid.Rows[i].ColorLborder!=System.Drawing.Color.Empty){
                 cell.Borders.Bottom.Color=ConvertColor(grid.Rows[i].ColorLborder);
             }
         }
         if(grid.Rows[i].Note!=null && grid.Rows[i].Note!="" && grid.NoteSpanStop>0 && grid.NoteSpanStart<grid.Columns.Count){
             row=table.AddRow();
             row.TopPadding=Unit.FromInch(.01);
             row.BottomPadding=Unit.FromInch(0);
             cell=row.Cells[grid.NoteSpanStart+1];
             par=cell.AddParagraph();
           par.AddFormattedText(grid.Rows[i].Note,fontBody);
           cell.Format.Alignment=ParagraphAlignment.Left;
             cell.Borders.Color=new MigraDoc.DocumentObjectModel.Color(180,180,180);
             cell.MergeRight=grid.Columns.Count-1-grid.NoteSpanStart;
             edgeRows++;
         }
     }
     table.SetEdge(1,0,grid.Columns.Count,edgeRows,Edge.Box,MigraDoc.DocumentObjectModel.BorderStyle.Single,1,Colors.Black);
     section.Add(table);
 }