Esempio n. 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);
                }
            }
        }
Esempio n. 2
0
    public static void createTable(Section section ,string tableHeadder, string [] tableHeaders , dynamic tableData, string typeOfTable )
    {
        section.AddPageBreak();
           section.AddParagraph();
           Paragraph headerGroup = section.AddParagraph();
           headerGroup.Style = "Header";
           headerGroup.Format.Alignment = ParagraphAlignment.Center;
           headerGroup.AddText(string.Format(tableHeadder));
           section.AddParagraph();

           Table table = section.AddTable();
           table.Style = EstiloTabla;
           table.Borders.Color = ColorBorderTabla;
           table.Borders.Width = BorderWidth;
           table.Borders.Left.Width = LeftWidth;
           table.Borders.Right.Width = RightWidth;
           table.Rows.LeftIndent = LeftIndent;

          string[] sizes= new []{"16cm"};
          if (tableHeaders.Length == 3)
          {
          sizes = length3;
          }
          if (tableHeaders.Length == 4)
          {
          sizes = length4;
          }
          if (tableHeaders.Length == 6)
          {
          sizes = length6;
          }

          for (int i = 0; i < sizes.Length; i++)
          {
          table.AddColumn(sizes[i]);

          }

          Row row = table.AddRow();
          row.HeadingFormat = true;
          row.Format.Alignment = AlineamientoTableHead;
          row.Format.Font.Bold = true;
          row.Shading.Color = ColorFondoTableHead;

          for (int i = 0; i < tableHeaders.Length; i++)
          {
          row.Cells[i].AddParagraph(tableHeaders[i]);
          }

          row.HeadingFormat = false;

          //Agregar contenido de a la tabla.

          int counter = 0;
          if (tableData != null)
          {
          foreach (var dataObj in tableData)
          {
              row = table.AddRow();
              if (counter % 2 == 0)
                  row.Shading.Color = ColorFondoRow;

              if (typeOfTable.Equals("initial") || typeOfTable.Equals("final"))
              {
                  row.Cells[0].AddParagraph((string)dataObj.Descripcion);
                  row.Cells[1].AddParagraph((string)dataObj.volume);
                  row.Cells[2].AddParagraph((string)dataObj.Precio);
              }
              if (typeOfTable.Equals("cargas") || typeOfTable.Equals("descargas"))
              {
                  row.Cells[0].AddParagraph((string)dataObj.Descripcion);
                  row.Cells[1].AddParagraph((string)dataObj.Cantidad);
                  row.Cells[2].AddParagraph((string)dataObj.volume);
                  row.Cells[3].AddParagraph((string)dataObj.Precio);
              }
              if(typeOfTable.Equals("ralenti")){
                  row.Cells[0].AddParagraph((string)dataObj.Descripcion);
                  row.Cells[1].AddParagraph((string)dataObj.Tiempo);
                  row.Cells[2].AddParagraph((string)dataObj.volume);
                  row.Cells[3].AddParagraph((string)dataObj.Precio);
              }
              if(typeOfTable.Equals("consumido")){
                  row.Cells[0].AddParagraph((string)dataObj.Descripcion);
                  row.Cells[1].AddParagraph((string)dataObj.distance);
                  row.Cells[2].AddParagraph((string)dataObj.volume);
                  row.Cells[3].AddParagraph((string)dataObj.Precio);
              }
              if(typeOfTable.Equals("comportamiento")){
                  row.Cells[0].AddParagraph((string)dataObj.Descripcion);
                  row.Cells[1].AddParagraph((string)dataObj.VMax);
                  row.Cells[2].AddParagraph((string)dataObj.TMov);
                  row.Cells[3].AddParagraph((string)dataObj.TMuerto);
                  row.Cells[4].AddParagraph((string)dataObj.RendBruto);
                  row.Cells[5].AddParagraph((string)dataObj.RendEfectivo);

              }

              counter++;
              section.AddParagraph();
          }
          }
    }
Esempio n. 3
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);
                }
            }
        }
Esempio n. 4
0
        public void CreateCharacterCertificatePDF(List <string[]> data, string flName)
        {
            if (data.Count == 0)
            {
                return;
            }
            else
            {
                string containerfolder  = this.GenerateDocumentBaseDirectory();
                MigraModel.Document doc = new MigraModel.Document();
                MigraModel.Section  sec = doc.AddSection();
                sec.PageSetup           = doc.DefaultPageSetup.Clone();
                sec.PageSetup.TopMargin = ".7cm";

                foreach (var item in data)
                {
                    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 admNo   = item[4];
                    string admYear = item[5];
                    string ameta   = "Admission Sl. " + admNo + " of " + admYear;
                    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);

                    // student & headmaster
                    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;
                    para_aText  = item[0].Trim();
                    para_aTextb = item[1].Trim();
                    paraTextc   = item[2].Trim();
                    paraTextd   = item[3].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;

                    sec.AddPageBreak();
                }

                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_" + flName + "_" + 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);
            }
        }