private void AddForm(Section section) { ParagraphStyle descriptionStyle = new ParagraphStyle(section.Document); descriptionStyle.Name = "description"; descriptionStyle.CharacterFormat.FontSize = 12; descriptionStyle.CharacterFormat.FontName = "Arial"; descriptionStyle.CharacterFormat.TextColor = Color.FromArgb(0x00, 0x45, 0x8e); section.Document.Styles.Add(descriptionStyle); Paragraph p1 = section.AddParagraph(); String text1 = "So that we can verify your identity and find your information, " + "please provide us with the following information. " + "This information will be used to create your online account. " + "Your information is not public, shared in anyway, or displayed on this site"; p1.AppendText(text1); p1.ApplyStyle(descriptionStyle.Name); Paragraph p2 = section.AddParagraph(); String text2 = "You must provide a real email address to which we will send your password."; p2.AppendText(text2); p2.ApplyStyle(descriptionStyle.Name); p2.Format.AfterSpacing = 8; //field group label style ParagraphStyle formFieldGroupLabelStyle = new ParagraphStyle(section.Document); formFieldGroupLabelStyle.Name = "formFieldGroupLabel"; formFieldGroupLabelStyle.ApplyBaseStyle("description"); formFieldGroupLabelStyle.CharacterFormat.Bold = true; formFieldGroupLabelStyle.CharacterFormat.TextColor = Color.White; section.Document.Styles.Add(formFieldGroupLabelStyle); //field label style ParagraphStyle formFieldLabelStyle = new ParagraphStyle(section.Document); formFieldLabelStyle.Name = "formFieldLabel"; formFieldLabelStyle.ApplyBaseStyle("description"); formFieldLabelStyle.ParagraphFormat.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Right; section.Document.Styles.Add(formFieldLabelStyle); //add table Table table = section.AddTable(); //2 columns of per row table.DefaultColumnsNumber = 2; //default height of row is 20point table.DefaultRowHeight = 20; //load form config data using (Stream stream = File.OpenRead(@"..\..\..\..\..\..\Data\Form.xml")) { XPathDocument xpathDoc = new XPathDocument(stream); XPathNodeIterator sectionNodes = xpathDoc.CreateNavigator().Select("/form/section"); foreach (XPathNavigator node in sectionNodes) { //create a row for field group label, does not copy format TableRow row = table.AddRow(false); row.Cells[0].CellFormat.BackColor = Color.FromArgb(0x00, 0x71, 0xb6); row.Cells[0].CellFormat.VerticalAlignment = VerticalAlignment.Middle; //label of field group Paragraph cellParagraph = row.Cells[0].AddParagraph(); cellParagraph.AppendText(node.GetAttribute("name", "")); cellParagraph.ApplyStyle(formFieldGroupLabelStyle.Name); XPathNodeIterator fieldNodes = node.Select("field"); foreach (XPathNavigator fieldNode in fieldNodes) { //create a row for field, does not copy format TableRow fieldRow = table.AddRow(false); //field label fieldRow.Cells[0].CellFormat.VerticalAlignment = VerticalAlignment.Middle; Paragraph labelParagraph = fieldRow.Cells[0].AddParagraph(); labelParagraph.AppendText(fieldNode.GetAttribute("label", "")); labelParagraph.ApplyStyle(formFieldLabelStyle.Name); fieldRow.Cells[1].CellFormat.VerticalAlignment = VerticalAlignment.Middle; Paragraph fieldParagraph = fieldRow.Cells[1].AddParagraph(); String fieldId = fieldNode.GetAttribute("id", ""); switch (fieldNode.GetAttribute("type", "")) { case "text": //add text input field TextFormField field = fieldParagraph.AppendField(fieldId, FieldType.FieldFormTextInput) as TextFormField; //set default text field.DefaultText = ""; field.Text = ""; break; case "list": //add dropdown field DropDownFormField list = fieldParagraph.AppendField(fieldId, FieldType.FieldFormDropDown) as DropDownFormField; //add items into dropdown. XPathNodeIterator itemNodes = fieldNode.Select("item"); foreach (XPathNavigator itemNode in itemNodes) { list.DropDownItems.Add(itemNode.SelectSingleNode("text()").Value); } break; case "checkbox": //add checkbox field fieldParagraph.AppendField(fieldId, FieldType.FieldFormCheckBox); break; } } //merge field group row. 2 columns to 1 column table.ApplyHorizontalMerge(row.GetRowIndex(), 0, 1); } } }
private void InsertContent(Section section) { //title Paragraph paragraph = section.AddParagraph(); TextRange title = paragraph.AppendText("Summary of Science"); title.CharacterFormat.Bold = true; title.CharacterFormat.FontName = "Arial"; title.CharacterFormat.FontSize = 14; paragraph.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center; paragraph.Format.AfterSpacing = 10; //style ParagraphStyle style1 = new ParagraphStyle(section.Document); style1.Name = "style1"; style1.CharacterFormat.FontName = "Arial"; style1.CharacterFormat.FontSize = 9; style1.ParagraphFormat.LineSpacing = 1.5F * 12F; style1.ParagraphFormat.LineSpacingRule = LineSpacingRule.Multiple; section.Document.Styles.Add(style1); ParagraphStyle style2 = new ParagraphStyle(section.Document); style2.Name = "style2"; style2.ApplyBaseStyle(style1.Name); style2.CharacterFormat.Font = new Font("Arial", 10f); section.Document.Styles.Add(style2); paragraph = section.AddParagraph(); paragraph.AppendText("(All text and pictures are from "); String link = "http://en.wikipedia.org/wiki/Science"; paragraph.AppendHyperlink(link, "Wikipedia", HyperlinkType.WebLink); paragraph.AppendText(", the free encyclopedia)"); paragraph.ApplyStyle(style1.Name); Paragraph paragraph1 = section.AddParagraph(); String str1 = "Science (from the Latin scientia, meaning \"knowledge\") " + "is an enterprise that builds and organizes knowledge in the form " + "of testable explanations and predictions about the natural world. " + "An older meaning still in use today is that of Aristotle, " + "for whom scientific knowledge was a body of reliable knowledge " + "that can be logically and rationally explained " + "(see \"History and etymology\" section below)."; paragraph1.AppendText(str1); //Insert a picture in the right of the paragraph1 DocPicture picture = paragraph1.AppendPicture(Image.FromFile(@"..\..\..\..\..\..\Data\Wikipedia_Science.png")); picture.TextWrappingStyle = TextWrappingStyle.Square; picture.TextWrappingType = TextWrappingType.Left; picture.VerticalOrigin = VerticalOrigin.Paragraph; picture.VerticalPosition = 0; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalAlignment = ShapeHorizontalAlignment.Right; paragraph1.ApplyStyle(style2.Name); Paragraph paragraph2 = section.AddParagraph(); String str2 = "Since classical antiquity science as a type of knowledge was closely linked " + "to philosophy, the way of life dedicated to discovering such knowledge. " + "And into early modern times the two words, \"science\" and \"philosophy\", " + "were sometimes used interchangeably in the English language. " + "By the 17th century, \"natural philosophy\" " + "(which is today called \"natural science\") could be considered separately " + "from \"philosophy\" in general. But \"science\" continued to also be used " + "in a broad sense denoting reliable knowledge about a topic, in the same way " + "it is still used in modern terms such as library science or political science."; paragraph2.AppendText(str2); paragraph2.ApplyStyle(style2.Name); Paragraph paragraph3 = section.AddParagraph(); String str3 = "The more narrow sense of \"science\" that is common today developed as a part " + "of science became a distinct enterprise of defining \"laws of nature\", " + "based on early examples such as Kepler's laws, Galileo's laws, and Newton's " + "laws of motion. In this period it became more common to refer to natural " + "philosophy as \"natural science\". Over the course of the 19th century, the word " + "\"science\" became increasingly associated with the disciplined study of the " + "natural world including physics, chemistry, geology and biology. This sometimes " + "left the study of human thought and society in a linguistic limbo, which was " + "resolved by classifying these areas of academic study as social science. " + "Similarly, several other major areas of disciplined study and knowledge " + "exist today under the general rubric of \"science\", such as formal science " + "and applied science."; paragraph3.AppendText(str3); paragraph3.ApplyStyle(style2.Name); }