Example #1
1
        /// <summary>Writes PDF for specified auto-doc commands.</summary>
        /// <param name="section">The writer to write to.</param>
        /// <param name="tags">The autodoc tags.</param>
        /// <param name="workingDirectory">The working directory.</param>
        private void TagsToMigraDoc(Section section, List<AutoDocumentation.ITag> tags, string workingDirectory)
        {
            foreach (AutoDocumentation.ITag tag in tags)
            {
                if (tag is AutoDocumentation.Heading)
                {
                    AutoDocumentation.Heading heading = tag as AutoDocumentation.Heading;
                    if (heading.headingLevel > 0 && heading.headingLevel <= 6)
                    {
                        if (heading.headingLevel == 1)
                            section.AddPageBreak();

                        Paragraph para = section.AddParagraph(heading.text, "Heading" + heading.headingLevel);
                        if (heading.headingLevel == 1)
                            para.Format.OutlineLevel = OutlineLevel.Level1;
                        else if (heading.headingLevel == 2)
                            para.Format.OutlineLevel = OutlineLevel.Level2;
                        else if (heading.headingLevel == 3)
                            para.Format.OutlineLevel = OutlineLevel.Level3;
                        else if (heading.headingLevel == 4)
                            para.Format.OutlineLevel = OutlineLevel.Level4;
                        else if (heading.headingLevel == 5)
                            para.Format.OutlineLevel = OutlineLevel.Level5;
                        else if (heading.headingLevel == 6)
                            para.Format.OutlineLevel = OutlineLevel.Level6;
                    }
                }
                else if (tag is AutoDocumentation.Paragraph)
                {
                    AddFormattedParagraphToSection(section, tag as AutoDocumentation.Paragraph);
                }
                else if (tag is AutoDocumentation.GraphAndTable)
                {
                    CreateGraphPDF(section, tag as AutoDocumentation.GraphAndTable, workingDirectory);
                }
                else if (tag is AutoDocumentation.Table)
                {
                    CreateTable(section, tag as AutoDocumentation.Table, workingDirectory);
                }
                else if (tag is Graph)
                {
                    GraphPresenter graphPresenter = new GraphPresenter();
                    GraphView graphView = new GraphView();
                    graphView.BackColor = System.Drawing.Color.White;
                    graphView.FontSize = 12;
                    graphView.Width = 500;
                    graphView.Height = 500;
                    graphPresenter.Attach(tag, graphView, ExplorerPresenter);
                    string PNGFileName = graphPresenter.ExportToPDF(workingDirectory);
                    section.AddImage(PNGFileName);
                    string caption = (tag as Graph).Caption;
                    if (caption != null)
                        section.AddParagraph(caption);
                    graphPresenter.Detach();
                }
                else if (tag is Map)
                {
                    Form f = new Form();
                    f.Width = 700; // 1100;
                    f.Height = 500; // 600;
                    MapPresenter mapPresenter = new MapPresenter();
                    MapView mapView = new MapView();
                    mapView.BackColor = System.Drawing.Color.White;
                    mapView.Parent = f;
                    (mapView as Control).Dock = DockStyle.Fill;
                    f.Show();

                    mapPresenter.Attach(tag, mapView, ExplorerPresenter);

                    Application.DoEvents();
                    Thread.Sleep(2000);
                    Application.DoEvents();
                    string PNGFileName = mapPresenter.ExportToPDF(workingDirectory);
                    section.AddImage(PNGFileName);
                    mapPresenter.Detach();

                    f.Close();
                }
                else if (tag is AutoDocumentation.Image)
                {
                    AutoDocumentation.Image imageTag = tag as AutoDocumentation.Image;
                    if (imageTag.image.Width > 700)
                        imageTag.image = ImageUtilities.ResizeImage(imageTag.image, 700, 500);
                    string PNGFileName = Path.Combine(workingDirectory, imageTag.name);
                    imageTag.image.Save(PNGFileName, System.Drawing.Imaging.ImageFormat.Png);
                    section.AddImage(PNGFileName);
                }
            }
        }
Example #2
0
 /// <summary>
 /// Add logo to the report. The logo will be placed on the header of the report.
 /// </summary>
 /// <param name="Path"></param>
 public void AddLogo(string Path)
 {
     _img = _section.AddImage(Path);
     _img.LockAspectRatio = true;
     _img.Top             = ShapePosition.Center;
     _img.Left            = ShapePosition.Center;
 }
Example #3
0
        public static Section AddLogo(this Section section, Action <Image> callback = null, string logoFile = null)
        {
            var image = section.AddImage(HttpContext.Current.Server.MapPath(logoFile.IsNullOrWhiteSpace() ? "/Content/reports/pdf-logo.gif" : logoFile));

            image.LockAspectRatio    = false;
            image.RelativeVertical   = RelativeVertical.Line;
            image.RelativeHorizontal = RelativeHorizontal.Margin;
            image.Top              = ShapePosition.Top;
            image.Left             = "14cm";
            image.WrapFormat.Style = WrapStyle.Through;
            if (logoFile.IsNullOrWhiteSpace())
            {
                image.Width  = (187 - 0).PixelsToUnitPoints();
                image.Height = (234 - 0).PixelsToUnitPoints();
            }


            if (callback != null)
            {
                callback(image);
            }

            return(section);
        }
Example #4
0
        private void SetInfo(Order order, ref Section section)
        {
            TextFrame frame1 = section.AddTextFrame();
            frame1.RelativeVertical = RelativeVertical.Page;
            frame1.Left = ShapePosition.Right;
            frame1.Top = new Unit(1.85, UnitType.Centimeter);
            frame1.Width = new Unit(10, UnitType.Centimeter);
            Paragraph p = frame1.AddParagraph();
            p.Format.Font.Size = 16;
            p.Format.Alignment = ParagraphAlignment.Right;
            p.AddFormattedText("Order #" + order.Id, TextFormat.Bold);

            frame1 = section.AddTextFrame();
            TextFrame frame2 = section.AddTextFrame();

            if (!String.IsNullOrWhiteSpace(_ecommerceSettings.ReportLogoImage) &&
                !_ecommerceSettings.ReportLogoImage.Contains("http"))
            {
                string logoUrl = _getLogoUrl.Get();
                if (!String.IsNullOrWhiteSpace(logoUrl))
                {
                    MigraDoc.DocumentObjectModel.Shapes.Image logo = section.AddImage(logoUrl);
                    logo.RelativeVertical = RelativeVertical.Page;
                    logo.Left = ShapePosition.Left;
                    logo.Top = new Unit(1.85, UnitType.Centimeter);
                    logo.Height = new Unit(1.5, UnitType.Centimeter);
                    frame1.MarginTop = new Unit(0.5, UnitType.Centimeter);
                    frame2.MarginTop = new Unit(0.5, UnitType.Centimeter);
                }
            }

            frame1.RelativeVertical = RelativeVertical.Page;
            frame1.Left = ShapePosition.Left;
            frame1.Top = new Unit(3.5, UnitType.Centimeter);
            frame1.Width = new Unit(10, UnitType.Centimeter);

            frame2.RelativeVertical = RelativeVertical.Page;
            frame2.Left = ShapePosition.Right;
            frame2.Top = new Unit(3.5, UnitType.Centimeter);
            frame2.Width = new Unit(8, UnitType.Centimeter);

            //BILLING AND SHIPPING
            p = frame1.AddParagraph();
            p.AddFormattedText("Bill to:", TextFormat.Bold);
            p = frame2.AddParagraph();
            p.AddFormattedText("Ship to:", TextFormat.Bold);
            p = frame1.AddParagraph();
            p.AddText(order.BillingAddress.Name);
            if (!string.IsNullOrEmpty(order.BillingAddress.Company))
            {
                p = frame1.AddParagraph();
                p.AddText(order.BillingAddress.Company);
            }

            if (order.ShippingAddress != null)
            {
                p = frame2.AddParagraph();
                p.AddText(order.ShippingAddress.Name);

                if (!string.IsNullOrEmpty(order.ShippingAddress.Company))
                {
                    p = frame2.AddParagraph();
                    p.AddText(order.ShippingAddress.Company);
                }
            }

            p = frame1.AddParagraph();
            p.AddText(order.BillingAddress.PhoneNumber);

            if (order.ShippingAddress != null)
            {
                if (!string.IsNullOrWhiteSpace(order.ShippingAddress.PhoneNumber))
                {
                    p = frame2.AddParagraph();
                    p.AddText(order.ShippingAddress.PhoneNumber);
                }
            }

            p = frame1.AddParagraph();
            p.AddText(order.BillingAddress.Address1);

            if (order.ShippingAddress != null)
            {
                if (!string.IsNullOrWhiteSpace(order.ShippingAddress.Address1))
                {
                    p = frame2.AddParagraph();
                    p.AddText(order.ShippingAddress.Address1);   
                }
            }

            if (!string.IsNullOrWhiteSpace(order.BillingAddress.Address2))
            {
                p = frame1.AddParagraph();
                p.AddText(order.BillingAddress.Address2);
            }

            if (order.ShippingAddress != null)
            {
                if (!string.IsNullOrWhiteSpace(order.ShippingAddress.Address2))
                {
                    p = frame2.AddParagraph();
                    p.AddText(order.ShippingAddress.Address2);
                }
            }

            if (!string.IsNullOrWhiteSpace(order.BillingAddress.City))
            {
                p = frame1.AddParagraph();
                p.AddText(order.BillingAddress.City);
            }

            if (order.ShippingAddress != null)
            {
                if (!string.IsNullOrWhiteSpace(order.ShippingAddress.City))
                {
                    p = frame2.AddParagraph();
                    p.AddText(order.ShippingAddress.City);
                }
            }

            if (!string.IsNullOrWhiteSpace(order.BillingAddress.StateProvince))
            {
                p = frame1.AddParagraph();
                p.AddText(order.BillingAddress.StateProvince);
            }

            if (order.ShippingAddress != null)
            {
                if (!string.IsNullOrWhiteSpace(order.ShippingAddress.StateProvince))
                {
                    p = frame2.AddParagraph();
                    p.AddText(order.ShippingAddress.StateProvince);
                }
            }

            string billingCountryName = order.BillingAddress.GetCountryName();
            if (!string.IsNullOrWhiteSpace(billingCountryName))
            {
                p = frame1.AddParagraph();
                p.AddText(billingCountryName);
            }

            if (order.ShippingAddress != null)
            {
                string shippingCountryName = order.ShippingAddress.GetCountryName();
                if (!string.IsNullOrWhiteSpace(shippingCountryName))
                {
                    p = frame2.AddParagraph();
                    p.AddText(shippingCountryName);
                }
            }

            if (!string.IsNullOrWhiteSpace(order.BillingAddress.PostalCode))
            {
                p = frame1.AddParagraph();
                p.AddText(order.BillingAddress.PostalCode);
            }

            if (order.ShippingAddress != null)
            {
                if (!string.IsNullOrWhiteSpace(order.ShippingAddress.PostalCode))
                {
                    p = frame2.AddParagraph();
                    p.AddText(order.ShippingAddress.PostalCode);
                }
            }

            frame1.AddParagraph("").AddLineBreak();
            frame2.AddParagraph("").AddLineBreak();

            //PAYMENT AND SHIPPING METHODS
            p = frame1.AddParagraph();
            p.AddText(string.Format("Payment method: {0}", order.PaymentMethod.BreakUpString()));
            p = frame2.AddParagraph();
            p.AddText(string.Format("Shipping method: {0}", order.ShippingMethodName));
        }
Example #5
0
        /// <summary>Writes PDF for specified auto-doc commands.</summary>
        /// <param name="section">The writer to write to.</param>
        /// <param name="tags">The autodoc tags.</param>
        /// <param name="workingDirectory">The working directory.</param>
        private void TagsToMigraDoc(Section section, List<AutoDocumentation.ITag> tags, string workingDirectory)
        {
            foreach (AutoDocumentation.ITag tag in tags)
            {
                if (tag is AutoDocumentation.Heading)
                {
                    AutoDocumentation.Heading heading = tag as AutoDocumentation.Heading;
                    if (heading.headingLevel > 0 && heading.headingLevel <= 6)
                    {
                        if (heading.headingLevel == 1)
                            section.AddPageBreak();

                        Paragraph para = section.AddParagraph(heading.text, "Heading" + heading.headingLevel);
                        if (heading.headingLevel == 1)
                            para.Format.OutlineLevel = OutlineLevel.Level1;
                        else if (heading.headingLevel == 2)
                            para.Format.OutlineLevel = OutlineLevel.Level2;
                        else if (heading.headingLevel == 3)
                            para.Format.OutlineLevel = OutlineLevel.Level3;
                        else if (heading.headingLevel == 4)
                            para.Format.OutlineLevel = OutlineLevel.Level4;
                        else if (heading.headingLevel == 5)
                            para.Format.OutlineLevel = OutlineLevel.Level5;
                        else if (heading.headingLevel == 6)
                            para.Format.OutlineLevel = OutlineLevel.Level6;
                    }
                }
                else if (tag is AutoDocumentation.Paragraph)
                {
                    AddFormattedParagraphToSection(section, tag as AutoDocumentation.Paragraph);
                }
                else if (tag is AutoDocumentation.GraphAndTable)
                {
                    CreateGraphPDF(section, tag as AutoDocumentation.GraphAndTable, workingDirectory);
                }
                else if (tag is AutoDocumentation.Table)
                {
                    CreateTable(section, tag as AutoDocumentation.Table, workingDirectory);
                }
                else if (tag is Graph)
                {
                    GraphPresenter graphPresenter = new GraphPresenter();
                    GraphView graphView = new GraphView(null);
                    graphView.BackColor = OxyPlot.OxyColors.White;
                    graphView.FontSize = 12;
                    graphView.Width = 500;
                    graphView.Height = 500;
                    graphPresenter.Attach(tag, graphView, ExplorerPresenter);
                    string PNGFileName = graphPresenter.ExportToPDF(workingDirectory);
                    section.AddImage(PNGFileName);
                    string caption = (tag as Graph).Caption;
                    if (caption != null)
                        section.AddParagraph(caption);
                    graphPresenter.Detach();
                    graphView.MainWidget.Destroy();
                }
                else if (tag is Map && (tag as Map).GetCoordinates().Count > 0)
                {
                    MapPresenter mapPresenter = new MapPresenter();
                    MapView mapView = new MapView(null);
                    mapPresenter.Attach(tag, mapView, ExplorerPresenter);
                    string PNGFileName = mapPresenter.ExportToPDF(workingDirectory);
                    if (!String.IsNullOrEmpty(PNGFileName))
                       section.AddImage(PNGFileName);
                    mapPresenter.Detach();
                    mapView.MainWidget.Destroy();
                }
                else if (tag is AutoDocumentation.Image)
                {
                    AutoDocumentation.Image imageTag = tag as AutoDocumentation.Image;
                    if (imageTag.image.Width > 700)
                        imageTag.image = ImageUtilities.ResizeImage(imageTag.image, 700, 500);
                    string PNGFileName = Path.Combine(workingDirectory, imageTag.name);
                    imageTag.image.Save(PNGFileName, System.Drawing.Imaging.ImageFormat.Png);
                    section.AddImage(PNGFileName);
                }
            }
        }
 private void AddWrcLegendImage(Section section)
 {
     DataConnector dataConnector = new DataConnector();
     section.AddImage(dataConnector.PathToWrcDiagramLegendImage());
 }
Example #7
0
 /// <summary>Writes PDF for specified auto-doc commands.</summary>
 /// <param name="section">The writer to write to.</param>
 /// <param name="tags">The autodoc tags.</param>
 /// <param name="workingDirectory">The working directory.</param>
 private void TagsToMigraDoc(Section section, List<AutoDocumentation.ITag> tags, string workingDirectory)
 {
     foreach (AutoDocumentation.ITag tag in tags)
     {
         if (tag is AutoDocumentation.Heading)
         {
             AutoDocumentation.Heading heading = tag as AutoDocumentation.Heading;
             if (heading.headingLevel > 0 && heading.headingLevel < 4)
             {
                 Paragraph para = section.AddParagraph(heading.text, "Heading" + heading.headingLevel);
                 if (heading.headingLevel == 1)
                     para.Format.OutlineLevel = OutlineLevel.Level1;
                 else if (heading.headingLevel == 2)
                     para.Format.OutlineLevel = OutlineLevel.Level2;
                 else if (heading.headingLevel == 3)
                     para.Format.OutlineLevel = OutlineLevel.Level3;
                 else if (heading.headingLevel == 4)
                     para.Format.OutlineLevel = OutlineLevel.Level4;
             }
         }
         else if (tag is AutoDocumentation.Paragraph)
         {
             AddFormattedParagraphToSection(section, tag as AutoDocumentation.Paragraph);
         }
         else if (tag is AutoDocumentation.GraphAndTable)
         {
             CreateGraphPDF(section, tag as AutoDocumentation.GraphAndTable, workingDirectory);
         }
         else if (tag is Graph)
         {
             GraphPresenter graphPresenter = new GraphPresenter();
             GraphView graphView = new GraphView();
             graphView.BackColor = System.Drawing.Color.White;
             graphPresenter.Attach(tag, graphView, ExplorerPresenter);
             string PNGFileName = graphPresenter.ExportToPDF(workingDirectory);
             section.AddImage(PNGFileName);
             string caption = (tag as Graph).Caption;
             if (caption != null)
                 section.AddParagraph(caption);
             graphPresenter.Detach();
         }
     }
 }
 private void AddSchaefflerLegendImage(Section section)
 {
     DataConnector dataConnector = new DataConnector();
     section.AddImage(dataConnector.PathToSchaefflerDiagramLegendImage());
 }
 private void AddMinimapChartImage(Section section)
 {
     DataConnector dataConnector = new DataConnector();
     section.AddImage(dataConnector.PathToMinimapChartImage());
 }
Example #10
0
 public static void DefineImage(Section section, string strPath, Unit strWidth, ShapePosition shapePosition, WrapStyle wrapStyle)
 {
     Image image = section.AddImage(strPath);
     image.Width = strWidth;
     image.Left = shapePosition;
     image.WrapFormat.Style = wrapStyle;
 }
Example #11
0
 public static void DefineImage(Section section, string strPath, Unit strWidth, ShapePosition shapePosition)
 {
     Image image = section.AddImage(strPath);
     image.Width = strWidth;
     image.Left = shapePosition;
 }
Example #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);
        }
Example #13
-1
 private void addPage(Section section, string imgPaths)
 {
     Image image = section.AddImage(imgPaths);
     image.Width = "21cm";
     image.LockAspectRatio = true;
     image.RelativeVertical = RelativeVertical.Page;
     image.RelativeHorizontal = RelativeHorizontal.Page;
     image.WrapFormat.Style = WrapStyle.Through;
 }