Пример #1
0
 public void VisitTableRow(TableRow element)
 {
     _pdfRow = _pdfTable.AddRow();
     if (TableRowsToDataProviders.TryGetValue(element, out var tableRowValueProvider))
     {
         tableRowValueProvider.MoveNext();
     }
 }
Пример #2
0
        private void FillTable(MigraDoc.DocumentObjectModel.Tables.Table table, int start, int count)
        {
            foreach (double[] rowData in Values.GetRange(start, count))
            {
                MigraDoc.DocumentObjectModel.Tables.Row row = table.AddRow();
                row.Format.Alignment = MigraDoc.DocumentObjectModel.ParagraphAlignment.Center;

                int j = 0;
                foreach (double value in rowData)
                {
                    if (j > 5)
                    {
                        row.Cells[j++].AddParagraph(String.Format("{0:0.0000000}", value));
                    }
                    else
                    {
                        row.Cells[j++].AddParagraph(value.ToString());
                    }
                }
            }
        }
Пример #3
0
        private void CreateTable(MigraDoc.DocumentObjectModel.Tables.Table table)
        {
            table.Columns.Clear();
            table.Rows.Clear();

            table.Borders.Color = MigraDoc.DocumentObjectModel.Colors.Black;
            table.Borders.Width = 0.5;

            MigraDoc.DocumentObjectModel.Tables.Column column;
            column = table.AddColumn("1cm");

            for (int i = 0; i < 5; i++)
            {
                column = table.AddColumn("1.3cm");
                column.Format.Alignment = MigraDoc.DocumentObjectModel.ParagraphAlignment.Center;
            }

            for (int i = 0; i < 4; i++)
            {
                column = table.AddColumn("2.2cm");
                column.Format.Alignment = MigraDoc.DocumentObjectModel.ParagraphAlignment.Center;
            }

            MigraDoc.DocumentObjectModel.Tables.Row row = table.AddRow();
            row.Format.Font.Bold   = true;
            row.Format.SpaceBefore = "0.1cm";
            row.Format.SpaceAfter  = "0.1cm";
            row.Format.Alignment   = MigraDoc.DocumentObjectModel.ParagraphAlignment.Center;

            row.Cells[0].AddParagraph("№");
            row.Cells[1].AddParagraph("τ, мин.");
            row.Cells[2].AddParagraph("t1, °C");
            row.Cells[3].AddParagraph("φ1, %");
            row.Cells[4].AddParagraph("t2, °C");
            row.Cells[5].AddParagraph("φ2, %");
            row.Cells[6].AddParagraph("W");
            row.Cells[7].AddParagraph("u");
            row.Cells[8].AddParagraph("N");
            row.Cells[9].AddParagraph("βv");
        }
Пример #4
0
        public void CreateHead(string T0, double u, string H, string ms, string mv, string V)
        {
            MigraDoc.DocumentObjectModel.Tables.Table head = FirstSection.AddTable();

            head.Columns.Clear();
            head.Rows.Clear();

            head.Borders.Color = MigraDoc.DocumentObjectModel.Colors.Black;
            head.Borders.Width = 0.5;

            head.AddColumn("2.5cm");
            head.AddColumn("2.5cm");
            head.AddColumn("11.3cm");

            MigraDoc.DocumentObjectModel.Tables.Row row = head.AddRow();
            row.Cells[0].AddParagraph(string.Format("{0}°C | u = {1:0.00} | H = {2}", T0, u, H));
            row.Cells[0].MergeRight = 2;
            row.Format.Alignment    = MigraDoc.DocumentObjectModel.ParagraphAlignment.Center;
            row.Format.Font.Bold    = true;

            row = head.AddRow();
            row.Cells[0].AddParagraph("m1, гр");
            row.Cells[1].AddParagraph(ms);
            row.Cells[2].AddParagraph("Масса сухого материала");

            row = head.AddRow();
            row.Cells[0].AddParagraph("m2, гр");
            row.Cells[1].AddParagraph(mv);
            row.Cells[2].AddParagraph("Масса влажного материала");

            row = head.AddRow();
            row.Cells[0].AddParagraph("H, мм");
            row.Cells[1].AddParagraph(H);
            row.Cells[2].AddParagraph("Высота слоя");

            row = head.AddRow();
            row.Cells[0].AddParagraph("Расход, м³/ч");
            row.Cells[1].AddParagraph(V);
            row.Cells[2].AddParagraph("Объёмный расход воздуха");
        }
Пример #5
0
        protected void CreatePage(IList <Student> students)
        {
            Section section = this.document.AddSection();

            this.table                     = section.AddTable();
            this.table.Style               = "Table";
            this.table.Borders.Color       = Colors.Black;
            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;

            MigraDoc.DocumentObjectModel.Tables.Column column = this.table.AddColumn("4cm"); //first name, father initial, last name
            column.Format.Alignment = ParagraphAlignment.Center;

            column = this.table.AddColumn("3cm");//specialization
            column.Format.Alignment = ParagraphAlignment.Left;

            column = this.table.AddColumn("2cm"); //final grade
            column.Format.Alignment = ParagraphAlignment.Left;

            column = this.table.AddColumn("2cm"); //addmision grade
            column.Format.Alignment = ParagraphAlignment.Left;

            column = this.table.AddColumn("2cm"); //baccalaureat average grade
            column.Format.Alignment = ParagraphAlignment.Left;

            column = this.table.AddColumn("2cm"); //baccalaureat maximum grade
            column.Format.Alignment = ParagraphAlignment.Left;

            column = this.table.AddColumn("3cm"); //status
            column.Format.Alignment = ParagraphAlignment.Left;

            MigraDoc.DocumentObjectModel.Tables.Row row = this.table.AddRow();
            row.HeadingFormat          = true;
            row.Format.Alignment       = ParagraphAlignment.Center;
            row.Format.Font.Bold       = true;
            row.Borders.Bottom.Visible = true;
            row.Borders.Bottom.Width   = 1;

            row.Cells[0].AddParagraph("Student");
            row.Cells[1].AddParagraph("Specialization");
            row.Cells[2].AddParagraph("Final Grade");
            row.Cells[3].AddParagraph("Admission");
            row.Cells[4].AddParagraph("Average");
            row.Cells[5].AddParagraph("Maximum");
            row.Cells[6].AddParagraph("Status");

            for (int j = 0; j < 7; j++)
            {
                row.Cells[j].Format.Font.Bold     = true;
                row.Cells[j].Format.Alignment     = ParagraphAlignment.Justify;
                row.Cells[j].Borders.Bottom.Width = 0.25;
            }

            for (int i = 0; i < students.Count; i++)
            {
                row = this.table.AddRow();
                Student current = students.ElementAt(i);
                row.Cells[0].AddParagraph(current.FirstName + " " + current.FatherInitial + " " + current.LastName);
                row.Cells[1].AddParagraph(current.Specialization);
                row.Cells[2].AddParagraph(current.FinalGrade.ToString());
                row.Cells[3].AddParagraph(current.AdmissionExamGrade.ToString());
                row.Cells[4].AddParagraph(current.BaccalaureatAverageGrade.ToString());
                row.Cells[5].AddParagraph(current.BaccalaureatMaximumGrade.ToString());
                row.Cells[6].AddParagraph(current.Status);


                row.Borders.Bottom.Visible = true;
                row.Borders.Bottom.Width   = 0.25;
            }
        }
        public void MakeGiftCert(int itemID)
        {
            try
            {
                GiftCertificateInfo item;
                //load the item
                GiftCertificateController controller = new GiftCertificateController();
                item = controller.GetGiftCert(itemId);

                string CertAmountWords    = "";
                string MailToAddressField = "";
                string CertAmountNumber   = "";

                if (item != null)
                {
                    if (item.PaypalPaymentState.ToString().Length == 0)
                    {
                        Response.Redirect(Globals.NavigateURL("Access Denied"), true);
                    }

                    TextInfo textInfo = new CultureInfo("en-US", false).TextInfo;

                    CertAmountWords  = textInfo.ToTitleCase(NumberToWords(Int32.Parse(item.CertAmount.ToString())).ToString()).ToString() + " Dollars" + Environment.NewLine;
                    CertAmountNumber = "$" + String.Format("{0:f2}", item.CertAmount).ToString();

                    MailToAddressField = item.MailTo.ToString() + Environment.NewLine
                                         + item.MailToAddress.ToString() + Environment.NewLine
                                         + item.MailToCity.ToString() + ", " + item.MailToState.ToString() + " " + item.MailToZip.ToString();

                    _CertNotes = item.Notes.ToString();
                }


                string myPortalName = this.PortalSettings.PortalName.ToString();



                Document document = new Document();
                document.Info.Author   = "Joseph Aucoin";
                document.Info.Keywords = "Gift Certificate";
                document.Info.Title    = myPortalName.ToString() + " Gift Certificate";

                // Get the A4 page size
                MigraDoc.DocumentObjectModel.Unit width, height;
                PageSetup.GetPageSize(PageFormat.Letter, out width, out height);



                // Add a section to the document and configure it such that it will be in the centre
                // of the page
                Section section = document.AddSection();
                section.PageSetup.PageHeight  = height;
                section.PageSetup.PageWidth   = width;
                section.PageSetup.LeftMargin  = 20;
                section.PageSetup.RightMargin = 10;
                section.PageSetup.TopMargin   = 20; // height / 2;



                //++++++++++++++++++++++++++++++
                //++++++++++++++++++++++++++++++
                //++++++++++++++++++++++++++++++
                // ADD LOGO
                string myLogo = PortalSettings.HomeDirectoryMapPath + _CertLogo.ToString(); // "Images\\Chapins-Logo.png";
                MigraDoc.DocumentObjectModel.Shapes.Image image = section.Headers.Primary.AddImage(myLogo.ToString());

                image.LockAspectRatio    = true;
                image.RelativeVertical   = MigraDoc.DocumentObjectModel.Shapes.RelativeVertical.Line;
                image.RelativeHorizontal = MigraDoc.DocumentObjectModel.Shapes.RelativeHorizontal.Margin;
                image.Top              = MigraDoc.DocumentObjectModel.Shapes.ShapePosition.Top;
                image.Left             = MigraDoc.DocumentObjectModel.Shapes.ShapePosition.Right;
                image.WrapFormat.Style = MigraDoc.DocumentObjectModel.Shapes.WrapStyle.Through;

                MigraDoc.DocumentObjectModel.Tables.Table HeaderTable = new MigraDoc.DocumentObjectModel.Tables.Table();
                HeaderTable.Borders.Width         = 0; // Default to show borders 1 pixel wide Column
                HeaderTable.LeftPadding           = 10;
                HeaderTable.RightPadding          = 10;
                HeaderTable.Borders.Left.Visible  = false;
                HeaderTable.Borders.Right.Visible = false;


                // Add 1 columns
                float myColumnWidth = ((section.PageSetup.PageWidth - section.PageSetup.LeftMargin - section.PageSetup.RightMargin) / 2);   // ((width / 2) - 10);
                MigraDoc.DocumentObjectModel.Tables.Column column0 = HeaderTable.AddColumn(myColumnWidth);

                MigraDoc.DocumentObjectModel.Tables.Row row1 = HeaderTable.AddRow();
                row1.Cells[0].Elements.AddParagraph(_CertReturnAddress.ToString());
                row1.Cells[0].Format.Alignment = ParagraphAlignment.Left;


                section.Add(HeaderTable);

                /// SPACING
                MigraDoc.DocumentObjectModel.Paragraph paragraph = section.AddParagraph();
                paragraph.Format.LineSpacingRule = MigraDoc.DocumentObjectModel.LineSpacingRule.Exactly;
                paragraph.Format.LineSpacing     = MigraDoc.DocumentObjectModel.Unit.FromMillimeter(30.0);

                //   section.Add(paragraph);

                //++++++++++++++++++++++++++++++
                // ADD ANOTHER TABLE FOR MAIL TO ADDRESS
                // Create a table so that we can draw the horizontal lines
                MigraDoc.DocumentObjectModel.Tables.Table tableMailToAddress = new MigraDoc.DocumentObjectModel.Tables.Table();
                tableMailToAddress.Borders.Width = 0; // Default to show borders 1 pixel wide Column
                tableMailToAddress.LeftPadding   = 20;
                tableMailToAddress.RightPadding  = 10;

                //  float myColumnWidth100percent = (width - 10);
                var column = tableMailToAddress.AddColumn((section.PageSetup.PageWidth - section.PageSetup.LeftMargin - section.PageSetup.RightMargin));

                double fontHeight = 20;
                Font   font       = new Font("Times New Roman", fontHeight);

                // Add a row with a single cell for the first line
                MigraDoc.DocumentObjectModel.Tables.Row  row  = tableMailToAddress.AddRow();
                MigraDoc.DocumentObjectModel.Tables.Cell cell = row.Cells[0];


                cell = row.Cells[0];

                cell.Format.Font.Color = Colors.Black;
                cell.Format.Alignment  = ParagraphAlignment.Left;
                cell.Format.Font.ApplyFont(font);

                cell.AddParagraph(MailToAddressField.ToString());

                section.Add(tableMailToAddress);

                // ADD SPACER+++++++++++++++++++++++++++++++++++++++
                MigraDoc.DocumentObjectModel.Paragraph paragraph1 = section.AddParagraph();
                paragraph1.Format.LineSpacingRule = MigraDoc.DocumentObjectModel.LineSpacingRule.Exactly;
                paragraph1.Format.LineSpacing     = MigraDoc.DocumentObjectModel.Unit.FromMillimeter(20.0);



                // ADD ANOTHER TABLE FOR CERT
                // Create a table so that we can draw the horizontal lines
                MigraDoc.DocumentObjectModel.Tables.Table tableCert = new MigraDoc.DocumentObjectModel.Tables.Table();
                tableCert.Borders.Width         = 0; // Default to show borders 1 pixel wide Column
                tableCert.LeftPadding           = 10;
                tableCert.RightPadding          = 10;
                tableCert.Borders.Right.Visible = true;

                //  float myColumnWidth100percent = (width - 10);
                float sectionWidth = section.PageSetup.PageWidth - section.PageSetup.LeftMargin - section.PageSetup.RightMargin;
                float columnWidth  = sectionWidth;


                var columnCert = tableCert.AddColumn(columnWidth);
                columnCert.Format.Alignment = ParagraphAlignment.Center;

                double fontHeightCert = 30;
                Font   fontCert       = new Font("Times New Roman", fontHeightCert);

                // Add a row with a single cell for the first line
                MigraDoc.DocumentObjectModel.Tables.Row  rowCert  = tableCert.AddRow();
                MigraDoc.DocumentObjectModel.Tables.Cell cellCert = rowCert.Cells[0];

                cellCert.Format.Font.Color = Colors.Black;
                cellCert.Format.Font.ApplyFont(fontCert);
                cellCert.Borders.Left.Visible   = false;
                cellCert.Borders.Right.Visible  = false;
                cellCert.Borders.Bottom.Visible = false;

                cellCert.AddParagraph(_CertBannerText.ToString());

                // Add a row with a single cell for the second line
                rowCert  = tableCert.AddRow();
                cellCert = rowCert.Cells[0];

                cellCert.Format.Font.Color = Colors.Black;
                cellCert.Format.Alignment  = ParagraphAlignment.Center;
                cellCert.Format.Font.ApplyFont(fontCert);
                cellCert.Borders.Left.Visible  = false;
                cellCert.Borders.Right.Visible = false;
                cellCert.Borders.Top.Visible   = false;

                cellCert.AddParagraph(CertAmountWords.ToString());

                // 3RD LINE
                // Add a row with a single cell for the third line
                rowCert  = tableCert.AddRow();
                cellCert = rowCert.Cells[0];


                Font fontCertDetails = new Font("Times New Roman", 20);
                cellCert.Format.Font.Color = Colors.Black;

                cellCert.Format.Alignment = ParagraphAlignment.Left;
                cellCert.Format.Font.ApplyFont(fontCertDetails);
                cellCert.Borders.Left.Visible  = false;
                cellCert.Borders.Right.Visible = false;
                cellCert.Borders.Top.Visible   = false;

                cellCert.Format.SpaceBefore = MigraDoc.DocumentObjectModel.Unit.FromMillimeter(10.0);
                cellCert.Format.LeftIndent  = MigraDoc.DocumentObjectModel.Unit.FromMillimeter(15.0);
                cellCert.AddParagraph("Date:" + item.CreatedDate.ToShortDateString() + Environment.NewLine + "Presented to: " + item.ToName.ToString() + Environment.NewLine +
                                      "From: " + item.FromName.ToString() + Environment.NewLine + "Amount: " + CertAmountNumber.ToString());


////////////////////////////////
                // 4th LINE
                // Add a row with a single cell for the forth line
                rowCert  = tableCert.AddRow();
                cellCert = rowCert.Cells[0];


                Font fontCertSignature = new Font("Arial", 12);
                cellCert.Format.Font.Color = Colors.Black;

                cellCert.Format.Alignment = ParagraphAlignment.Left;
                cellCert.Format.Font.ApplyFont(fontCertSignature);
                cellCert.Borders.Left.Visible  = false;
                cellCert.Borders.Right.Visible = false;
                cellCert.Borders.Top.Visible   = false;

                cellCert.Format.SpaceBefore = MigraDoc.DocumentObjectModel.Unit.FromMillimeter(10.0);
                cellCert.Format.LeftIndent  = MigraDoc.DocumentObjectModel.Unit.FromMillimeter(15.0);
                cellCert.AddParagraph("Authorized Signature: __________________________________________________");

                ////////////////////////////////
                // 5th LINE
                // Add a row with a single cell for the fifth line
                rowCert  = tableCert.AddRow();
                cellCert = rowCert.Cells[0];


                Font fontCertInvoiceNumber = new Font("Arial", 10);
                cellCert.Format.Font.Color = Colors.Black;

                cellCert.Format.Alignment = ParagraphAlignment.Center;
                cellCert.Format.Font.ApplyFont(fontCertInvoiceNumber);
                cellCert.Borders.Left.Visible  = false;
                cellCert.Borders.Right.Visible = false;
                cellCert.Borders.Top.Visible   = false;
                //      cellCert.Format.AddTabStop("16cm", TabAlignment.Right);
                cellCert.Format.SpaceBefore = MigraDoc.DocumentObjectModel.Unit.FromMillimeter(3.0);
                //cellCert.Format.LeftIndent = MigraDoc.DocumentObjectModel.Unit.FromMillimeter(15.0);
                cellCert.AddParagraph("Certificate Number 00" + item.ItemId.ToString());

                document.LastSection.Add(tableCert);


                if (item.Notes.ToString().Trim().Length > 0)
                {
                    //+++++++++ ADD PARAGRAPH FOR BUYER NOTES
                    MigraDoc.DocumentObjectModel.Paragraph paragraphFooter = section.AddParagraph();
                    paragraphFooter.Format.LineSpacingRule = MigraDoc.DocumentObjectModel.LineSpacingRule.Exactly;
                    paragraphFooter.Format.LineSpacing     = MigraDoc.DocumentObjectModel.Unit.FromMillimeter(8.0);
                    paragraphFooter.Format.SpaceBefore     = MigraDoc.DocumentObjectModel.Unit.FromMillimeter(10.0);
                    paragraphFooter.AddText("NOTES:" + Environment.NewLine + _CertNotes.ToString());
                }



                Paragraph footerText = new Paragraph();
                footerText.Format.Alignment = ParagraphAlignment.Center;
                footerText.AddText(_CertFooterText.ToString());

                section.Footers.Primary.Add(footerText);



                // Create a renderer
                PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer();

                // Associate the MigraDoc document with a renderer
                pdfRenderer.Document = document;

                // Layout and render document to PDF
                pdfRenderer.RenderDocument();


                string pdfFilename = PortalSettings.HomeDirectoryMapPath + _PdfFilesFolder.ToString() + "Cert" + itemId.ToString() + ".pdf";

                if (File.Exists(pdfFilename))
                {
                    File.Delete(pdfFilename);
                }

                pdfRenderer.PdfDocument.Save(pdfFilename);



                bool watermarkIsNeeded = false;
                if (_CertWatermark.ToString().Trim().Length > 1)
                {
                    watermarkIsNeeded = true;
                }

                if (watermarkIsNeeded)
                {
                    PdfDocument pdfIn  = PdfReader.Open(pdfFilename, PdfDocumentOpenMode.Import);
                    PdfDocument pdfOut = new PdfDocument();

                    for (int i = 0; i < pdfIn.PageCount; i++)
                    {
                        PdfPage pg = pdfIn.Pages[i];
                        pg = pdfOut.AddPage(pg);
                        // WATERMARK TEXT
                        string draftFlagStr = _CertWatermark.ToString();

                        // Get an XGraphics object for drawing beneath the existing content
                        XGraphics gfx = XGraphics.FromPdfPage(pg, XGraphicsPdfPageOptions.Prepend);

                        // Get the size (in point) of the text
                        XFont fontWM = new XFont("Verdana", 62, XFontStyle.Bold);
                        XSize size   = gfx.MeasureString(draftFlagStr, fontWM);

                        // Define a rotation transformation at the center of the page
                        gfx.TranslateTransform(pg.Width / 2, pg.Height / 2);
                        gfx.RotateTransform(-Math.Atan(pg.Height / pg.Width) * 180 / Math.PI);
                        gfx.TranslateTransform(-pg.Width / 2, -pg.Height / 2);

                        // Create a string format
                        XStringFormat format = new XStringFormat();
                        format.Alignment     = XStringAlignment.Near;
                        format.LineAlignment = XLineAlignment.Near;

                        // Create a dimmed red brush
                        XBrush brush = new XSolidBrush(XColor.FromArgb(32, 0, 0, 255));

                        // Draw the string
                        gfx.DrawString(draftFlagStr, fontWM, brush,
                                       new XPoint((pg.Width - size.Width) / 2, (pg.Height - size.Height) / 2),
                                       format);
                    }
                    pdfOut.Save(pdfFilename);
                }



                // Save and show the document
                //  pdfRenderer.PdfDocument.Save("TestDocument.pdf");
                Process.Start("explorer.exe", pdfFilename);


                HyperLinkPDF.Visible     = true;
                HyperLinkPDF.NavigateUrl = PortalSettings.HomeDirectory + _PdfFilesFolder.ToString() + "Cert" + itemId.ToString() + ".pdf";
            }
            catch (Exception ex)
            {
                Exceptions.ProcessModuleLoadException(this, ex);
            }
        }