private static void Main(string[] args) { // Create document by specifying paper size and orientation, // and default language. var doc = new RtfDocument(PaperSize.A4, PaperOrientation.Portrait, Lcid.TraditionalChinese); // Create fonts and colors for later use var times = doc.createFont("Times New Roman"); var courier = doc.createFont("Courier New"); var red = doc.createColor(new Color("ff0000")); var blue = doc.createColor(new Color(0, 0, 255)); // Don't instantiate RtfTable, RtfParagraph, and RtfImage objects by using // ``new'' keyword. Instead, use add* method in objects derived from // RtfBlockList class. (See Demos.) RtfTable table; RtfParagraph par; RtfImage img; // Don't instantiate RtfCharFormat by using ``new'' keyword, either. // An addCharFormat method are provided by RtfParagraph objects. RtfCharFormat fmt; // ========================================================================== // Demo 5: Image // ========================================================================== //par = doc.addParagraph(); //par.Alignment = Align.Center; //img = doc.addImage("images/hellas.gif", ImageFileType.Gif); //// You may set the width only, and let the height be automatically adjusted //// to keep aspect ratio. ////img.Width = 130; //// Place the image on a new page. The ``StartNewPage'' property is also supported //// by paragraphs and tables. //img.StartNewPage = true; // ========================================================================== //// Demo 1: Font Setting //// ========================================================================== //// If you want to use Latin characters only, it is as simple as assigning //// ``Font'' property of RtfCharFormat objects. If you want to render Far East //// characters with some font, and Latin characters with another, you may //// assign the Far East font to ``Font'' property and the Latin font to //// ``AnsiFont'' property. This Demo contains Traditional Chinese characters. //// (Note: non-Latin characters are unicoded so you don't have to be worried.) //par = doc.addParagraph(); //par.DefaultCharFormat.Font = doc.createFont("標楷體"); //par.DefaultCharFormat.AnsiFont = courier; //par.setText("Demo1: 分別設定中英文字型"); // ========================================================================== // Demo 2: Character Formatting // ========================================================================== //par = doc.addParagraph(); //par.DefaultCharFormat.Font = times; //par.setText("Demo2: Character Formatting"); //// Besides setting default character formats of a paragraph, you can specify //// a range of characters to which formatting is applied. For convenience, //// let's call it range formatting. The following section sets formatting //// for the 4th, 5th, ..., 8th characters in the paragraph. (Note: the first //// character has an index of 0) //fmt = par.addCharFormat(4, 8); //fmt.FgColor = blue; //fmt.BgColor = red; //fmt.FontSize = 18; //// Sets another range formatting. Note that when range formatting overlaps, //// the latter formatting will overwrite the former ones. In the following, //// formatting for the 8th chacacter is overwritten. //fmt = par.addCharFormat(8, 10); //fmt.FontStyle.addStyle(FontStyleFlag.Bold); //fmt.FontStyle.addStyle(FontStyleFlag.Underline); //fmt.Font = courier; // ========================================================================== // Demo 3: Footnote // ========================================================================== //par = doc.addParagraph(); //par.setText("Demo3: Footnote"); //// In this example, the footnote is inserted just after the 7th character in //// the paragraph. //par.addFootnote(7).addParagraph().setText("Footnote details here."); // ========================================================================== // Demo 4: Header and Footer // ========================================================================== // You may use ``Header'' and ``Footer'' properties of RtfDocument objects to // specify information to be displayed in the header and footer of every page, // respectively. //par = doc.Footer.addParagraph(); //par.setText("Demo4: Page: / Date: Time:"); //par.Alignment = Align.Center; //par.DefaultCharFormat.FontSize = 15; //// You may insert control words, including page number, total pages, date and //// time, into the header and/or the footer. //par.addControlWord(12, RtfFieldControlWord.FieldType.Page); //par.addControlWord(13, RtfFieldControlWord.FieldType.NumPages); //par.addControlWord(19, RtfFieldControlWord.FieldType.Date); //par.addControlWord(25, RtfFieldControlWord.FieldType.Time); //// Here we also add some text in header. //par = doc.Header.addParagraph(); //par.setText("Demo4: Header"); // ========================================================================== // demo 6: 表格 // ========================================================================== // Please be careful when dealing with tables, as most crashes come from them. // If you follow steps below, the resulting RTF is not likely to crash your // MS Word. // // Step 1. Plan and draw the table you want on a scratch paper. // Step 2. Start with a MxN regular table. table = doc.addTable(5, 4, 415.2f, 12); table.Margins[Direction.Bottom] = 20; // Step 3. (Optional) Set text alignment for each cell, row height, column width, // border style, etc. for(var i = 0; i < table.RowCount; i++) { for(var j = 0; j < table.ColCount; j++) { table.cell(i, j).Alignment = Align.Left; table.cell(i, j).AlignmentVertical = AlignVertical.Middle; table.cell(i, j).addParagraph().setText("CELL " + i.ToString() + "," + j.ToString()); } } table.setInnerBorder(BorderStyle.Dotted, 1.5f); table.setOuterBorder(BorderStyle.Double, 3f); // Step 4. Merge cells so that the resulting table would look like the one you drew // on paper. One cell cannot be merged twice. In this way, we can construct // almost all kinds of tables we need. table.merge(1, 0, 4, 1); // Step 5. You may start inserting content for each cell. Actually, it is adviced // that the only thing you do after merging cell is inserting content. table.cell(1, 0).addParagraph().setText("Demo6: Table"); // ========================================================================== // Demo 7: ``Two in one'' format // ========================================================================== // This format is provisioned for Far East languages. This demo uses Traditional // Chinese as an example. //par = doc.addParagraph(); //par.setText("Demo7: aaa並排文字aaa"); //fmt = par.addCharFormat(10, 13); //fmt.TwoInOneStyle = TwoInOneStyle.Braces; //fmt.FontSize = 16; // ========================================================================== // Save // ========================================================================== // You may also retrieve RTF code string by calling to render() method of // RtfDocument objects. doc.save("Demo.rtf"); // ========================================================================== // Open the RTF file we just saved // ========================================================================== var p = new Process {StartInfo = {FileName = "Demo.rtf"}}; p.Start(); }
private void CreateRTF() { // Create document by specifying paper size and orientation, // and default language. var doc = new RtfDocument(PaperSize.A4, PaperOrientation.Portrait, Lcid.TraditionalChinese); var times = doc.createFont("Times New Roman"); var courier = doc.createFont("Arial"); var red = doc.createColor(new DW.RtfWriter.Color("ff0000")); var blue = doc.createColor(new DW.RtfWriter.Color(System.Drawing.Color.Navy)); // Don't instantiate RtfTable, RtfParagraph, and RtfImage objects by using // ``new'' keyword. Instead, use add* method in objects derived from // RtfBlockList class. (See Demos.) RtfTable table; RtfParagraph par; RtfImage img; // Don't instantiate RtfCharFormat by using ``new'' keyword, either. // An addCharFormat method are provided by RtfParagraph objects. RtfCharFormat fmt; // ========================================================================== // Demo 1: Font Setting // ========================================================================== // If you want to use Latin characters only, it is as simple as assigning // ``Font'' property of RtfCharFormat objects. If you want to render Far East // characters with some font, and Latin characters with another, you may // assign the Far East font to ``Font'' property and the Latin font to // ``AnsiFont'' property. This Demo contains Traditional Chinese characters. // (Note: non-Latin characters are unicoded so you don't have to be worried.) img = doc.addImage("images/hellas.gif", ImageFileType.Gif); img.Alignment = Align.Center; img.Width = 60; par = doc.addParagraph(); par.DefaultCharFormat.Font = doc.createFont("Arial"); par.DefaultCharFormat.FontSize = 11; par.DefaultCharFormat.FgColor = blue; par.DefaultCharFormat.AnsiFont = courier; par.DefaultCharFormat.FontStyle.addStyle(FontStyleFlag.Bold); par.Alignment = Align.Center; par.setText("ΕΛΛΗΝΙΚΗ ΔΗΜΟΚΡΑΤΙΑ\n ΥΠΟΥΡΓΕΙΟ ΕΡΓΑΣΙΑΣ, ΚΟΙΝΩΝΙΚΗΣ ΑΣΦΑΛΙΣΗΣ ΚΑΙ ΠΡΟΝΟΙΑΣ\n ΓΕΝΙΚΗ ΓΡΑΜΜΑΤΕΙΑ ΔΙΑΧΕΙΡΙΣΗΣ ΚΟΙΝΟΤΙΚΩΝ ΚΑΙ ΑΛΛΩΝ ΠΟΡΩΝ\n ΕΙΔΙΚΗ ΥΠΗΡΕΣΙΑ ΕΦΑΡΜΟΓΗΣ\nΣΥΓΧΡΗΜΑΤΟΔΟΤΟΥΜΕΝΩΝ ΕΝΕΡΓΕΙΩΝ ΑΠΟ ΤΟ ΕΚΤ"); par = doc.addParagraph(); fmt = par.addCharFormat(); fmt.FontStyle.addStyle(FontStyleFlag.Bold); par.Alignment = Align.Center; par.setText("\n\nΑΝΑΦΟΡΑ ΔΕΙΓΜΑΤΟΛΗΨΙΑΣ\n"); par = doc.addParagraph(); par.Alignment = Align.Center; par.setText(" ___________________________________________________________\n"); par = doc.addParagraph(); par.Alignment = Align.Center; par.setText("Ημερομηνία: " + this.CurrentProject.Date + " Ώρα: " + this.CurrentProject.Time); par = doc.addParagraph(); par.Alignment = Align.Center; par.setText(" ___________________________________________________________\n"); par = doc.addParagraph(); par.Alignment = Align.FullyJustify; par.setText("Πραγματοποιήθηκε δειγματοληψία, όπως προβλέπεται από το άρθρο 3 της υπ’ αριθμ. 37156/18953/ 20.05.2008 ΚΥΑ, σε πληθυσμό " + CurrentProject.NumOfItems.ToString() + " προγραμμάτων του έργου «" + CurrentProject.title + "». Ως αποτέλεσμα της δειγματοληψίας, επιλέχθηκε δείγμα " + CurrentProject.NumOfSamples.ToString() + " προγραμμάτων στα οποία θα πραγματοποιηθεί από την αρμόδια Μονάδα Ελέγχου της ΕΥΕ επιτόπιος έλεγχος για τη διαπίστωση της ορθής υλοποίηση των συγχρηματοδοτούμενων ενεργειών και την τήρηση των υποχρεώσεων των Αναδόχων σύμφωνα με το ισχύον θεσμικό πλαίσιο."); par = doc.addParagraph(); par.setText("\n\n"); par = doc.addParagraph(); par.DefaultCharFormat.FontStyle.addStyle(FontStyleFlag.Underline); par.Alignment = Align.Left; par.setText("Ρυθμίσεις δειγματοληψίας.\n\n"); par = doc.addParagraph(); par.Alignment = Align.FullyJustify; par.setText(CurrentProject.Settings + "\n\n"); par = doc.addParagraph(); par.DefaultCharFormat.FontStyle.addStyle(FontStyleFlag.Underline); par.Alignment = Align.Left; par.setText("Πίνακας επιλεγμένων δειγμάτων.\n"); int tablerows = CurrentProject.ResultItems.Count; int x = 1; table = doc.addTable(tablerows+1, 7, 415.2f, 9); table.Margins[Direction.Bottom] = 20; table.setInnerBorder(BorderStyle.Dotted, 1.5f); table.setOuterBorder(BorderStyle.Dotted, 3f); table.Alignment = Align.Left; for (var j = 0; j < table.ColCount; j++) { table.cell(0, j).AlignmentVertical = AlignVertical.Middle; table.cell(0, j).DefaultCharFormat.FontStyle.addStyle(FontStyleFlag.Bold); table.cell(0, j).DefaultCharFormat.FontSize = 9; } table.cell(0, 0).Width = 20; table.cell(0, 0).addParagraph().setText("Α/Α"); table.cell(0, 1).Width = 30; table.cell(0, 1).addParagraph().setText("Πράξη"); table.cell(0, 2).Width = 120; table.cell(0, 2).addParagraph().setText("Επωνυμία Φορέα"); table.cell(0, 3).Width = 35; table.cell(0, 3).addParagraph().setText("Υποέργο"); table.cell(0, 4).Width = 40; table.cell(0, 4).addParagraph().setText("Κωδ.Πρ."); table.cell(0, 5).Width = 120; table.cell(0, 5).addParagraph().setText("Τίτλος Πρ."); table.cell(0, 6).Width = 70; table.cell(0, 6).addParagraph().setText("Περιφέρεια"); for (var i = 1; i < table.RowCount; i++) { for (var j = 0; j < table.ColCount; j++) { table.cell(i, j).AlignmentVertical = AlignVertical.Middle; table.cell(i, j).DefaultCharFormat.FontSize = 8; } Item t = CurrentProject.ResultItems[i-1]; table.cell(i, 0).Width = 20; table.cell(i, 1).Width = 30; table.cell(i, 2).Width = 120; table.cell(i, 3).Width = 35; table.cell(i, 4).Width = 40; table.cell(i, 5).Width = 120; table.cell(i, 6).Width = 70; table.cell(i, 0).addParagraph().setText(x++.ToString()); table.cell(i, 1).addParagraph().setText(t.getProperty("praxi").value); table.cell(i, 2).addParagraph().setText(t.getProperty("eponimia").value); table.cell(i, 3).addParagraph().setText(t.getProperty("ypoergo").value); table.cell(i, 4).addParagraph().setText(t.getProperty("kod_programmatos").value); table.cell(i, 5).addParagraph().setText(t.getProperty("titlos_programmatos").value); table.cell(i, 6).addParagraph().setText(t.getProperty("periferia").value); } doc.save(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "/RECENT_SAMPLINGS/" + CurrentProject.Report()); }