Skip to content

Commit

Permalink
Merge branch 'master' into ReleasePreparation
Browse files Browse the repository at this point in the history
  • Loading branch information
falleretic committed Apr 6, 2023
2 parents 1857565 + 0ce27aa commit 71e0fac
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ private List<Paragraph> SelectTopicStarts()
return topicStartParas;
}

//ExStart:InsertSectionBreaks
/// <summary>
/// Insert section breaks before the specified paragraphs.
/// </summary>
Expand All @@ -86,6 +87,7 @@ private void InsertSectionBreaks(List<Paragraph> topicStartParas)
}
}
}
//ExEnd:InsertSectionBreaks

/// <summary>
/// Splits the current document into one topic per section and saves each topic
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Drawing;
using Aspose.Words;
using Aspose.Words.Loading;
using Aspose.Words.Settings;
Expand Down Expand Up @@ -156,5 +157,47 @@ public void SetPageSetupAndSectionFormatting()
doc.Save(ArtifactsDir + "WorkingWithDocumentOptionsAndSettings.SetPageSetupAndSectionFormatting.docx");
//ExEnd:DocumentBuilderSetPageSetupAndSectionFormatting
}

[Test]
public void PageBorderProperties()
{
//ExStart:PageBorderProperties
Document doc = new Document();

PageSetup pageSetup = doc.Sections[0].PageSetup;
pageSetup.BorderAlwaysInFront = false;
pageSetup.BorderDistanceFrom = PageBorderDistanceFrom.PageEdge;
pageSetup.BorderAppliesTo = PageBorderAppliesTo.FirstPage;

Border border = pageSetup.Borders[BorderType.Top];
border.LineStyle = LineStyle.Single;
border.LineWidth = 30;
border.Color = Color.Blue;
border.DistanceFromText = 0;

doc.Save(ArtifactsDir + "WorkingWithDocumentOptionsAndSettings.PageBorderProperties.docx");
//ExEnd:PageBorderProperties
}

[Test]
public void LineGridSectionLayoutMode()
{
//ExStart:LineGridSectionLayoutMode
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Enable pitching, and then use it to set the number of lines per page in this section.
// A large enough font size will push some lines down onto the next page to avoid overlapping characters.
builder.PageSetup.LayoutMode = SectionLayoutMode.LineGrid;
builder.PageSetup.LinesPerPage = 15;

builder.ParagraphFormat.SnapToGrid = true;

for (int i = 0; i < 30; i++)
builder.Write("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. ");

doc.Save(ArtifactsDir + "WorkingWithDocumentOptionsAndSettings.LinesPerPage.docx");
//ExEnd:LineGridSectionLayoutMode
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ internal class WorkingWithHeadersAndFooters : DocsExamplesBase
public void CreateHeaderFooter()
{
//ExStart:CreateHeaderFooterUsingDocBuilder
//ExStart:DifferentFirstPageHeaderFooter
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

Expand Down Expand Up @@ -44,6 +45,7 @@ public void CreateHeaderFooter()
builder.Write("Aspose.Words Header/Footer Creation Primer.");

builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary);
//ExEnd:DifferentFirstPageHeaderFooter

// We use a table with two cells to make one part of the text on the line (with page numbering).
// To be aligned left, and the other part of the text (with copyright) to be aligned right.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Aspose.Words;
using NUnit.Framework;
using System;

namespace DocsExamples.Programming_with_Documents
{
Expand Down Expand Up @@ -59,22 +60,19 @@ public void AppendSectionContent()
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.Writeln("Hello1");
doc.AppendChild(new Section(doc));
builder.Writeln("Hello22");
doc.AppendChild(new Section(doc));
builder.Writeln("Hello3");
doc.AppendChild(new Section(doc));
builder.Writeln("Hello45");
builder.Write("Section 1");
builder.InsertBreak(BreakType.SectionBreakNewPage);
builder.Write("Section 2");
builder.InsertBreak(BreakType.SectionBreakNewPage);
builder.Write("Section 3");

// This is the section that we will append and prepend to.
Section section = doc.Sections[2];

// This copies the content of the 1st section and inserts it at the beginning of the specified section.
// Insert the contents of the first section to the beginning of the third section.
Section sectionToPrepend = doc.Sections[0];
section.PrependContent(sectionToPrepend);

// This copies the content of the 2nd section and inserts it at the end of the specified section.
// Insert the contents of the second section to the end of the third section.
Section sectionToAppend = doc.Sections[1];
section.AppendContent(sectionToAppend);
//ExEnd:AppendSectionContent
Expand All @@ -97,9 +95,9 @@ public void CopySection()
Document dstDoc = new Document();

Section sourceSection = srcDoc.Sections[0];
Section newSection = (Section) dstDoc.ImportNode(sourceSection, true);
Section newSection = (Section)dstDoc.ImportNode(sourceSection, true);
dstDoc.Sections.Add(newSection);

dstDoc.Save(ArtifactsDir + "WorkingWithSection.CopySection.docx");
//ExEnd:CopySection
}
Expand All @@ -109,7 +107,7 @@ public void DeleteHeaderFooterContent()
{
//ExStart:DeleteHeaderFooterContent
Document doc = new Document(MyDir + "Document.docx");

Section section = doc.Sections[0];
section.ClearHeadersFooters();
//ExEnd:DeleteHeaderFooterContent
Expand All @@ -120,7 +118,7 @@ public void DeleteSectionContent()
{
//ExStart:DeleteSectionContent
Document doc = new Document(MyDir + "Document.docx");

Section section = doc.Sections[0];
section.ClearContent();
//ExEnd:DeleteSectionContent
Expand All @@ -133,13 +131,13 @@ public void ModifyPageSetupInAllSections()
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.Writeln("Hello1");
builder.Writeln("Section 1");
doc.AppendChild(new Section(doc));
builder.Writeln("Hello22");
builder.Writeln("Section 2");
doc.AppendChild(new Section(doc));
builder.Writeln("Hello3");
builder.Writeln("Section 3");
doc.AppendChild(new Section(doc));
builder.Writeln("Hello45");
builder.Writeln("Section 4");

// It is important to understand that a document can contain many sections,
// and each section has its page setup. In this case, we want to modify them all.
Expand All @@ -155,7 +153,7 @@ public void SectionsAccessByIndex()
{
//ExStart:SectionsAccessByIndex
Document doc = new Document(MyDir + "Document.docx");

Section section = doc.Sections[0];
section.PageSetup.LeftMargin = 90; // 3.17 cm
section.PageSetup.RightMargin = 90; // 3.17 cm
Expand All @@ -166,5 +164,66 @@ public void SectionsAccessByIndex()
section.PageSetup.TextColumns.Spacing = 35.4; // 1.25 cm
//ExEnd:SectionsAccessByIndex
}

[Test]
public void SectionChildNodes()
{
//ExStart:SectionChildNodes
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.Write("Section 1");
builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
builder.Write("Primary header");
builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary);
builder.Write("Primary footer");

Section section = doc.FirstSection;

// A Section is a composite node and can contain child nodes,
// but only if those child nodes are of a "Body" or "HeaderFooter" node type.
foreach (Node node in section)
{
switch (node.NodeType)
{
case NodeType.Body:
{
Body body = (Body)node;

Console.WriteLine("Body:");
Console.WriteLine($"\t\"{body.GetText().Trim()}\"");
break;
}
case NodeType.HeaderFooter:
{
HeaderFooter headerFooter = (HeaderFooter)node;

Console.WriteLine($"HeaderFooter type: {headerFooter.HeaderFooterType}:");
Console.WriteLine($"\t\"{headerFooter.GetText().Trim()}\"");
break;
}
default:
{
throw new Exception("Unexpected node type in a section.");
}
}
}
//ExEnd:SectionChildNodes
}

[Test]
public void EnsureMinimum()
{
//ExStart:EnsureMinimum
Document doc = new Document();

// If we add a new section like this, it will not have a body, or any other child nodes.
doc.Sections.Add(new Section(doc));
// Run the "EnsureMinimum" method to add a body and a paragraph to this section to begin editing it.
doc.LastSection.EnsureMinimum();

doc.Sections[0].Body.FirstParagraph.AppendChild(new Run(doc, "Hello world!"));
//ExEnd:EnsureMinimum
}
}
}

0 comments on commit 71e0fac

Please sign in to comment.