Beispiel #1
0
        //  [UnitTestFunction]
        public static void TestFields()
        {
            Document doc = new Document();

            doc.Info.Author = "K.P.";
            Section   sec = doc.Sections.AddSection();
            Paragraph par = sec.AddParagraph();

            par.AddBookmark("myBookmark1");

            PageRefField prf = par.AddPageRefField("myBookmark1");

            prf.Format = "ALPHABETIC";

            PageField pf = par.AddPageField();

            pf.Format = "ROMAN";

            SectionField sf = par.AddSectionField();

            sf.Format = "roman";

            SectionPagesField spf = par.AddSectionPagesField();

            spf.Format = "roman";

            NumPagesField npf = par.AddNumPagesField();

            npf.Format = "alphabetic";

            InfoField inf = par.AddInfoField(InfoFieldType.Author);
            DateField df  = par.AddDateField("D");

            df = par.AddDateField("d");
            df = par.AddDateField("s");
            df = par.AddDateField("r");
            df = par.AddDateField("G");
            df = par.AddDateField("dddd dd.MM.yyyy");

            DocumentRenderer docRndrr = new DocumentRenderer();

            docRndrr.Render(doc, "RtfFields.txt", null);

            File.Copy("RtfFields.txt", "RtfFields.rtf", true);
            System.Diagnostics.Process.Start("RtfFields.txt");
        }
        public static void Fields(string outputFile)
        {
            Document  document = new Document();
            Section   section  = document.AddSection();
            Paragraph par      = section.AddParagraph();

            par.AddText("Section: ");
            par.AddSectionField().Format = "ALPHABETIC";
            par.AddLineBreak();

            par.AddText("SectionPages: ");
            par.AddSectionField().Format = "alphabetic";
            par.AddLineBreak();

            par.AddText("Page: ");
            par.AddPageField().Format = "ROMAN";
            par.AddLineBreak();

            par.AddText("NumPages: ");
            par.AddNumPagesField();
            par.AddLineBreak();

            par.AddText("Date: ");
            par.AddDateField();
            par.AddLineBreak();

            par.AddText("Bookmark: ");
            par.AddBookmark("Egal");
            par.AddLineBreak();

            par.AddText("PageRef: ");
            par.AddPageRefField("Egal");

            PdfDocumentRenderer printer = new PdfDocumentRenderer()
            {
                Document = document
            };

            printer.RenderDocument(CancellationToken.None);
            printer.PdfDocument.Save(outputFile);
        }