示例#1
0
        protected override HtmlItem renderingHtmlDiv(HtmlItem it, ref Paragraph par, HtmlItem parent)
        {
            HtmlDiv div = it as HtmlDiv;
            if (div != null)
            {
                foreach (HtmlItem t in it.ListItem)
                {
                    FormattedText ff = new FormattedText();
                    RenderStyle.CreateRenderStyle(it, ref ff).Render(); //Render styles element

                    HtmlItem itemrendered = renderingit(t, ref par, it, null);
                    HtmlText textitem = itemrendered as HtmlText;
                    if (textitem != null)
                    {
                        ff.Add(new Text(textitem.Text));
                        it.SizeRenderItem.Width = calculateWithText(textitem.Text.Length, ff.Size);
                        if (it.SizeRenderItem.Width > 210)
                            it.SizeRenderItem.Width = 210;
                        it.SizeRenderItem.Height = calculateHeightText(textitem.Text.Length, ff.Size);
                    }

                    par.Add(ff);

                }
                par.AddLineBreak();
            }
            return div;
        }
示例#2
0
 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.");
 }
示例#3
0
        protected override HtmlItem renderingHtmltr(HtmlItem it, ref Paragraph par, HtmlItem parent, DocumentObject renderparent)
        {
            Htmltr tr = it as Htmltr;
            MigraDoc.DocumentObjectModel.Tables.Row rw = null;
            if (tr != null)
            {
                HtmlTable tb = parent as HtmlTable;
                if (tb != null)
                {
                    MigraDoc.DocumentObjectModel.Tables.Table tt = renderparent as MigraDoc.DocumentObjectModel.Tables.Table;
                    if (tt != null)
                    {
                        if (tt.Columns.Count > 0)
                            rw = tt.AddRow();

                        tr.SetTableParent(tb);
                    }

                }
                foreach (HtmlItem t in it.ListItem)
                {
                    FormattedText ff = new FormattedText();
                    RenderStyle.CreateRenderStyle(it, ref ff).Render();
                    HtmlItem itemrendered = renderingit(t, ref par, it, rw);
                }
            }
            return tr;
        }
示例#4
0
        protected override HtmlItem renderingHtmlLi(HtmlItem it, ref Paragraph par, HtmlItem parent)
        {
            HtmlLi  l = it as HtmlLi;
            if (l != null)
            {
                foreach (HtmlItem i in it.ListItem)
                {
                 FormattedText ff = new FormattedText();
                 HtmlItem itemrendered =   renderingit(i, ref par, l, null);
                 HtmlText textitem = itemrendered as HtmlText;
                 //RenderStyle.CreateRenderStyle(it, ref ff).Render();

                 if (textitem != null)
                 {
                     ff.Add(new Text(textitem.Text));
                     par.Add(ff);
                     it.SizeRenderItem.Width = calculateWithText(textitem.Text.Length, ff.Size);

                     if (it.SizeRenderItem.Width > 210)
                         it.SizeRenderItem.Width = 210;
                     it.SizeRenderItem.Height = calculateHeightText(textitem.Text.Length, ff.Size);

                 }
                }
            }

            return l;
        }
        /// <summary>
        /// Renders <paramref name="control"/> to the <paramref name="document"/>.
        /// </summary>
        /// <param name="document">The PDF document.</param>
        /// <param name="control">The control to be rendered.</param>
        /// <param name="level">The depth down the control tree being rendered (affects indenting).</param>
        /// <param name="controlList">The complete control list.</param>
        protected override void DoRender(Document document, Control control, int level, ControlList controlList)
        {
            TextFrame frameTemplate = this.CreateCharacterInputBox(document.Styles[StyleNames.Normal]);

            Paragraph paragraphTemplate = new Paragraph
                                              {
                                                  Style = StyleNames.Normal,
                                                  Format = { Alignment = ParagraphAlignment.Justify, Font = { Color = Colors.LightGray } }
                                              };
            Unit spacer = new Unit((frameTemplate.Width.Point - paragraphTemplate.Format.Font.Size.Point) / 4, UnitType.Point);
            paragraphTemplate.Format.SpaceBefore = spacer;
            paragraphTemplate.Format.LeftIndent = spacer;
            frameTemplate.MarginBottom = frameTemplate.Height;

            for (int i = 0; i < 8; i++)
            {
                TextFrame frame = frameTemplate.Clone();
                frame.WrapFormat.DistanceLeft = (frame.Width * i) + (new Unit(PdfConstants.IndentMultiplier * level, UnitType.Millimeter));
                string watermark = i < 2 ? "D" : i < 4 ? "M" : "Y";
                Paragraph paragraph = paragraphTemplate.Clone();
                paragraph.AddText(watermark);
                frame.Add(paragraph);
                document.LastSection.Add(frame);
            }

            TextFrame clearFrame = frameTemplate.Clone();
            clearFrame.WrapFormat.Style = WrapStyle.TopBottom;
            clearFrame.LineFormat.Width = 0;
            document.LastSection.Add(clearFrame);
        }
示例#6
0
        protected override HtmlItem renderingHtmlImg(HtmlItem it, ref Paragraph par, HtmlItem parent, DocumentObject renderparent)
        {
            HtmlImg imagen = it as HtmlImg;
            MigraDoc.DocumentObjectModel.Shapes.Image img = null;
            MigraDoc.DocumentObjectModel.Shapes.TextFrame tf = null;
            if (imagen != null)
            {
                string route = AppDomain.CurrentDomain.BaseDirectory;
                string directorytem = Settings1.Default.routetem;
                string filename = RandomString(16, false) + "." + imagen.ImageType.ToString();
                string routecompleted = route + directorytem + "\\" + filename;
                imagen.Image.Save(routecompleted);

                MigraDoc.DocumentObjectModel.Tables.Cell cellparent = renderparent as MigraDoc.DocumentObjectModel.Tables.Cell;
                if (cellparent != null)
                {
                    tf = cellparent.AddTextFrame();
                    tf.WrapFormat.Style = MigraDoc.DocumentObjectModel.Shapes.WrapStyle.Through;
                }

                if (tf != null)
                    img = tf.AddImage(routecompleted);
                else
                    img = par.AddImage(routecompleted);

                RenderStyle.CreateRenderStyle(it, ref img).Render();
                listTempFiles.Add(routecompleted);
                imagen.SizeRenderItem = new RenderSizeItem() { Width = Convert.ToDecimal(img.Width), Height = Convert.ToDecimal(img.Height) };

            }

            return imagen;
        }
示例#7
0
        /// <summary>
        /// The write drawing.
        /// </summary>
        /// <param name="d">
        /// The d.
        /// </param>
        public void WriteDrawing(DrawingFigure d)
        {
            Paragraph p = this.WriteStartFigure(d);

            this.CurrentSection.AddParagraph("Drawings are not implemented.");
            this.WriteEndFigure(d, p);
        }
示例#8
0
        /// <summary>
        /// Render this component into a section
        /// </summary>
        public void RenderInto(Cell cell)
        {
            MigraDoc.DocumentObjectModel.Paragraph paragraph = cell.AddParagraph(this.text);

            paragraph.Style            = this.style;
            paragraph.Format.Alignment = getAlignment();
        }
示例#9
0
    /// <summary>
    /// Defines page setup, headers, and footers.
    /// </summary>
    static void DefineContentSection(Document document, Project currentProject)
    {
    	try {
    	  Section section = document.AddSection();
	      section.PageSetup.OddAndEvenPagesHeaderFooter = true;
	      section.PageSetup.StartingNumber = 1;
	
	      HeaderFooter header = section.Headers.Primary;
	      header.AddParagraph(currentProject.Name);
	      
	      header = section.Headers.EvenPage;
	      header.AddParagraph(currentProject.Name);
	
	      // Create a paragraph with centered page number. See definition of style "Footer".
	      Paragraph paragraph = new Paragraph();
	      paragraph.AddTab();
	      paragraph.AddPageField();
	
	      // Add paragraph to footer for odd pages.
	      section.Footers.Primary.Add(paragraph);
	      // Add clone of paragraph to footer for odd pages. Cloning is necessary because an object must
	      // not belong to more than one other object. If you forget cloning an exception is thrown.
	      section.Footers.EvenPage.Add(paragraph.Clone());
    	} catch (Exception ex) {
    		throw ex;
    	}
     
    }
示例#10
0
        protected override HtmlItem renderingHtmlList(HtmlItem it, ref Paragraph par, HtmlItem parent)
        {
            HtmlList uol = it as HtmlList;

            if (uol != null)
            {
                foreach (HtmlLi l in uol.ListLi)
                {
                    if (l.ListItem.Exists(isText))
                    {
                        ListInfo listinfo = new ListInfo();
                        listinfo.ContinuePreviousList = true;
                        listinfo.ListType = ListType.BulletList1; // default
                        listinfo.NumberPosition = 25 * uol.Level; // BulletList margin default
                        RenderStyle.CreateRenderStyle(uol, ref listinfo).Render(); // render styles element
                        Paragraph newpar = par.Section.AddParagraph();
                        RenderStyle.CreateRenderStyle(uol, ref newpar).Render(); // render styles paragraph
                        newpar.Format.ListInfo = listinfo;

                        renderingit(l, ref newpar, uol, null);
                    }
                    else
                        renderingit(l, ref par, uol, null);
                }
            }
            if (!(parent is HtmlLi))
                par.Section.AddParagraph().AddLineBreak();
            return uol;
        }
示例#11
0
        /// <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);
        }
示例#12
0
        /// <summary>
        /// Render a title into a header or footer
        /// </summary>
        public override void RenderInto(HeaderFooter headerFooter)
        {
            MigraDoc.DocumentObjectModel.Paragraph title = new MigraDoc.DocumentObjectModel.Paragraph();

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

            headerFooter.Add(title);
        }
示例#13
0
文件: PDF.cs 项目: reaverDK/giganten
        public static void CreatePdf(string person1, string person2, DataHandler datahandler, Dictionary <string, string[]> groups)
        {
            Document document = new Document();

            document.UseCmykColor = true;

            MigraDoc.DocumentObjectModel.Section section = document.AddSection();
            section.PageSetup.Orientation = MigraDoc.DocumentObjectModel.Orientation.Landscape;
            MigraDoc.DocumentObjectModel.Paragraph paragraph = section.AddParagraph();
            paragraph.Format.Font.Color = MigraDoc.DocumentObjectModel.Color.FromCmyk(100, 20, 30, 50);

            if (person1 == "<Ingen sælger valgt>")
            {
                person1 = null;
            }

            if (person2 == "<Ingen sælger valgt>")
            {
                person2 = null;
            }

            if (person1 != null)
            {
                paragraph.AddFormattedText(person1, TextFormat.Bold);
                paragraph.AddLineBreak();
                paragraph.AddLineBreak();

                DefineCharts(document, person1, groups, datahandler);
            }

            if (person2 != null)
            {
                MigraDoc.DocumentObjectModel.Section newSection = document.AddSection();
                newSection.PageSetup.Orientation = MigraDoc.DocumentObjectModel.Orientation.Landscape;
                MigraDoc.DocumentObjectModel.Paragraph newParagraph = newSection.AddParagraph();

                newParagraph.AddFormattedText(person2, TextFormat.Bold);
                newParagraph.AddLineBreak();
                newParagraph.AddLineBreak();

                DefineCharts(document, person2, groups, datahandler);
            }

            const bool             unicode     = false;
            const PdfFontEmbedding embedding   = PdfFontEmbedding.Always;
            PdfDocumentRenderer    pdfRenderer = new PdfDocumentRenderer(unicode, embedding);

            pdfRenderer.Document = document;
            pdfRenderer.RenderDocument();

            string time   = DateTime.Today.ToShortDateString();
            string myfile = time + ".pdf";

            pdfRenderer.PdfDocument.Save(myfile);
            Process.Start(myfile);
        }
示例#14
0
        /// <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");
        }
示例#15
0
        public void VisitParagraph(Paragraph element)
        {
            if (_pdfSection == null)
            {
                _pdfSection = _document.AddSection();
            }

            _pdfParagraph = _pdfCell?.AddParagraph() ?? _pdfSection.AddParagraph();
            SetParagraphProperties(element.ParagraphProperties);
        }
示例#16
0
        /// <summary>
        /// The write image.
        /// </summary>
        /// <param name="i">
        /// The i.
        /// </param>
        public void WriteImage(Image i)
        {
            Paragraph p = this.WriteStartFigure(i);

            if (i.Source != null)
            {
                MigraDoc.DocumentObjectModel.Shapes.Image pi = p.AddImage(Path.GetFullPath(i.Source));
                pi.Width = Unit.FromCentimeter(15);
            }

            this.WriteEndFigure(i, p);
        }
示例#17
0
    public static string GetBackIterators(Paragraph paragraph)
    {
      ParagraphIterator iter = new ParagraphIterator(paragraph.Elements);
      iter = iter.GetLastLeaf();
      string retString = "";
      while (iter != null)
      {
        retString += "[" + iter.Current.GetType().Name + ":]";
        if (iter.Current is Text)
          retString += ((Text)iter.Current).Content;

        iter = iter.GetPreviousLeaf();
      }
      return retString;
    }
示例#18
0
        protected override HtmlItem renderingHtmlText(HtmlItem it, ref Paragraph par, HtmlItem parent)
        {
            HtmlText te = it as HtmlText;
            if (te != null)
            {
                if (parent == null)
                {
                    par.AddText(te.Text);
                    it.SizeRenderItem.Width =calculateWithText( te.Text.Length ,8);
                    if (it.SizeRenderItem.Width > 210)
                        it.SizeRenderItem.Width = 210;
                    it.SizeRenderItem.Height = calculateHeightText(te.Text.Length, 8);
                }
            }

            return te;
        }
示例#19
0
        /// <summary>
        /// Creates the dynamic parts of the invoice.
        /// </summary>
        void FillContent()
        {
            // Fill address in address text frame
            Paragraph paragraph = this.addressFrame.AddParagraph();

            paragraph.AddText("Dr. Anwar Ali");
            paragraph.AddLineBreak();
            paragraph.AddText("Health And Social Services ");
            paragraph.AddLineBreak();
            paragraph.AddText("Karachi");

            Row row1;

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                row1            = this.table.AddRow();
                row1.TopPadding = 1.5;

                for (int j = 0; j < dt.Columns.Count; j++)
                {
                    row1.Cells[j].Shading.Color     = TableGray;
                    row1.Cells[j].VerticalAlignment = VerticalAlignment.Center;

                    row1.Cells[j].Format.Alignment       = ParagraphAlignment.Left;
                    row1.Cells[j].Format.FirstLineIndent = 1;

                    row1.Cells[j].AddParagraph(dt.Rows[i][j].ToString());


                    this.table.SetEdge(0, this.table.Rows.Count - 2, dt.Columns.Count, 1, Edge.Box, BorderStyle.Single, 0.75);
                }
            }

            // Add the notes paragraph
            paragraph = this.document.LastSection.AddParagraph();
            paragraph.Format.SpaceBefore      = "1cm";
            paragraph.Format.Borders.Width    = 0.75;
            paragraph.Format.Borders.Distance = 3;
            paragraph.Format.Borders.Color    = TableBorder;
            paragraph.Format.Shading.Color    = TableGray;

            paragraph.AddText("Note: For any complain please contact us in 24 hours from the issuance of bill");
        }
示例#20
0
        private void FillContent()
        {
            //XPathNavigator item = SelectItem("/invoice/to");
            MigraDoc.DocumentObjectModel.Paragraph paragraph = addressFrame.AddParagraph();
            paragraph.AddText("Dane Zamawiajacego :");
            paragraph.AddLineBreak();
            paragraph.AddText($"Imię i nazwisko: {order.UserData.Name} {order.UserData.Surname}");
            paragraph.AddLineBreak();
            paragraph.AddText($"Adres: ul. {order.UserData.Adres.Street} {order.UserData.Adres.HomeNumber}, {order.UserData.Adres.PostCode} {order.UserData.Adres.City}");

            MigraDoc.DocumentObjectModel.Paragraph priceParagraph = PriceFrame.AddParagraph();
            priceParagraph.AddText($"Cena całkowita: \n {order.OrderAmount} zł \n ");
            //paragraph.AddLineBreak();
            priceParagraph.AddText($"Rodzaj przesyłki: \n {order.OrderOption}  \n");
            //paragraph.AddLineBreak();
            priceParagraph.AddText($"Cena z przesyłką: \n {order.Amount} zł\n ");
            //paragraph.AddLineBreak();


            foreach (var orderItem in order.Ordered)
            {
                Row row = table.AddRow();
                row.TopPadding = 1.5;

                row.Cells[0].Shading.Color     = TableGray;
                row.Cells[0].VerticalAlignment = MigraDoc.DocumentObjectModel.Tables.VerticalAlignment.Center;
                row.Cells[0].Format.Alignment  = ParagraphAlignment.Left;
                row.Cells[1].Format.Alignment  = ParagraphAlignment.Left;
                row.Cells[2].Format.Alignment  = ParagraphAlignment.Left;
                row.Cells[3].Format.Alignment  = ParagraphAlignment.Left;
                row.Cells[1].Shading.Color     = TableGray;
                row.Cells[2].Shading.Color     = TableGray;
                row.Cells[3].Shading.Color     = TableGray;

                row.Cells[0].AddParagraph(orderItem.Product.Name);
                row.Cells[1].AddParagraph(orderItem.Count.ToString());
                row.Cells[2].AddParagraph($"{orderItem.Product.Price} zł");
                row.Cells[3].AddParagraph($"{orderItem.Amount} zł");

                this.table.SetEdge(0, this.table.Rows.Count - 1, 4, 1, Edge.Box, BorderStyle.Single, 0.75);
            }
        }
示例#21
0
        /// <summary>
        /// Defines page setup, headers, and footers.
        /// </summary>
        private static void DefineContentSection(Document document, List<QueryData> data )
        {
            Section section = document.AddSection();
            //section.PageSetup.OddAndEvenPagesHeaderFooter = true;
            section.PageSetup.StartingNumber = 1;

            HeaderFooter header = section.Headers.Primary;
            header.AddParagraph(data[0].ProjectName + " - Отчет проверки данных от " + DateTime.Now.ToShortDateString() );
            header.Format.Alignment = ParagraphAlignment.Center;
            // Create a paragraph with centered page number. See definition of style "Footer".
            Paragraph paragraph = new Paragraph();
            paragraph.AddTab();
            paragraph.AddPageField();
            paragraph.AddText(" из ");
            paragraph.AddNumPagesField();
            // Add paragraph to footer for odd pages.
            section.Footers.Primary.Add(paragraph);
            // Add clone of paragraph to footer for odd pages. Cloning is necessary because an object must
            // not belong to more than one other object. If you forget cloning an exception is thrown.
            section.Footers.EvenPage.Add(paragraph.Clone());
        }
示例#22
0
        /// <summary>
        /// Creates a MigraDoc paragraph component based on properties
        /// </summary>
        private MigraDoc.DocumentObjectModel.Paragraph Create()
        {
            MigraDoc.DocumentObjectModel.Paragraph paragraph = new MigraDoc.DocumentObjectModel.Paragraph();

            paragraph.Style = this.style;
            this.RenderTextInto(paragraph);

            paragraph.Format.Alignment = this.GetPosition();

            if (this.border != null)
            {
                this.border.RenderInto(paragraph);
            }

            if (this.shading != null)
            {
                this.shading.RenderInto(paragraph);
            }

            return(paragraph);
        }
示例#23
0
        protected override HtmlItem renderingHtmlTable(HtmlItem it, ref Paragraph par, HtmlItem parent, DocumentObject renderparent)
        {
            HtmlTable tbl = it as HtmlTable;
            MigraDoc.DocumentObjectModel.Shapes.TextFrame tf = null;
            Paragraph partf = null;
            if (tbl != null)
            {
                MigraDoc.DocumentObjectModel.Tables.Table tt = null;
                MigraDoc.DocumentObjectModel.Tables.Cell cellparent = renderparent as MigraDoc.DocumentObjectModel.Tables.Cell;
                if (cellparent != null)
                {
                    tf = cellparent.AddTextFrame();
                    tt = tf.AddTable();
                    partf = tf.AddParagraph();

                }
                else
                    tt = par.Section.AddTable();

                tbl.SizeRenderItem.Width = 0;
                for (int i = 0; i < tbl.Cells; i++)
                {
                    MigraDoc.DocumentObjectModel.Tables.Column cc = tt.AddColumn();

                }

                foreach (HtmlItem t in it.ListItem)
                {
                    FormattedText ff = new FormattedText();
                    RenderStyle.CreateRenderStyle(it, ref ff).Render();
                    if (partf != null)
                        renderingit(t, ref partf, it, tt);
                    else
                        renderingit(t, ref par, it, tt);
                }
                RenderStyle.CreateRenderStyle(it, ref tt).Render();

            }
            return tbl;
        }
示例#24
0
        protected override HtmlItem renderingHtmlContent(HtmlItem it, ref Paragraph par, HtmlItem parent)
        {
            HtmlContent content = it as HtmlContent;
            if (content != null)
            {
                if (parent is HtmlContent)
                    par.AddLineBreak();

                foreach (HtmlItem t in it.ListItem)
                {
                    FormattedText ff = new FormattedText();
                    if (content.Bold.hasValue())
                        ff.Bold = content.Bold.Value;
                    if (content.Size.hasValue())
                        ff.Size = content.Size.Value;

                    RenderStyle.CreateRenderStyle(it, ref ff).Render();

                    HtmlItem itemrendered = renderingit(t, ref par, it, null);
                    HtmlText textitem = itemrendered as HtmlText;
                    if (textitem != null)
                    {
                        ff.Add(new Text(textitem.Text));
                        par.Add(ff);
                        it.SizeRenderItem.Width = calculateWithText(textitem.Text.Length, ff.Size);

                        //ff.Section.PageSetup.PageWidth=59 =>>210 mm A4
                        if (it.SizeRenderItem.Width > 210)
                            it.SizeRenderItem.Width = 210;
                        it.SizeRenderItem.Height = calculateHeightText(textitem.Text.Length, ff.Size);

                    }
                }
                par.AddLineBreak();
            }
            return content;
        }
示例#25
0
        protected override HtmlItem renderingHtmlSpan(HtmlItem it, ref Paragraph par, HtmlItem parent)
        {
            HtmlSpan span = it as HtmlSpan;
            if (span != null)
            {
                foreach (HtmlItem t in it.ListItem)
                {
                    FormattedText ff = new FormattedText();
                    if (span.Size.hasValue())
                        ff.Size = span.Size.Value;
                    if (span.Bold.hasValue())
                        ff.Bold = span.Bold.Value;
                    if (span.Sub.hasValue())
                        ff.Subscript = span.Sub.Value;
                    if (span.Super.hasValue())
                        ff.Superscript = span.Super.Value;

                    RenderStyle.CreateRenderStyle(it, ref ff).Render(); // render styles element

                    HtmlItem itemrendered = renderingit(t, ref par, it, null);
                    HtmlText textitem = itemrendered as HtmlText;
                    if (textitem != null)
                    {
                        ff.Add(new Text(textitem.Text));
                        it.SizeRenderItem.Width = calculateWithText(textitem.Text.Length, ff.Size);
                        if (it.SizeRenderItem.Width > 210)
                            it.SizeRenderItem.Width = 210;
                        it.SizeRenderItem.Height = calculateHeightText(textitem.Text.Length, ff.Size);
                    }

                    par.Add(ff);

                }
            }
            return span;
        }
示例#26
0
 public void BeginContextBlock()
 {
     section.AddParagraph("Context:\n\n");
     contextParagraph = section.AddParagraph();
     contextParagraph.Style = "TextBox";
 }
 /// <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");
 }
示例#28
0
        /// <summary>
        /// Render a paragraph into a header or footer
        /// </summary>
        public override void RenderInto(HeaderFooter headerFooter)
        {
            MigraDoc.DocumentObjectModel.Paragraph paragraph = this.Create();

            headerFooter.Add(paragraph);
        }
示例#29
0
 /// <summary>
 /// Render a image into a table cell
 /// </summary>
 public void RenderInto(Cell cell)
 {
     MigraDoc.DocumentObjectModel.Paragraph paragraph = cell.AddParagraph();
     paragraph.Add(this.CreateImage());
     paragraph.Format.Alignment = GetAlignment();
 }
示例#30
0
 /// <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);
 }
示例#31
0
 /// <summary>
 /// Adds a new paragraph to the header or footer.
 /// </summary>
 public void Add(Paragraph paragraph)
 {
     Elements.Add(paragraph);
 }
        private Document CreateDocument(List<domain.Product> productList, decimal euro2cny, decimal serviceRate)
        {
            productList.OrderBy(x => x.Brand);

            Document document = new Document();
            document.Styles[StyleNames.Normal].Font.Name = "Arial Unicode MS";
            document.Styles[StyleNames.Normal].Font.Color = new Color(30, 30, 30);

            Section section = document.AddSection();
            section.PageSetup.LeftMargin = 20;
            section.PageSetup.TopMargin = 20;
            Paragraph header = new Paragraph();
            header.Format.Font.Size = 35;
            header.Format.Alignment = ParagraphAlignment.Center;
            header.AddText("");
            header.AddLineBreak(); header.AddLineBreak(); header.AddLineBreak();
            header.AddText("吕贝克Nx-daigou商品报价单");
            header.AddLineBreak(); header.AddLineBreak(); header.AddLineBreak();
            document.LastSection.Add(header);

            Paragraph code = new Paragraph();
            code.Format.Font.Size = 15;
            string codeTxt = "编号: " + (euro2cny * 100.0m).ToString() + "-" + (serviceRate * 100.0m).ToString();
            code.AddText(codeTxt.Replace(".","#"));
            code.Format.Alignment = ParagraphAlignment.Center;
            code.AddLineBreak(); code.AddLineBreak(); code.AddLineBreak();
            document.LastSection.Add(code);

            Paragraph time = new Paragraph();
            time.Format.Alignment = ParagraphAlignment.Center;
            time.Format.Font.Size = 15;

            DateTimeFormatInfo chDatetimeCulture = new CultureInfo("zh-CN", false).DateTimeFormat;
            string result = DateTime.Today.ToString(chDatetimeCulture.LongDatePattern);
            time.AddText("日期: " + result);
            time.AddLineBreak(); time.AddLineBreak(); time.AddLineBreak();
            document.LastSection.Add(time);


            string productCountTxt = "商品总数: " + productList.Count.ToString();
            Paragraph productCountPara = new Paragraph();
            productCountPara.Format.Alignment = ParagraphAlignment.Center;
            productCountPara.AddText(productCountTxt);
            productCountPara.AddLineBreak(); productCountPara.AddLineBreak();
            document.LastSection.Add(productCountPara);


            string remarkTxt = "说明: 报价单里的价格均不包含邮费";
            Paragraph remarkheaderPara = new Paragraph();
            remarkheaderPara.Format.Alignment = ParagraphAlignment.Center;
            remarkheaderPara.Format.Font.Size = 10;
            remarkheaderPara.AddText(remarkTxt);
            remarkheaderPara.AddLineBreak();
            document.LastSection.Add(remarkheaderPara);


            document.LastSection.AddPageBreak();
            
            string lastBrand = "";
            int index = 1;

            foreach (var item in productList)
            {
                if ( lastBrand != item.Brand)
                {
                    Paragraph p = new Paragraph();
                    p.Format.Font.Size = 15;
                    p.Format.Font.Bold = true;
                    p.Format.Font.Color = Colors.DarkBlue;
                    p.AddText("==" + item.Brand + "==");
                    document.LastSection.Add(p);
                    lastBrand = item.Brand;                    
                }
 
                Table table = document.LastSection.AddTable();                
                table.Borders.Visible = true;
                table.Borders.Color = Colors.Gray;


                Column column = table.AddColumn(Unit.FromCentimeter(5));
                column.Format.Alignment = ParagraphAlignment.Center;

                column = table.AddColumn(Unit.FromCentimeter(12));
                column.Format.Alignment = ParagraphAlignment.Left;

                column = table.AddColumn(Unit.FromCentimeter(3));
                column.Format.Alignment = ParagraphAlignment.Left;
    

                table.Rows.Height = 10;

                Row row = table.AddRow();
                row.Cells[0].MergeDown = 2;
                string path = (item.Photo.IsNullOrEmpty()) ? "images\\default.png" : item.Photo;

                Paragraph imagePara = new Paragraph();
                imagePara.Add(CreateImage(DirectoryHelper.CombineWithCurrentExeDir(path)));
                imagePara.Format.Alignment = ParagraphAlignment.Center;

                row.Cells[0].Add(imagePara);
                row.Cells[1].AddParagraph("编号: " + item.ID + "\t\t别名:" + item.Code + "   ");

                string priceTxt = this.productPriceCalcuateService.GetPrice(item, euro2cny * serviceRate).ToString() + "元";
                Paragraph pricePara = new Paragraph();
                pricePara.AddText(priceTxt);
                pricePara.Format.Font.Color = Colors.OrangeRed;
                row.Cells[2].Add(pricePara);               


                row = table.AddRow();
                string productNameTxt = item.Brand + "->" + item.Name;
                Paragraph productNamePara = new Paragraph();
                productNamePara.AddText(productNameTxt);
                productNamePara.Format.Font.Color = Colors.DarkBlue;
                row.Cells[1].Add(productNamePara);      
          
                row.Cells[2].AddParagraph("重量: " + item.GrossWeight + " g");


                row = table.AddRow();
                row.Cells[1].AddParagraph("[规格:" + item.Spec + "]              [适用于:" + item.ApplicableCrowd+"]");

                Paragraph remarkPara = new Paragraph();
                remarkPara.AddText(item.Remark);
                remarkPara.Format.Font.Size = 8;
                row.Cells[1].Add(remarkPara);

                Paragraph tagListPara = new Paragraph();
                tagListPara.AddText(item.TagList);
                tagListPara.Format.Font.Size = 8;
                row.Cells[2].Add(tagListPara);                    

                table.SetEdge(0, 0, 3, 3, Edge.Top, BorderStyle.Single, 2, Colors.Black);

                index++; 
            }

            return document;
        }
        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);
            }
        }
示例#34
0
        /// <summary>
        /// Adds fixed-width text to a MigraDoc paragraph
        /// </summary>
        /// <param name="paragraph">The paragaraph to add text to</param>
        /// <param name="text">The text</param>
        private static void AddFixedWidthText(Paragraph paragraph, string text, int width)
        {
            //For some reason, a parapraph converts all sequences of white
            //space to a single space.  Thus we need to split the text and add
            //the spaces using the AddSpace function.

            int numSpaces = width - text.Length;

            paragraph.AddSpace(numSpaces);
            paragraph.AddText(text);
        }
示例#35
0
 /// <summary>
 /// Renders text components into a paragraph
 /// </summary>
 protected void RenderTextInto(MigraDoc.DocumentObjectModel.Paragraph paragraph)
 {
     this.childs.ForEach(text => text.AddTo(paragraph));
 }
        private static MigraDoc.Rendering.PdfDocumentRenderer CreateHomeGroupListDocument(string groupName, List<PersonViewModel> personList)
        {
            // Create new MigraDoc document
            Document document = new Document();
            document.Info.Title = groupName;
            document.Info.Author = "oikonomos";
            document.Info.Subject = "Group List for " + groupName;
            Section sec = document.AddSection();
            sec.PageSetup.TopMargin = Unit.FromCentimeter(1);
            sec.PageSetup.LeftMargin = Unit.FromCentimeter(1);
            document.DefaultPageSetup.TopMargin = Unit.FromCentimeter(1);
            document.DefaultPageSetup.LeftMargin = Unit.FromCentimeter(1);

            Paragraph p = sec.Headers.Primary.AddParagraph();
            p.AddText("Group List for " + groupName);
            p.Format.Font.Size = 10.0;
            p.Format.Font.Bold = true;
            p.Format.Alignment = ParagraphAlignment.Center;

            Paragraph pf = new Paragraph();
            pf.AddText("Date: " + DateTime.Now.ToString("dd MMM yyyy"));
            pf.Format.Font.Size = 6.0;
            sec.Footers.Primary.Add(pf);

            MigraDoc.DocumentObjectModel.Tables.Table membersTable = new MigraDoc.DocumentObjectModel.Tables.Table();
            personList = personList.OrderBy(x => x.RoleName).ThenBy(x => x.Surname).ThenBy(x => x.PersonId).ToList();
            AddHeaders(membersTable, null);
            AddHomegroupData(document, personList, membersTable);

            MigraDoc.DocumentObjectModel.Tables.Table visitorsTable = new MigraDoc.DocumentObjectModel.Tables.Table();

            sec.Add(membersTable);

            document.LastSection.PageSetup.TopMargin = Unit.FromMillimeter(20);

            MigraDoc.Rendering.PdfDocumentRenderer pdfRender = new MigraDoc.Rendering.PdfDocumentRenderer(false, PdfSharp.Pdf.PdfFontEmbedding.Always);
            pdfRender.Document = document; //document is where all of my info has been written to and is a MigraDoc type
            pdfRender.RenderDocument();

            return pdfRender;
        }
        private static MigraDoc.Rendering.PdfDocumentRenderer CreateHomeGroupAttendanceDocument(string groupName, List<AttendanceEventViewModel> attendees, Dictionary<int, string> comments)
        {
            // Create new MigraDoc document
            Document document = new Document();
            document.Info.Title = groupName;
            document.Info.Author = "oikonomos";
            document.Info.Subject = "Homegroup Attendance for " + groupName;
            Section sec = document.AddSection();
            sec.PageSetup.TopMargin = Unit.FromCentimeter(1);
            sec.PageSetup.LeftMargin = Unit.FromCentimeter(1);
            document.DefaultPageSetup.TopMargin = Unit.FromCentimeter(1);
            document.DefaultPageSetup.LeftMargin = Unit.FromCentimeter(1);

            Paragraph p = sec.Headers.Primary.AddParagraph();
            p.AddText("Homegroup Attendance for " + groupName);
            p.Format.Font.Size = 10.0;
            p.Format.Font.Bold = true;
            p.Format.Alignment = ParagraphAlignment.Center;

            Paragraph pf = new Paragraph();
            pf.AddText("Date: " + DateTime.Now.ToString("dd MMM yyyy"));
            pf.Format.Font.Size = 6.0;
            sec.Footers.Primary.Add(pf);

            //Work out which distinct days there are in each month
            List<int> month1Events = new List<int>();
            List<int> month2Events = new List<int>();
            int month1 = DateTime.Now.AddMonths(-1).Month;
            int month2 = DateTime.Now.Month;
            GetAttendanceDays(attendees, month1Events, month2Events, month1, month2);

            if (month1Events.Count == 0)
            {
                month1Events.Add(1);
            }
            if (month2Events.Count == 0)
            {
                month2Events.Add(1);
            }

            MigraDoc.DocumentObjectModel.Tables.Table attendeesTable = new MigraDoc.DocumentObjectModel.Tables.Table();
            int totalColumns = AddAttendanceHeaders(month1, month2, month1Events, month2Events, attendeesTable, "Members");
            AddAttendanceData(attendees, document, month1Events, month2Events, month1, month2, attendeesTable, totalColumns, comments);
            sec.Add(attendeesTable);

            document.LastSection.PageSetup.TopMargin = Unit.FromMillimeter(20);

            MigraDoc.Rendering.PdfDocumentRenderer pdfRender = new MigraDoc.Rendering.PdfDocumentRenderer(false, PdfSharp.Pdf.PdfFontEmbedding.Always);
            pdfRender.Document = document; //document is where all of my info has been written to and is a MigraDoc type
            pdfRender.RenderDocument();

            return pdfRender;
        }
示例#38
0
 public void EndContextBlock()
 {
     section.AddParagraph("\n\n");
     contextParagraph = null;
 }
 public RenderStyleParagraph(HtmlItem it, ref Paragraph prg)
 {
     Prg = prg;
     It = it;
 }
示例#40
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");
 }
示例#41
0
        private static Document CreatePDF(SetViewModel obj)
        {
            Document doc = new Document();

            //Defining styles
            Style style = doc.Styles["Normal"];
            style.Font.Name = "Arial";
            style.Font.Size = 6;

            style = doc.Styles[StyleNames.Header];
            style.ParagraphFormat.AddTabStop("16cm", TabAlignment.Right);

            style = doc.Styles[StyleNames.Footer];
            style.ParagraphFormat.AddTabStop("8cm", TabAlignment.Right);

            foreach (var itemSet in obj.Set)
            {

                //Define content section
                Section section = doc.AddSection();
                section.PageSetup.StartingNumber = 1;
                section.PageSetup.LeftMargin = "0.7cm";
                section.PageSetup.RightMargin = "0.7cm";
                section.PageSetup.BottomMargin = "0.5cm";
                section.PageSetup.TopMargin = "1.4cm";
                section.PageSetup.FooterDistance = "0.5cm";
                section.PageSetup.HeaderDistance = "0.5cm";

                // Create Header
                Table hTable = section.Headers.Primary.AddTable();
                hTable.Borders.Width = 0;
                var hlColumn = hTable.AddColumn("6cm");
                hlColumn.Format.Alignment = ParagraphAlignment.Left;
                var hcColumn = hTable.AddColumn("8cm");
                hlColumn.Format.Alignment = ParagraphAlignment.Center;
                var hrColumn = hTable.AddColumn("6cm");
                hrColumn.Format.Alignment = ParagraphAlignment.Right;
                var hRow = hTable.AddRow();
                var hCell = hRow.Cells[0];
                hCell.AddParagraph("НИИ Антимикробной химиотерапии");
                hCell.Format.Alignment = ParagraphAlignment.Left;
                hCell = hRow.Cells[1];
                hCell.AddParagraph(itemSet.AB);
                hCell.Format.Alignment = ParagraphAlignment.Center;
                hCell = hRow.Cells[2];

                hCell.AddParagraph("Исследование " + itemSet.Project);
                hCell.Format.Alignment = ParagraphAlignment.Right;
                hRow = hTable.AddRow();
                hCell = hRow.Cells[0];
                hCell.AddParagraph("Метод тестирования: " + itemSet.TestMethod);
                hCell.Format.Alignment = ParagraphAlignment.Left;
                hCell = hRow.Cells[2];
                hCell.AddParagraph("Сет:  " + itemSet.Set + " - " + "Антибиотик: " + itemSet.AB);
                hCell.Format.Alignment = ParagraphAlignment.Right;
                hRow = hTable.AddRow();
                hCell = hRow.Cells[0];
                hCell.AddParagraph("Дата печати: " + DateTime.Now.ToShortDateString());
                hCell.Format.Alignment = ParagraphAlignment.Left;
                Paragraph fPar = new Paragraph();
                fPar.AddText("Страница ");
                fPar.AddPageField();
                fPar.AddText(" из ");
                fPar.AddSectionPagesField();
                hCell = hRow.Cells[2];
                hCell.Add(fPar);
                hCell.Format.Alignment = ParagraphAlignment.Right;

                hCell = hTable.Rows[0].Cells[1];
                hCell.MergeDown = 2;

                hCell.Format.Font.Bold = true;
                hCell.Format.Font.Size = 9;
                hCell.Format.Alignment = ParagraphAlignment.Center;

                // Create table

                Table table;
                Row row;
                Cell cell;
                CreateMicTable(doc, itemSet, section, out table, out row, out cell);

                foreach (var item in itemSet.MOList)
                {
                    row = table.AddRow();
                    row.Height = "0.55cm";
                    cell = row.Cells[0];
                    cell.VerticalAlignment = VerticalAlignment.Center;
                    cell.AddParagraph(item.Cell);
                    cell = row.Cells[1];
                    cell.VerticalAlignment = VerticalAlignment.Center;
                    cell.AddParagraph(item.MuseumNumber);
                    cell = row.Cells[2];
                    cell.VerticalAlignment = VerticalAlignment.Center;
                    cell.AddParagraph(item.MO);
                    if (item.Number % 12 == 0)
                    {
                        row.Borders.Bottom.Width = "0.05cm";
                    }
                    if ((item.Number % 48 == 0) && (item.Number > 10))
                    {
                        doc.LastSection.Add(table);
                        doc.LastSection.AddPageBreak();
                        CreateMicTable(doc, itemSet, section, out table, out row, out cell);

                    }
                }

                foreach (var item in itemSet.ControlMOList)
                {
                    row = table.AddRow();
                    row.Height = "0.5cm";
                    cell = row.Cells[0];
                    cell.VerticalAlignment = VerticalAlignment.Center;
                    cell.AddParagraph(item.Cell);
                    cell.Shading.Color = Colors.LightGray;
                    cell = row.Cells[1];
                    cell.VerticalAlignment = VerticalAlignment.Center;
                    cell.AddParagraph(item.MuseumNumber);
                    cell.Shading.Color = Colors.LightGray;
                    cell = row.Cells[2];
                    cell.VerticalAlignment = VerticalAlignment.Center;
                    cell.Shading.Color = Colors.LightGray;
                    cell.AddParagraph(item.MO);

                }

                doc.LastSection.Add(table);

            }
            return doc;
        }
示例#42
0
        /// <summary>
        /// The write equation.
        /// </summary>
        /// <param name="equation">
        /// The equation.
        /// </param>
        public void WriteEquation(Equation equation)
        {
            Paragraph p = this.CurrentSection.AddParagraph();

            p.AddText("Equations are not supported.");
        }
示例#43
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());
        }
示例#44
0
文件: PDF.cs 项目: reaverDK/giganten
        private static void DefineCharts(Document document, string person, Dictionary <string, string[]> groups, DataHandler datahandler)
        {
            List <double[]> list  = new List <double[]>();
            List <String>   names = new List <string>();
            YearInfo        year  = datahandler.GetYear(datahandler.FirstAvailableYear);

            /***** Calculate series data ******/

            foreach (KeyValuePair <string, string[]> pair in groups)
            {
                String[] kgms        = pair.Value;
                double[] percentages = new double[12];
                names.Add(pair.Key);
                for (int i = 0; i < 12; i++)
                {
                    if (year[i] != null)
                    {
                        Salesman sm = year[i].GetSalesman(person);
                        if (sm != null)
                        {
                            percentages[i] = sm.PercentOfTotal(kgms);
                        }
                        else
                        {
                            percentages[i] = 0;
                        }
                    }
                    else
                    {
                        percentages[i] = 0;
                    }
                }
                list.Add(percentages);
            }

            double[] oms = new double[12];
            for (int i = 0; i < 12; i++)
            {
                if (year[i] != null)
                {
                    Salesman sm = year[i].GetSalesman(person);
                    if (sm != null)
                    {
                        oms[i] = sm.Omsaetning;
                    }
                    else
                    {
                        oms[i] = 0;
                    }
                }
                else
                {
                    oms[i] = 0;
                }
            }

            double[] ind = new double[12];
            for (int i = 0; i < 12; i++)
            {
                if (year[i] != null)
                {
                    Salesman sm = year[i].GetSalesman(person);
                    if (sm != null)
                    {
                        ind[i] = sm.Indtjening;
                    }
                    else
                    {
                        ind[i] = 0;
                    }
                }
                else
                {
                    ind[i] = 0;
                }
            }

            /***** Create chart for omsætning/indtjening series ******/

            MigraDoc.DocumentObjectModel.Paragraph paragraph = document.LastSection.AddParagraph("Sælger Diagram", "Heading1");
            Chart chart = new Chart();

            chart.Left   = 0;
            chart.Width  = Unit.FromCentimeter(22);
            chart.Height = Unit.FromCentimeter(15);

            MigraDoc.DocumentObjectModel.Shapes.Charts.Series series = chart.SeriesCollection.AddSeries();
            series.ChartType        = ChartType.Line;
            series.LineFormat.Width = 10;
            series.Add(oms);
            series.SetNull();
            series.Name = "Omsætning";

            series                  = chart.SeriesCollection.AddSeries();
            series.ChartType        = ChartType.Line;
            series.LineFormat.Width = 10;
            series.Add(ind);
            series.SetNull();
            series.Name = "Indtjening";

            XSeries xseries = chart.XValues.AddXSeries();

            xseries.Add(new string[] { "Maj", "Juni", "Juli", "Aug", "Sep", "Okt", "Nov", "Dec", "Jan", "Feb", "Marts", "April" });
            chart.XAxis.MajorTickMark = TickMarkType.Inside;
            chart.XAxis.Title.Caption = "MÅNEDER";

            chart.YAxis.MajorTickMark     = TickMarkType.Outside;
            chart.YAxis.MajorTickMark     = TickMarkType.Outside;
            chart.YAxis.HasMajorGridlines = true;

            chart.PlotArea.LineFormat.Color = MigraDoc.DocumentObjectModel.Colors.DarkGray;
            chart.PlotArea.LineFormat.Width = 1;
            chart.LeftArea.AddLegend();
            document.LastSection.Add(chart);

            /***** Create chart for KGM series ******/

            paragraph    = document.LastSection.AddParagraph("Sælger Diagram", "Heading1");
            chart        = new Chart();
            chart.Left   = 0;
            chart.Width  = Unit.FromCentimeter(22);
            chart.Height = Unit.FromCentimeter(15);

            for (int i = 0; i < list.Count; i++)
            {
                series                  = chart.SeriesCollection.AddSeries();
                series.ChartType        = ChartType.Line;
                series.LineFormat.Width = 10;
                series.Add(list[i]);
                series.SetNull();
                series.Name = names[i];
            }

            xseries = chart.XValues.AddXSeries();
            xseries.Add(new string[] { "Maj", "Juni", "Juli", "Aug", "Sep", "Okt", "Nov", "Dec", "Jan", "Feb", "Marts", "April" });
            chart.XAxis.MajorTickMark = TickMarkType.Inside;
            chart.XAxis.Title.Caption = "MÅNEDER";

            chart.YAxis.TickLabels.Format = "#0%";
            chart.YAxis.MajorTickMark     = TickMarkType.Outside;
            chart.YAxis.MajorTickMark     = TickMarkType.Outside;
            chart.YAxis.HasMajorGridlines = true;

            chart.PlotArea.LineFormat.Color = MigraDoc.DocumentObjectModel.Colors.DarkGray;
            chart.PlotArea.LineFormat.Width = 1;
            chart.LeftArea.AddLegend();
            document.LastSection.Add(chart);
        }
示例#45
0
 /// <summary>
 /// Adds a new paragraph to the section.
 /// </summary>
 public void Add(Paragraph paragraph)
 {
   this.Elements.Add(paragraph);
 }
示例#46
0
 /// <summary>
 /// Render shading into an existing paragraphd
 /// </summary>
 public void RenderInto(MigraDoc.DocumentObjectModel.Paragraph paragrapgh)
 {
     paragrapgh.Format.Shading.Color = this.color.GetColor();
 }
示例#47
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);
        }
示例#48
0
        /// <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");
        }
        private static MigraDoc.Rendering.PdfDocumentRenderer CreatePeopleListDocument(Person currentUser, List<PersonListViewModel> churchList, string documentType)
        {
            // Create new MigraDoc document
            Document document = new Document();
            document.Info.Title = documentType + " List for " + currentUser.Church.Name;
            document.Info.Author = "oikonomos";
            document.Info.Subject = documentType + " List";
            Section sec = document.AddSection();
            sec.PageSetup.TopMargin = Unit.FromCentimeter(1);
            sec.PageSetup.LeftMargin = Unit.FromCentimeter(1);
            document.DefaultPageSetup.TopMargin = Unit.FromCentimeter(1);
            document.DefaultPageSetup.LeftMargin = Unit.FromCentimeter(1);

            Paragraph p = new Paragraph();
            p.AddText(documentType + " List for " + currentUser.Church.Name);
            p.Format.Font.Size = 6.0;
            sec.Footers.Primary.Add(p);

            MigraDoc.DocumentObjectModel.Tables.Table table = new MigraDoc.DocumentObjectModel.Tables.Table();
            AddHeaders(table, documentType + "s");

            var style = document.Styles["Normal"];
            style.Font.Size = 8.0;
            TextMeasurement tm = new TextMeasurement(style.Font.Clone());
            int familyId = 0;
            foreach (PersonListViewModel person in churchList)
            {
                Row row=table.AddRow();
                Cell cell = row.Cells[0];
                if (familyId != person.FamilyId)
                {
                    cell.Format.Font.Bold = true;
                    cell.AddParagraph(AdjustIfTooWideToFitIn(cell, person.Surname, tm));
                }
                cell = row.Cells[1];
                cell.AddParagraph(AdjustIfTooWideToFitIn(cell, person.Firstname, tm));
                cell = row.Cells[2];
                if (familyId != person.FamilyId)
                {
                    cell.AddParagraph(AdjustIfTooWideToFitIn(cell, person.HomePhone ?? string.Empty, tm));
                }
                cell = row.Cells[3];
                cell.AddParagraph(AdjustIfTooWideToFitIn(cell, person.WorkPhone ?? string.Empty, tm));
                cell = row.Cells[4];
                cell.AddParagraph(AdjustIfTooWideToFitIn(cell, person.CellPhone ?? string.Empty, tm));
                cell = row.Cells[5];
                cell.AddParagraph(AdjustIfTooWideToFitIn(cell, person.Email ?? string.Empty, tm));
                familyId = person.FamilyId;
            }

            sec.Add(table);

            MigraDoc.Rendering.PdfDocumentRenderer pdfRender = new MigraDoc.Rendering.PdfDocumentRenderer(false, PdfSharp.Pdf.PdfFontEmbedding.Always);
            pdfRender.Document = document; //document is where all of my info has been written to and is a MigraDoc type
            pdfRender.RenderDocument();

            return pdfRender;
        }
示例#50
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);
        }
示例#51
0
        internal static void GiveBorders(Paragraph par)
        {
            Borders borders = par.Format.Borders;
            borders.Top.Color = Colors.Gray;
            borders.Top.Width = 4;
            borders.Top.Style = BorderStyle.DashDot;
            borders.Left.Color = Colors.Red;
            borders.Left.Style = BorderStyle.Dot;
            borders.Left.Width = 7;
            borders.Bottom.Color = Colors.Red;
            borders.Bottom.Width = 3;
            borders.Bottom.Style = BorderStyle.DashLargeGap;
            borders.Right.Style = BorderStyle.DashSmallGap;
            borders.Right.Width = 3;

            borders.DistanceFromBottom = "1cm";
            borders.DistanceFromTop = "1.5cm";

            borders.DistanceFromLeft = "0.5cm";
            borders.DistanceFromRight = "2cm";

            par.Format.Shading.Color = Colors.LightBlue;
        }
示例#52
0
 /// <summary>
 /// Render border into paragraph
 /// </summary>
 public void RenderInto(MigraDoc.DocumentObjectModel.Paragraph paragrapgh)
 {
     paragrapgh.Format.Borders.Width    = this.width;
     paragrapgh.Format.Borders.Distance = this.distance;
     paragrapgh.Format.Borders.Color    = this.color.GetColor();
 }
示例#53
0
    /// <summary>
    /// Initializes a ParagraphRenderer object for formatting.
    /// </summary>
    /// <param name="gfx">The XGraphics object to do measurements on.</param>
    /// <param name="paragraph">The paragraph to format.</param>
    /// <param name="fieldInfos">The field infos.</param>
    internal ParagraphRenderer(XGraphics gfx, Paragraph paragraph, FieldInfos fieldInfos)
      : base(gfx, paragraph, fieldInfos)
    {
      this.paragraph = paragraph;

      ParagraphRenderInfo parRenderInfo = new ParagraphRenderInfo();
      parRenderInfo.paragraph = this.paragraph;
      ((ParagraphFormatInfo)parRenderInfo.FormatInfo).widowControl = this.paragraph.Format.WidowControl;

      this.renderInfo = parRenderInfo;
    }
示例#54
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);
            }
        }
示例#55
0
    /// <summary>
    /// Returns an array of Paragraphs that are separated by parabreaks. Null if no parabreak is found.
    /// </summary>
    internal Paragraph[] SplitOnParaBreak()
    {
      if (this.elements == null)
        return null;

      int startIdx = 0;
      ArrayList paragraphs = new ArrayList();
      for (int idx = 0; idx < this.Elements.Count; ++idx)
      {
        DocumentObject element = this.Elements[idx];
        if (element is Character)
        {
          Character character = (Character)element;
          if (character.SymbolName == SymbolName.ParaBreak)
          {
            Paragraph paragraph = new Paragraph();
            paragraph.Format = this.Format.Clone();
            paragraph.Style = this.Style;
            paragraph.Elements = SubsetElements(startIdx, idx - 1);
            startIdx = idx + 1;
            paragraphs.Add(paragraph);
          }
        }
      }
      if (startIdx == 0) //No paragraph breaks given.
        return null;
      else
      {
        Paragraph paragraph = new Paragraph();
        paragraph.Format = this.Format.Clone();
        paragraph.Style = this.Style;
        paragraph.Elements = SubsetElements(startIdx, this.elements.Count - 1);
        paragraphs.Add(paragraph);

        return (Paragraph[])paragraphs.ToArray(typeof(Paragraph));
      }
    }
示例#56
0
        /// <summary>
        /// Defines page setup, headers, and footers.
        /// </summary>
        static void DefineContentSection(Document document, ArticlesWithWordMigra article)
        {
            Section section = document.AddSection();
            section.PageSetup.OddAndEvenPagesHeaderFooter = false;
            section.PageSetup.StartingNumber = 1;

            HeaderFooter header = section.Headers.Primary;
            header.AddParagraph(article.EditionName +"\t"+ article.Url);
                    
            // Create a paragraph with centered page number. See definition of style "Footer".
            Paragraph paragraph = new Paragraph();
            paragraph.AddTab();
            paragraph.AddPageField();

            // Add paragraph to footer for odd pages.
            section.Footers.Primary.Add(paragraph);
            
        }
示例#57
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);
        }
示例#58
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);
        }