static void CreateDocumentPaperSizes(C1WordDocument word) { // landscape for first page bool landscape = true; word.Landscape = landscape; // add title Font titleFont = new Font("Tahoma", 24, RtfFontStyle.Bold); Rect rc = WordUtils.PageRectangle(word); word.AddParagraph(Strings.PaperSizesFirstPage, titleFont); var paragraph = (RtfParagraph)word.Current; paragraph.BottomBorderColor = Colors.Purple; paragraph.BottomBorderStyle = RtfBorderStyle.Dotted; paragraph.BottomBorderWidth = 3.0f; // view warning Font warningFont = new Font("Arial", 14); word.AddParagraph(Strings.PaperSizesWarning, warningFont, Colors.Blue); // create constant font and StringFormat objects Font font = new Font("Tahoma", 18); StringFormat sf = new StringFormat(); sf.Alignment = HorizontalAlignment.Center; sf.LineAlignment = VerticalAlignment.Center; word.AddParagraph(string.Empty, font, Colors.Black); // create one page with each paper size foreach (PaperKind pk in Enum.GetValues(typeof(PaperKind))) { // skip custom page size if (pk == PaperKind.Custom) { continue; } // add new page for every page after the first one word.PageBreak(); // set paper kind and orientation var section = new RtfSection(pk); word.Add(section); landscape = !landscape; word.Landscape = landscape; // add some content on the page string text = string.Format(Strings.StringFormatTwoArg, pk, word.Landscape); word.AddParagraph(text); paragraph = (RtfParagraph)word.Current; paragraph.SetRectBorder(RtfBorderStyle.DashSmall, Colors.Aqua, 2.0f); word.AddParagraph(string.Empty); } }
//--------------------------------------------------------------------------------- #region ** paper sizes static void CreateDocumentPaperSizes(C1WordDocument word) { // landscape for first page bool landscape = true; word.Landscape = landscape; // add title Font titleFont = new Font("Tahoma", 24, RtfFontStyle.Bold); Rect rc = WordUtils.PageRectangle(word); word.AddParagraph(word.Info.Title, titleFont); var paragraph = (RtfParagraph)word.Current; paragraph.BottomBorderColor = Colors.Purple; paragraph.BottomBorderStyle = RtfBorderStyle.Dotted; paragraph.BottomBorderWidth = 3.0f; // create constant font and StringFormat objects Font font = new Font("Tahoma", 18); StringFormat sf = new StringFormat(); sf.Alignment = HorizontalAlignment.Center; sf.LineAlignment = VerticalAlignment.Center; word.AddParagraph("By default used Landscape A4", font); word.AddParagraph(string.Empty, font); // create one page with each paper size foreach (var fi in typeof(PaperKind).GetFields(BindingFlags.Static | BindingFlags.Public)) { // Silverlight/Phone doesn't have Enum.GetValues PaperKind pk = (PaperKind)fi.GetValue(null); // skip custom size if (pk == PaperKind.Custom) { continue; } // add new page for every page after the first one word.PageBreak(); // set paper kind and orientation var section = new RtfSection(pk); word.Add(section); landscape = !landscape; word.Landscape = landscape; // add some content on the page string text = string.Format("PaperKind: [{0}];\r\nLandscape: [{1}];\r\nFont: [Tahoma 18pt]", pk, word.Landscape); word.AddParagraph(text); paragraph = (RtfParagraph)word.Current; paragraph.SetRectBorder(RtfBorderStyle.DashSmall, Colors.Aqua, 2.0f); word.AddParagraph(string.Empty); } }
/** * Takes an Element subclass and returns the correct IRtfBasicElement * subclass, that wraps the Element subclass. * * @param element The Element to wrap * @return A IRtfBasicElement wrapping the Element * @throws DocumentException */ public IRtfBasicElement MapElement(IElement element) { IRtfBasicElement rtfElement = null; if (element is IRtfBasicElement) { rtfElement = (IRtfBasicElement)element; rtfElement.SetRtfDocument(this.rtfDoc); return(rtfElement); } switch (element.Type) { case Element.CHUNK: if (((Chunk)element).GetImage() != null) { rtfElement = new RtfImage(rtfDoc, ((Chunk)element).GetImage()); } else if (((Chunk)element).HasAttributes() && ((Chunk)element).Attributes.ContainsKey(Chunk.NEWPAGE)) { rtfElement = new RtfNewPage(rtfDoc); } else { rtfElement = new RtfChunk(rtfDoc, (Chunk)element); } break; case Element.PHRASE: rtfElement = new RtfPhrase(rtfDoc, (Phrase)element); break; case Element.PARAGRAPH: rtfElement = new RtfParagraph(rtfDoc, (Paragraph)element); break; case Element.ANCHOR: rtfElement = new RtfAnchor(rtfDoc, (Anchor)element); break; case Element.ANNOTATION: rtfElement = new RtfAnnotation(rtfDoc, (Annotation)element); break; case Element.IMGRAW: case Element.IMGTEMPLATE: case Element.JPEG: rtfElement = new RtfImage(rtfDoc, (Image)element); break; case Element.AUTHOR: case Element.SUBJECT: case Element.KEYWORDS: case Element.TITLE: case Element.PRODUCER: case Element.CREATIONDATE: rtfElement = new RtfInfoElement(rtfDoc, (Meta)element); break; case Element.LIST: rtfElement = new RtfList(rtfDoc, (List)element); break; case Element.LISTITEM: rtfElement = new RtfListItem(rtfDoc, (ListItem)element); break; case Element.SECTION: rtfElement = new RtfSection(rtfDoc, (Section)element); break; case Element.CHAPTER: rtfElement = new RtfChapter(rtfDoc, (Chapter)element); break; case Element.TABLE: try { rtfElement = new TB.RtfTable(rtfDoc, (Table)element); } catch (InvalidCastException) { rtfElement = new TB.RtfTable(rtfDoc, ((SimpleTable)element).CreateTable()); } break; } return(rtfElement); }