Paragraphs
A Paragraph is the primary block container. Add one withdoc.AddParagraph(), then append text runs, images, or shapes. Paragraphs can be styled via ParagraphStyle.
Create a Simple Paragraph
Use case: Add a paragraph of body text to a document.
C#
1using Vega;
2using Vega.DOM;
3
4var doc = new VDocs();
5var p = doc.AddParagraph();
6p.AddText("Hello, world!");
7doc.SaveAsWord("hello.docx");
Multiple Paragraphs
Use case: Build a short multi-paragraph document.
C#
1doc.AddParagraph().AddText("First paragraph.");
2doc.AddParagraph().AddText("Second paragraph.");
3doc.AddParagraph().AddText("Third paragraph.");
Styled Paragraph
Use case: Apply a ParagraphStyle to control spacing and indentation.
C#
1var p = doc.AddParagraph();
2p.AddText("Indented, spaced paragraph.");
3p.Style = new ParagraphStyle
4{
5 Indent = new ParagraphIndentation
6 {
7 Left = new DocumentUnit(0.5, Units.inch),
8 FirstLine = new DocumentUnit(0.25, Units.inch),
9 },
10SpacingBetweenLines = new Spacing
11{
12 Before = 6.0,
13 After = 6.0,
14 Line = 1.15,
15}
16};
Paragraph with Inline Image
Use case: Insert a small logo inside a paragraph's flow.
C#
1var p = doc.AddParagraph();
2p.AddText("See our logo: ");
3p.AddImage("logo.png").SetDimensions(60, 30, Units.pt);
Related API
Frequently asked questions
How do I add a blank line between paragraphs?
Add an empty paragraph with doc.AddParagraph(), or use Spacing.Before/After on the following paragraph's style.
How do I insert a page break?
Add a new section with doc.AddSection() and set its SectionBreakType to SectionMarkValues.nextPage.
Can a paragraph contain both text and an image?
Yes. Use p.AddText(...) and p.AddImage(...) on the same paragraph.