public void PreProcessCulture() { //ExStart //ExFor:FieldOptions.PreProcessCulture //ExSummary:Shows how to set the preprocess culture. Document doc = new Document(MyDir + "Document.docx"); DocumentBuilder builder = new DocumentBuilder(doc); // Set the culture according to which some fields will format their displayed values. doc.FieldOptions.PreProcessCulture = new CultureInfo("de-DE"); Field field = builder.InsertField(" DOCPROPERTY CreateTime"); // The DOCPROPERTY field will display its result formatted according to the preprocess culture // we have set to German. The field will display the date/time using the "dd.mm.yyyy hh:mm" format. Assert.IsTrue(Regex.Match(field.Result, @"\d{2}[.]\d{2}[.]\d{4} \d{2}[:]\d{2}").Success); doc.FieldOptions.PreProcessCulture = CultureInfo.InvariantCulture; field.Update(); // After switching to the invariant culture, the DOCPROPERTY field will use the "mm/dd/yyyy hh:mm" format. Assert.IsTrue(Regex.Match(field.Result, @"\d{2}[/]\d{2}[/]\d{4} \d{2}[:]\d{2}").Success); //ExEnd doc = DocumentHelper.SaveOpen(doc); Assert.Null(doc.FieldOptions.PreProcessCulture); Assert.IsTrue(Regex.Match(doc.Range.Fields[0].Result, @"\d{2}[/]\d{2}[/]\d{4} \d{2}[:]\d{2}").Success); }
public void IncorrectStructureDoNotAdded() { Document doc = DocumentHelper.CreateDocumentFillWithDummyText(); DocumentBuilder builder = new DocumentBuilder(doc); //ExStart //ExFor:EditableRange.EditorGroup //ExFor:EditorType //ExSummary:Shows how to add editing group for editable ranges EditableRangeStart startRange1 = builder.StartEditableRange(); builder.Writeln("EditableRange_1_1"); builder.Writeln("EditableRange_1_2"); // Sets the editor for editable range region startRange1.EditableRange.EditorGroup = EditorType.Everyone; //ExEnd doc = DocumentHelper.SaveOpen(doc); // Assert that it's not valid structure and editable ranges aren't added to the current document NodeCollection startNodes = doc.GetChildNodes(NodeType.EditableRangeStart, true); Assert.AreEqual(0, startNodes.Count); NodeCollection endNodes = doc.GetChildNodes(NodeType.EditableRangeEnd, true); Assert.AreEqual(0, endNodes.Count); }
public void SetCellPaddings() { //ExStart //ExFor:CellFormat.SetPaddings //ExSummary:Shows how to set paddings to a table cell. DocumentBuilder builder = new DocumentBuilder(); builder.StartTable(); builder.CellFormat.Width = 300; builder.CellFormat.SetPaddings(5, 10, 40, 50); builder.RowFormat.HeightRule = HeightRule.Exactly; builder.RowFormat.Height = 50; builder.InsertCell(); builder.Write("Row 1, Col 1"); //ExEnd Document doc = DocumentHelper.SaveOpen(builder.Document); Table table = (Table)doc.GetChild(NodeType.Table, 0, true); Cell cell = table.Rows[0].Cells[0]; Assert.AreEqual(5, cell.CellFormat.LeftPadding); Assert.AreEqual(10, cell.CellFormat.TopPadding); Assert.AreEqual(40, cell.CellFormat.RightPadding); Assert.AreEqual(50, cell.CellFormat.BottomPadding); }
public void MarkCommentRepliesDone() { //ExStart //ExFor:Comment.Done //ExFor:CommentCollection //ExSummary:Shows how to mark comment as Done. Document doc = new Document(MyDir + "Comments.docx"); NodeCollection comments = doc.GetChildNodes(NodeType.Comment, true); Comment comment = (Comment)comments[0]; CommentCollection repliesCollection = comment.Replies; foreach (Comment childComment in repliesCollection) { if (!childComment.Done) { // Update comment reply Done mark childComment.Done = true; } } //ExEnd doc = DocumentHelper.SaveOpen(doc); comment = (Comment)doc.GetChildNodes(NodeType.Comment, true)[0]; repliesCollection = comment.Replies; foreach (Comment childComment in repliesCollection) { Assert.True(childComment.Done); } }
public void ApplyExistingListToParagraphs() { //ExStart //ExFor:ListCollection.Item(Int32) //ExSummary:Shows how to apply list formatting of an existing list to a collection of paragraphs. Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.Writeln("Paragraph 1"); builder.Writeln("Paragraph 2"); builder.Write("Paragraph 3"); NodeCollection paras = doc.GetChildNodes(NodeType.Paragraph, true); Assert.AreEqual(0, paras.Count(n => (n as Paragraph).ListFormat.IsListItem)); doc.Lists.Add(ListTemplate.NumberDefault); List list = doc.Lists[0]; foreach (Paragraph paragraph in paras.OfType <Paragraph>()) { paragraph.ListFormat.List = list; paragraph.ListFormat.ListLevelNumber = 2; } Assert.AreEqual(3, paras.Count(n => (n as Paragraph).ListFormat.IsListItem)); //ExEnd doc = DocumentHelper.SaveOpen(doc); paras = doc.GetChildNodes(NodeType.Paragraph, true); Assert.AreEqual(3, paras.Count(n => (n as Paragraph).ListFormat.IsListItem)); Assert.AreEqual(3, paras.Count(n => (n as Paragraph).ListFormat.ListLevelNumber == 2)); }
public void DefaultPaperTray() { //ExStart //ExFor:PageSetup.FirstPageTray //ExFor:PageSetup.OtherPagesTray //ExSummary:Shows how to change all sections in a document to use the default paper tray of the selected printer. Document doc = new Document(); // Find the printer that will be used for printing this document // In this case, it is the default printer // You can define a specific printer using PrinterName PrinterSettings settings = new PrinterSettings(); // The paper tray value stored in documents is completely printer specific // This means the code below resets all page tray values to use the current printers default tray // You can enumerate PrinterSettings.PaperSources to find the other valid paper tray values of the selected printer foreach (Section section in doc.Sections.OfType <Section>()) { section.PageSetup.FirstPageTray = settings.DefaultPageSettings.PaperSource.RawKind; section.PageSetup.OtherPagesTray = settings.DefaultPageSettings.PaperSource.RawKind; } //ExEnd foreach (Section section in DocumentHelper.SaveOpen(doc).Sections.OfType <Section>()) { Assert.AreEqual(settings.DefaultPageSettings.PaperSource.RawKind, section.PageSetup.FirstPageTray); Assert.AreEqual(settings.DefaultPageSettings.PaperSource.RawKind, section.PageSetup.OtherPagesTray); } }
public void ApplyNewListToParagraphs() { //ExStart //ExFor:ListCollection.Add(ListTemplate) //ExSummary:Shows how to create a list by applying a new list format to a collection of paragraphs. Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.Writeln("Paragraph 1"); builder.Writeln("Paragraph 2"); builder.Write("Paragraph 3"); NodeCollection paras = doc.GetChildNodes(NodeType.Paragraph, true); Assert.AreEqual(0, paras.Count(n => (n as Paragraph).ListFormat.IsListItem)); List list = doc.Lists.Add(ListTemplate.NumberUppercaseLetterDot); foreach (Paragraph paragraph in paras.OfType <Paragraph>()) { paragraph.ListFormat.List = list; paragraph.ListFormat.ListLevelNumber = 1; } Assert.AreEqual(3, paras.Count(n => (n as Paragraph).ListFormat.IsListItem)); //ExEnd doc = DocumentHelper.SaveOpen(doc); paras = doc.GetChildNodes(NodeType.Paragraph, true); Assert.AreEqual(3, paras.Count(n => (n as Paragraph).ListFormat.IsListItem)); Assert.AreEqual(3, paras.Count(n => (n as Paragraph).ListFormat.ListLevelNumber == 1)); }
public void StretchImagefitSizeLim() { Document doc = DocumentHelper.CreateTemplateDocumentWithDrawObjects("<<image [src.ImageStream] -fitSizeLim>>", ShapeType.TextBox); ImageTestClass imageStream = new ImageTestBuilder() .WithImageStream(new FileStream(mImage, FileMode.Open, FileAccess.Read)).Build(); BuildReport(doc, imageStream, "src", ReportBuildOptions.None); doc = DocumentHelper.SaveOpen(doc); NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true); foreach (Shape shape in shapes.OfType <Shape>()) { // Assert that the image is really insert in textbox Assert.IsNotNull(shape.Fill.ImageBytes); // Assert that textbox size are equal image size Assert.AreEqual(300.0d, shape.Height); Assert.AreEqual(300.0d, shape.Width); } }
public void FieldOptionsPreProcessCulture() { //ExStart //ExFor:FieldOptions.PreProcessCulture //ExSummary:Shows how to set the preprocess culture. Document doc = new Document(MyDir + "Document.docx"); DocumentBuilder builder = new DocumentBuilder(doc); doc.FieldOptions.PreProcessCulture = new CultureInfo("de-DE"); Field field = builder.InsertField(" DOCPROPERTY CreateTime"); // Conforming to the German culture, the date/time will be presented in the "dd.mm.yyyy hh:mm" format Assert.IsTrue(Regex.Match(field.Result, @"\d{2}[.]\d{2}[.]\d{4} \d{2}[:]\d{2}").Success); doc.FieldOptions.PreProcessCulture = CultureInfo.InvariantCulture; field.Update(); // After switching to the invariant culture, the date/time will be presented in the "mm/dd/yyyy hh:mm" format Assert.IsTrue(Regex.Match(field.Result, @"\d{2}[/]\d{2}[/]\d{4} \d{2}[:]\d{2}").Success); //ExEnd doc = DocumentHelper.SaveOpen(doc); Assert.Null(doc.FieldOptions.PreProcessCulture); Assert.IsTrue(Regex.Match(doc.Range.Fields[0].Result, @"\d{2}[/]\d{2}[/]\d{4} \d{2}[:]\d{2}").Success); }
public void ListDocument() { //ExStart //ExFor:ListCollection.Document //ExFor:ListCollection.Count //ExFor:ListCollection.Item(Int32) //ExFor:ListCollection.GetListByListId //ExFor:List.Document //ExFor:List.ListId //ExSummary:Shows how to verify owner document properties of lists. Document doc = new Document(); ListCollection lists = doc.Lists; Assert.AreEqual(doc, lists.Document); List list = lists.Add(ListTemplate.BulletDefault); Assert.AreEqual(doc, list.Document); Console.WriteLine("Current list count: " + lists.Count); Console.WriteLine("Is the first document list: " + (lists[0].Equals(list))); Console.WriteLine("ListId: " + list.ListId); Console.WriteLine("List is the same by ListId: " + (lists.GetListByListId(1).Equals(list))); //ExEnd doc = DocumentHelper.SaveOpen(doc); lists = doc.Lists; Assert.AreEqual(doc, lists.Document); Assert.AreEqual(1, lists.Count); Assert.AreEqual(1, lists[0].ListId); Assert.AreEqual(lists[0], lists.GetListByListId(1)); }
public void FormFieldFontFormatting() { //ExStart //ExFor:FormField //ExSummary:Shows how to formatting the entire FormField, including the field value. Document doc = new Document(MyDir + "Form fields.docx"); FormField formField = doc.Range.FormFields[0]; formField.Font.Bold = true; formField.Font.Size = 24; formField.Font.Color = Color.Red; formField.Result = "Aspose.FormField"; doc = DocumentHelper.SaveOpen(doc); Run formFieldRun = doc.FirstSection.Body.FirstParagraph.Runs[1]; Assert.AreEqual("Aspose.FormField", formFieldRun.Text); Assert.AreEqual(true, formFieldRun.Font.Bold); Assert.AreEqual(24, formFieldRun.Font.Size); Assert.AreEqual(Color.Red.ToArgb(), formFieldRun.Font.Color.ToArgb()); //ExEnd }
public void FieldOptionsUseInvariantCultureNumberFormat() { //ExStart //ExFor:FieldOptions.UseInvariantCultureNumberFormat //ExSummary:Shows how to format numbers according to the invariant culture. Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE"); Field field = builder.InsertField(" = 1234567,89 \\# $#,###,###.##"); field.Update(); // The combination of field, number format and thread culture can sometimes produce an unsuitable result Assert.IsFalse(doc.FieldOptions.UseInvariantCultureNumberFormat); Assert.AreEqual("$1234567,89 . ", field.Result); // We can set this attribute to avoid changing the whole thread culture just for numeric formats doc.FieldOptions.UseInvariantCultureNumberFormat = true; field.Update(); Assert.AreEqual("$1.234.567,89", field.Result); //ExEnd doc = DocumentHelper.SaveOpen(doc); Assert.False(doc.FieldOptions.UseInvariantCultureNumberFormat); TestUtil.VerifyField(FieldType.FieldFormula, " = 1234567,89 \\# $#,###,###.##", "$1.234.567,89", doc.Range.Fields[0]); }
public void CheckBox() { //ExStart //ExFor:StructuredDocumentTag.#ctor(DocumentBase, SdtType, MarkupLevel) //ExFor:StructuredDocumentTag.Checked //ExSummary:Show how to create and insert checkbox structured document tag. Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); StructuredDocumentTag sdtCheckBox = new StructuredDocumentTag(doc, SdtType.Checkbox, MarkupLevel.Inline); sdtCheckBox.Checked = true; // Insert content control into the document builder.InsertNode(sdtCheckBox); //ExEnd doc = DocumentHelper.SaveOpen(doc); NodeCollection sdts = doc.GetChildNodes(NodeType.StructuredDocumentTag, true); StructuredDocumentTag sdt = (StructuredDocumentTag)sdts[0]; Assert.AreEqual(true, sdt.Checked); Assert.That(sdt.XmlMapping.StoreItemId, Is.Empty); //Assert that this sdt has no StoreItemId }
public void FormFieldsWorkWithProperties() { //ExStart //ExFor:FormField //ExFor:FormField.Result //ExFor:FormField.Type //ExFor:FormField.Name //ExSummary:Shows how to work with form field name, type, and result. Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Use a DocumentBuilder to insert a combo box form field FormField comboBox = builder.InsertComboBox("MyComboBox", new[] { "One", "Two", "Three" }, 0); // Verify some of our form field's attributes Assert.AreEqual("MyComboBox", comboBox.Name); Assert.AreEqual(FieldType.FieldFormDropDown, comboBox.Type); Assert.AreEqual("One", comboBox.Result); //ExEnd doc = DocumentHelper.SaveOpen(doc); comboBox = doc.Range.FormFields[0]; Assert.AreEqual("MyComboBox", comboBox.Name); Assert.AreEqual(FieldType.FieldFormDropDown, comboBox.Type); Assert.AreEqual("One", comboBox.Result); }
public void AddCommentWithReply() { //ExStart //ExFor:Comment //ExFor:Comment.SetText(String) //ExFor:Comment.AddReply(String, String, DateTime, String) //ExSummary:Shows how to add a comment with a reply to a document. Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Create new comment Comment newComment = new Comment(doc, "John Doe", "J.D.", DateTime.Now); newComment.SetText("My comment."); // Add this comment to a document node builder.CurrentParagraph.AppendChild(newComment); // Add comment reply newComment.AddReply("John Doe", "JD", new DateTime(2017, 9, 25, 12, 15, 0), "New reply"); //ExEnd doc = DocumentHelper.SaveOpen(doc); Comment docComment = (Comment)doc.GetChild(NodeType.Comment, 0, true); Assert.AreEqual(1, docComment.Count); Assert.AreEqual(1, newComment.Replies.Count); Assert.AreEqual("\u0005My comment.\r", docComment.GetText()); Assert.AreEqual("\u0005New reply\r", docComment.Replies[0].GetText()); }
public void ClearTextFromStructuredDocumentTags() { //ExStart //ExFor:StructuredDocumentTag.Clear //ExSummary:Shows how to delete content of StructuredDocumentTag elements. Document doc = new Document(MyDir + "Structured document tags.docx"); NodeCollection sdts = doc.GetChildNodes(NodeType.StructuredDocumentTag, true); Assert.IsNotNull(sdts); foreach (StructuredDocumentTag sdt in sdts.OfType <StructuredDocumentTag>()) { sdt.Clear(); } //ExEnd doc = DocumentHelper.SaveOpen(doc); sdts = doc.GetChildNodes(NodeType.StructuredDocumentTag, true); Assert.AreEqual( "Enter any content that you want to repeat, including other content controls. You can also insert this control around table rows in order to repeat parts of a table.\r", sdts[0].GetText()); Assert.AreEqual("Click here to enter text.\f", sdts[2].GetText()); }
public void UseInvariantCultureNumberFormat() { //ExStart //ExFor:FieldOptions.UseInvariantCultureNumberFormat //ExSummary:Shows how to format numbers according to the invariant culture. Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE"); Field field = builder.InsertField(" = 1234567,89 \\# $#,###,###.##"); field.Update(); // Sometimes, fields may not format their numbers correctly under certain cultures. Assert.IsFalse(doc.FieldOptions.UseInvariantCultureNumberFormat); Assert.AreEqual("$1234567,89 . ", field.Result); // To fix this, we could change the culture for the entire thread. // Another way to fix this is to set this flag, // which gets all fields to use the invariant culture when formatting numbers. // This way allows us to avoid changing the culture for the entire thread. doc.FieldOptions.UseInvariantCultureNumberFormat = true; field.Update(); Assert.AreEqual("$1.234.567,89", field.Result); //ExEnd doc = DocumentHelper.SaveOpen(doc); Assert.False(doc.FieldOptions.UseInvariantCultureNumberFormat); TestUtil.VerifyField(FieldType.FieldFormula, " = 1234567,89 \\# $#,###,###.##", "$1.234.567,89", doc.Range.Fields[0]); }
public void DocumentBuilderInsertParagraph() { //ExStart //ExFor:DocumentBuilder.InsertParagraph //ExFor:ParagraphFormat.FirstLineIndent //ExFor:ParagraphFormat.Alignment //ExFor:ParagraphFormat.KeepTogether //ExFor:ParagraphFormat.AddSpaceBetweenFarEastAndAlpha //ExFor:ParagraphFormat.AddSpaceBetweenFarEastAndDigit //ExFor:Paragraph.IsEndOfDocument //ExSummary:Shows how to insert a paragraph into the document. Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Specify font formatting Font font = builder.Font; font.Size = 16; font.Bold = true; font.Color = Color.Blue; font.Name = "Arial"; font.Underline = Underline.Dash; // Specify paragraph formatting ParagraphFormat paragraphFormat = builder.ParagraphFormat; paragraphFormat.FirstLineIndent = 8; paragraphFormat.Alignment = ParagraphAlignment.Justify; paragraphFormat.AddSpaceBetweenFarEastAndAlpha = true; paragraphFormat.AddSpaceBetweenFarEastAndDigit = true; paragraphFormat.KeepTogether = true; // Using Writeln() ends the paragraph after writing and makes a new one, while Write() stays on the same paragraph builder.Writeln("A whole paragraph."); // We can use this flag to ensure that we are at the end of the document Assert.True(builder.CurrentParagraph.IsEndOfDocument); //ExEnd doc = DocumentHelper.SaveOpen(doc); Paragraph paragraph = doc.FirstSection.Body.FirstParagraph; Assert.AreEqual(8, paragraph.ParagraphFormat.FirstLineIndent); Assert.AreEqual(ParagraphAlignment.Justify, paragraph.ParagraphFormat.Alignment); Assert.True(paragraph.ParagraphFormat.AddSpaceBetweenFarEastAndAlpha); Assert.True(paragraph.ParagraphFormat.AddSpaceBetweenFarEastAndDigit); Assert.True(paragraph.ParagraphFormat.KeepTogether); Assert.AreEqual("A whole paragraph.", paragraph.GetText().Trim()); Font runFont = paragraph.Runs[0].Font; Assert.AreEqual(16.0d, runFont.Size); Assert.True(runFont.Bold); Assert.AreEqual(Color.Blue.ToArgb(), runFont.Color.ToArgb()); Assert.AreEqual("Arial", runFont.Name); Assert.AreEqual(Underline.Dash, runFont.Underline); }
public void IfElseWithoutData() { Document doc = new Document(MyDir + "Reporting engine template - If-else.docx"); BuildReport(doc, Common.GetEmptyManagers(), "m"); doc = DocumentHelper.SaveOpen(doc); Assert.AreEqual("You have chosen no items.\f", doc.GetText()); }
public void IndexOf() { Document doc = new Document(MyDir + "Reporting engine template - Index of.docx"); BuildReport(doc, Common.GetManagers(), "Managers"); doc = DocumentHelper.SaveOpen(doc); Assert.AreEqual("The names are: John Smith, Tony Anderson, July James\f", doc.GetText()); }
public void DocumentBuilderInsertParagraph() { //ExStart //ExFor:DocumentBuilder.InsertParagraph //ExFor:ParagraphFormat.FirstLineIndent //ExFor:ParagraphFormat.Alignment //ExFor:ParagraphFormat.KeepTogether //ExFor:ParagraphFormat.AddSpaceBetweenFarEastAndAlpha //ExFor:ParagraphFormat.AddSpaceBetweenFarEastAndDigit //ExFor:Paragraph.IsEndOfDocument //ExSummary:Shows how to insert a paragraph into the document. Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); Font font = builder.Font; font.Size = 16; font.Bold = true; font.Color = Color.Blue; font.Name = "Arial"; font.Underline = Underline.Dash; ParagraphFormat paragraphFormat = builder.ParagraphFormat; paragraphFormat.FirstLineIndent = 8; paragraphFormat.Alignment = ParagraphAlignment.Justify; paragraphFormat.AddSpaceBetweenFarEastAndAlpha = true; paragraphFormat.AddSpaceBetweenFarEastAndDigit = true; paragraphFormat.KeepTogether = true; // The "Writeln" method ends the paragraph after appending text // and then starts a new line, adding a new paragraph. builder.Writeln("Hello world!"); Assert.True(builder.CurrentParagraph.IsEndOfDocument); //ExEnd doc = DocumentHelper.SaveOpen(doc); Paragraph paragraph = doc.FirstSection.Body.FirstParagraph; Assert.AreEqual(8, paragraph.ParagraphFormat.FirstLineIndent); Assert.AreEqual(ParagraphAlignment.Justify, paragraph.ParagraphFormat.Alignment); Assert.True(paragraph.ParagraphFormat.AddSpaceBetweenFarEastAndAlpha); Assert.True(paragraph.ParagraphFormat.AddSpaceBetweenFarEastAndDigit); Assert.True(paragraph.ParagraphFormat.KeepTogether); Assert.AreEqual("Hello world!", paragraph.GetText().Trim()); Font runFont = paragraph.Runs[0].Font; Assert.AreEqual(16.0d, runFont.Size); Assert.True(runFont.Bold); Assert.AreEqual(Color.Blue.ToArgb(), runFont.Color.ToArgb()); Assert.AreEqual("Arial", runFont.Name); Assert.AreEqual(Underline.Dash, runFont.Underline); }
public void ParagraphSpacingAndIndents() { //ExStart //ExFor:ParagraphFormat.CharacterUnitLeftIndent //ExFor:ParagraphFormat.CharacterUnitRightIndent //ExFor:ParagraphFormat.CharacterUnitFirstLineIndent //ExFor:ParagraphFormat.LineUnitBefore //ExFor:ParagraphFormat.LineUnitAfter //ExSummary:Shows how to change paragraph spacing and indents. Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); ParagraphFormat format = doc.FirstSection.Body.FirstParagraph.ParagraphFormat; Assert.AreEqual(format.LeftIndent, 0.0d); //ExSkip Assert.AreEqual(format.RightIndent, 0.0d); //ExSkip Assert.AreEqual(format.FirstLineIndent, 0.0d); //ExSkip Assert.AreEqual(format.SpaceBefore, 0.0d); //ExSkip Assert.AreEqual(format.SpaceAfter, 0.0d); //ExSkip // Also ParagraphFormat.LeftIndent will be updated format.CharacterUnitLeftIndent = 10.0; // Also ParagraphFormat.RightIndent will be updated format.CharacterUnitRightIndent = -5.5; // Also ParagraphFormat.FirstLineIndent will be updated format.CharacterUnitFirstLineIndent = 20.3; // Also ParagraphFormat.SpaceBefore will be updated format.LineUnitBefore = 5.1; // Also ParagraphFormat.SpaceAfter will be updated format.LineUnitAfter = 10.9; builder.Writeln("Lorem ipsum dolor sit amet, consectetur adipiscing elit, " + "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."); builder.Write("测试文档测试文档测试文档测试文档测试文档测试文档测试文档测试文档测试" + "文档测试文档测试文档测试文档测试文档测试文档测试文档测试文档测试文档测试文档"); //ExEnd doc = DocumentHelper.SaveOpen(doc); format = doc.FirstSection.Body.FirstParagraph.ParagraphFormat; Assert.AreEqual(format.CharacterUnitLeftIndent, 10.0d); Assert.AreEqual(format.LeftIndent, 120.0d); Assert.AreEqual(format.CharacterUnitRightIndent, -5.5d); Assert.AreEqual(format.RightIndent, -66.0d); Assert.AreEqual(format.CharacterUnitFirstLineIndent, 20.3d); Assert.AreEqual(format.FirstLineIndent, 243.59d, 0.1d); Assert.AreEqual(format.LineUnitBefore, 5.1d, 0.1d); Assert.AreEqual(format.SpaceBefore, 61.1d, 0.1d); Assert.AreEqual(format.LineUnitAfter, 10.9d); Assert.AreEqual(format.SpaceAfter, 130.8d, 0.1d); }
public void CultureInfoPageSetupDefaults() { Thread.CurrentThread.CurrentCulture = new CultureInfo("en-us"); Document docEn = new Document(); // Assert that page defaults comply with current culture info. Section sectionEn = docEn.Sections[0]; Assert.AreEqual(72.0, sectionEn.PageSetup.LeftMargin); // 2.54 cm Assert.AreEqual(72.0, sectionEn.PageSetup.RightMargin); // 2.54 cm Assert.AreEqual(72.0, sectionEn.PageSetup.TopMargin); // 2.54 cm Assert.AreEqual(72.0, sectionEn.PageSetup.BottomMargin); // 2.54 cm Assert.AreEqual(36.0, sectionEn.PageSetup.HeaderDistance); // 1.27 cm Assert.AreEqual(36.0, sectionEn.PageSetup.FooterDistance); // 1.27 cm Assert.AreEqual(36.0, sectionEn.PageSetup.TextColumns.Spacing); // 1.27 cm // Change the culture and assert that the page defaults are changed. Thread.CurrentThread.CurrentCulture = new CultureInfo("de-de"); Document docDe = new Document(); Section sectionDe = docDe.Sections[0]; Assert.AreEqual(70.85, sectionDe.PageSetup.LeftMargin); // 2.5 cm Assert.AreEqual(70.85, sectionDe.PageSetup.RightMargin); // 2.5 cm Assert.AreEqual(70.85, sectionDe.PageSetup.TopMargin); // 2.5 cm Assert.AreEqual(56.7, sectionDe.PageSetup.BottomMargin); // 2 cm Assert.AreEqual(35.4, sectionDe.PageSetup.HeaderDistance); // 1.25 cm Assert.AreEqual(35.4, sectionDe.PageSetup.FooterDistance); // 1.25 cm Assert.AreEqual(35.4, sectionDe.PageSetup.TextColumns.Spacing); // 1.25 cm // Change page defaults. sectionDe.PageSetup.LeftMargin = 90; // 3.17 cm sectionDe.PageSetup.RightMargin = 90; // 3.17 cm sectionDe.PageSetup.TopMargin = 72; // 2.54 cm sectionDe.PageSetup.BottomMargin = 72; // 2.54 cm sectionDe.PageSetup.HeaderDistance = 35.4; // 1.25 cm sectionDe.PageSetup.FooterDistance = 35.4; // 1.25 cm sectionDe.PageSetup.TextColumns.Spacing = 35.4; // 1.25 cm docDe = DocumentHelper.SaveOpen(docDe); Section sectionDeAfter = docDe.Sections[0]; Assert.AreEqual(90.0, sectionDeAfter.PageSetup.LeftMargin); // 3.17 cm Assert.AreEqual(90.0, sectionDeAfter.PageSetup.RightMargin); // 3.17 cm Assert.AreEqual(72.0, sectionDeAfter.PageSetup.TopMargin); // 2.54 cm Assert.AreEqual(72.0, sectionDeAfter.PageSetup.BottomMargin); // 2.54 cm Assert.AreEqual(35.4, sectionDeAfter.PageSetup.HeaderDistance); // 1.25 cm Assert.AreEqual(35.4, sectionDeAfter.PageSetup.FooterDistance); // 1.25 cm Assert.AreEqual(35.4, sectionDeAfter.PageSetup.TextColumns.Spacing); // 1.25 cm }
public void SimpleCase() { Document doc = DocumentHelper.CreateSimpleDocument("<<[s.Name]>> says: <<[s.Message]>>"); MessageTestClass sender = new MessageTestClass("LINQ Reporting Engine", "Hello World"); BuildReport(doc, sender, "s", ReportBuildOptions.InlineErrorMessages); doc = DocumentHelper.SaveOpen(doc); Assert.AreEqual("LINQ Reporting Engine says: Hello World\f", doc.GetText()); }
public void StringFormat() { Document doc = DocumentHelper.CreateSimpleDocument( "<<[s.Name]:lower>> says: <<[s.Message]:upper>>, <<[s.Message]:caps>>, <<[s.Message]:firstCap>>"); MessageTestClass sender = new MessageTestClass("LINQ Reporting Engine", "hello world"); BuildReport(doc, sender, "s"); doc = DocumentHelper.SaveOpen(doc); Assert.AreEqual("linq reporting engine says: HELLO WORLD, Hello World, Hello world\f", doc.GetText()); }
public void PaperTrayForDifferentPaperType() { //ExStart //ExFor:PageSetup.FirstPageTray //ExFor:PageSetup.OtherPagesTray //ExSummary:Shows how to set up printing using different printer trays for different paper sizes. Document doc = new Document(); // Find the default printer that we will use for printing this document. // You can define a specific printer using the "PrinterName" property of the PrinterSettings object. PrinterSettings settings = new PrinterSettings(); // This is the tray we will use for pages in the "A4" paper size. int printerTrayForA4 = settings.PaperSources[0].RawKind; // This is the tray we will use for pages in the "Letter" paper size. int printerTrayForLetter = settings.PaperSources[1].RawKind; // Modify the PageSettings object of this section to get Microsoft Word to instruct the printer // to use one of the trays we identified above, depending on this section's paper size. foreach (Section section in doc.Sections.OfType <Section>()) { if (section.PageSetup.PaperSize == Aspose.Words.PaperSize.Letter) { section.PageSetup.FirstPageTray = printerTrayForLetter; section.PageSetup.OtherPagesTray = printerTrayForLetter; } else if (section.PageSetup.PaperSize == Aspose.Words.PaperSize.A4) { section.PageSetup.FirstPageTray = printerTrayForA4; section.PageSetup.OtherPagesTray = printerTrayForA4; } } //ExEnd foreach (Section section in DocumentHelper.SaveOpen(doc).Sections.OfType <Section>()) { if (section.PageSetup.PaperSize == Aspose.Words.PaperSize.Letter) { Assert.AreEqual(printerTrayForLetter, section.PageSetup.FirstPageTray); Assert.AreEqual(printerTrayForLetter, section.PageSetup.OtherPagesTray); } else if (section.PageSetup.PaperSize == Aspose.Words.PaperSize.A4) { Assert.AreEqual(printerTrayForA4, section.PageSetup.FirstPageTray); Assert.AreEqual(printerTrayForA4, section.PageSetup.OtherPagesTray); } } }
public void NumberFormat() { Document doc = DocumentHelper.CreateSimpleDocument( "<<[s.Value1]:alphabetic>> : <<[s.Value2]:roman:lower>>, <<[s.Value3]:ordinal>>, <<[s.Value1]:ordinalText:upper>>" + ", <<[s.Value2]:cardinal>>, <<[s.Value3]:hex>>, <<[s.Value3]:arabicDash>>"); NumericTestClass sender = new NumericTestBuilder() .WithValuesAndDate(1, 2.2, 200, null, DateTime.Parse("10.09.2016 10:00:00")).Build(); BuildReport(doc, sender, "s"); doc = DocumentHelper.SaveOpen(doc); Assert.AreEqual("A : ii, 200th, FIRST, Two, C8, - 200 -\f", doc.GetText()); }
public void PaperTrayForDifferentPaperType() { //ExStart //ExFor:PageSetup.FirstPageTray //ExFor:PageSetup.OtherPagesTray //ExSummary:Shows how to set up printing using different printer trays for different paper sizes. Document doc = new Document(); // Choose the default printer to be used for printing this document PrinterSettings settings = new PrinterSettings(); // This is the tray we will use for A4 paper size // This is the first tray in the paper sources collection int printerTrayForA4 = settings.PaperSources[0].RawKind; // The is the tray we will use for Letter paper size // This is the second tray in the paper sources collection int printerTrayForLetter = settings.PaperSources[1].RawKind; // Set the page tray used for each section based off the paper size used in the section foreach (Section section in doc.Sections.OfType <Section>()) { if (section.PageSetup.PaperSize == Aspose.Words.PaperSize.Letter) { section.PageSetup.FirstPageTray = printerTrayForLetter; section.PageSetup.OtherPagesTray = printerTrayForLetter; } else if (section.PageSetup.PaperSize == Aspose.Words.PaperSize.A4) { section.PageSetup.FirstPageTray = printerTrayForA4; section.PageSetup.OtherPagesTray = printerTrayForA4; } } //ExEnd foreach (Section section in DocumentHelper.SaveOpen(doc).Sections.OfType <Section>()) { if (section.PageSetup.PaperSize == Aspose.Words.PaperSize.Letter) { Assert.AreEqual(printerTrayForLetter, section.PageSetup.FirstPageTray); Assert.AreEqual(printerTrayForLetter, section.PageSetup.OtherPagesTray); } else if (section.PageSetup.PaperSize == Aspose.Words.PaperSize.A4) { Assert.AreEqual(printerTrayForA4, section.PageSetup.FirstPageTray); Assert.AreEqual(printerTrayForA4, section.PageSetup.OtherPagesTray); } } }
public void DefaultStyles() { Document doc = new Document(); doc.Styles.DefaultFont.Name = "PMingLiU"; doc.Styles.DefaultFont.Bold = true; doc.Styles.DefaultParagraphFormat.SpaceAfter = 20; doc.Styles.DefaultParagraphFormat.Alignment = ParagraphAlignment.Right; doc = DocumentHelper.SaveOpen(doc); Assert.IsTrue(doc.Styles.DefaultFont.Bold); Assert.AreEqual("PMingLiU", doc.Styles.DefaultFont.Name); Assert.AreEqual(20, doc.Styles.DefaultParagraphFormat.SpaceAfter); Assert.AreEqual(ParagraphAlignment.Right, doc.Styles.DefaultParagraphFormat.Alignment); }
public void CustomNamedAccess() { //ExStart //ExFor:DocumentPropertyCollection.Item(String) //ExFor:CustomDocumentProperties.Add(String,DateTime) //ExFor:DocumentProperty.ToDateTime //ExSummary:Shows how to create a custom document property which contains a date and time. Document doc = new Document(); doc.CustomDocumentProperties.Add("AuthorizationDate", DateTime.Now); Console.WriteLine($"Document authorized on {doc.CustomDocumentProperties["AuthorizationDate"].ToDateTime()}"); //ExEnd TestUtil.VerifyDate(DateTime.Now, DocumentHelper.SaveOpen(doc).CustomDocumentProperties["AuthorizationDate"].ToDateTime(), TimeSpan.FromSeconds(1)); }