コード例 #1
0
        public void gerarRelatório(string option, DateTime data)
        {
            DocumentModel doc = new DocumentModel();
            Section       s   = new Section(doc);

            doc.Sections.Add(s);
            Paragraph intro = new Paragraph(doc);

            s.Blocks.Add(intro);
            Run introRun = new Run(doc, "Relatório de Veículos, com manutenções e locações, cada uma com suas respectivas datas.");

            intro.Inlines.Add(introRun);
            SpecialCharacter newline = new SpecialCharacter(doc, SpecialCharacterType.LineBreak);

            intro.Inlines.Add(newline);
            newline  = newline.Clone();
            introRun = new Run(doc, "Relatório da opção " + option +
                               option == "período" ? "no período dado por " + data.ToString() : "");
            intro.Inlines.Add(introRun);
            using (var ctx = new DadosContainer())
            {
                ctx.Attach(this);
                foreach (Histórico h in getHistóricos())
                {
                    Paragraph p = new Paragraph(doc);
                    s.Blocks.Add(p);
                    List <Locação> locs = h.getLocações().FindAll(l => comparaDatas(option, data, l.getInicio()) ||
                                                                  (l.acabou() && comparaDatas(option, data, l.getFim())));
                    List <Manutenção> mans = h.getManutenções().FindAll(m => comparaDatas(option, data, m.getInicio()) ||
                                                                        (m.acabou() && comparaDatas(option, data, m.getFim())));
                    Run run = new Run(doc, "Veículo " + h.Veículo.Id);
                    p.Inlines.Add(run);
                    p.Inlines.Add(newline);
                    newline = newline.Clone();
                    run     = new Run(doc, "Manutenções no período dado");
                    p.Inlines.Add(run);
                    p.Inlines.Add(newline);
                    newline = newline.Clone();
                    List <string> linhas;
                    foreach (Manutenção m in mans)
                    {
                        linhas = m.ToString().Split('\n').ToList();
                        foreach (string linha in linhas)
                        {
                            run = new Run(doc, linha);
                            p.Inlines.Add(run);
                            p.Inlines.Add(newline);
                            newline = newline.Clone();
                        }
                    }
                    run = new Run(doc, "Locações no período dado");
                    p.Inlines.Add(run);
                    p.Inlines.Add(newline);
                    newline = newline.Clone();
                    foreach (Locação l in locs)
                    {
                        linhas = l.ToString().Split('\n').ToList();
                        foreach (string linha in linhas)
                        {
                            run = new Run(doc, linha);
                            p.Inlines.Add(run);
                            p.Inlines.Add(newline);
                            newline = newline.Clone();
                        }
                    }
                }
            }
            doc.Save("relatorio.pdf");
        }
コード例 #2
0
        private Paragraph CreateIntroduction(RequestForQuotation rfq)
        {
            var firstName = rfq.ContactPerson.GetFirstName();

            firstName = firstName.Length > 0 ? " " + firstName : "";

            return(new Paragraph(
                       _document,
                       new Run(_document, $"{rfq.CompanyName}"),
                       _lineBreak,
                       new Run(_document, $"{rfq.Address}"),
                       _lineBreak.Clone(),
                       new Run(_document, $"{rfq.City}"),
                       _lineBreak.Clone(),
                       _lineBreak.Clone(),
                       _lineBreak.Clone(),
                       _lineBreak.Clone(),
                       new Run(_document, $"Hello{firstName},"),
                       _lineBreak.Clone(),
                       _lineBreak.Clone(),
                       new Run(_document,
                               "This is sample output from FormToPDF.")
                       ));
        }
コード例 #3
0
    static void Main()
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        DocumentModel document = new DocumentModel();

        document.DefaultCharacterFormat.FontName = "Arial";
        document.DefaultCharacterFormat.Size     = 16;

        SpecialCharacter lineBreakElement = new SpecialCharacter(document, SpecialCharacterType.LineBreak);

        document.Sections.Add(
            new Section(document,
                        new Paragraph(document,
                                      new Run(document, "All caps")
        {
            CharacterFormat = { AllCaps = true }
        },
                                      lineBreakElement,
                                      new Run(document, "Text with background color")
        {
            CharacterFormat = { BackgroundColor = Color.Cyan }
        },
                                      lineBreakElement.Clone(),
                                      new Run(document, "Bold text")
        {
            CharacterFormat = { Bold = true }
        },
                                      lineBreakElement.Clone(),
                                      new Run(document, "Text with borders")
        {
            CharacterFormat = { Border = new SingleBorder(BorderStyle.Single, Color.Red, 1) }
        },
                                      lineBreakElement.Clone(),
                                      new Run(document, "Double strikethrough text")
        {
            CharacterFormat = { DoubleStrikethrough = true }
        },
                                      lineBreakElement.Clone(),
                                      new Run(document, "Blue text")
        {
            CharacterFormat = { FontColor = Color.Blue }
        },
                                      lineBreakElement.Clone(),
                                      new Run(document, "Text with 'Consolas' font")
        {
            CharacterFormat = { FontName = "Consolas" }
        },
                                      lineBreakElement.Clone(),
                                      new Run(document, "Hidden text")
        {
            CharacterFormat = { Hidden = true }
        },
                                      lineBreakElement.Clone(),
                                      new Run(document, "Text with highlight color")
        {
            CharacterFormat = { HighlightColor = Color.Yellow }
        },
                                      lineBreakElement.Clone(),
                                      new Run(document, "Italic text")
        {
            CharacterFormat = { Italic = true }
        },
                                      lineBreakElement.Clone(),
                                      new Run(document, "Kerning is 15 points")
        {
            CharacterFormat = { Kerning = 15 }
        },
                                      lineBreakElement.Clone(),
                                      new Run(document, "Position is 3 points")
        {
            CharacterFormat = { Position = 3 }
        },
                                      lineBreakElement.Clone(),
                                      new Run(document, "Scale is 125%")
        {
            CharacterFormat = { Scaling = 125 }
        },
                                      lineBreakElement.Clone(),
                                      new Run(document, "Font size is 24 points")
        {
            CharacterFormat = { Size = 24 }
        },
                                      lineBreakElement.Clone(),
                                      new Run(document, "Small caps")
        {
            CharacterFormat = { SmallCaps = true }
        },
                                      lineBreakElement.Clone(),
                                      new Run(document, "Spacing is 3 point")
        {
            CharacterFormat = { Spacing = 3 }
        },
                                      lineBreakElement.Clone(),
                                      new Run(document, "Strikethrough text")
        {
            CharacterFormat = { Strikethrough = true }
        },
                                      lineBreakElement.Clone(),
                                      new Run(document, "Subscript text")
        {
            CharacterFormat = { Subscript = true }
        },
                                      lineBreakElement.Clone(),
                                      new Run(document, "Superscript text")
        {
            CharacterFormat = { Superscript = true }
        },
                                      lineBreakElement.Clone(),
                                      new Run(document, "Underline color is orange")
        {
            CharacterFormat = { UnderlineColor = Color.Orange, UnderlineStyle = UnderlineType.Single }
        },
                                      lineBreakElement.Clone(),
                                      new Run(document, "Underline style is double")
        {
            CharacterFormat = { UnderlineStyle = UnderlineType.Double }
        },
                                      lineBreakElement.Clone(),
                                      new Field(document, FieldType.Date, @"\@ ""dddd, d. MMMM yyyy""")
        {
            CharacterFormat = { Language = CultureInfo.GetCultureInfo("de-DE") }
        })));

        document.Save("Character Formatting.docx");
    }