Quick Start
The snippet below builds a document with a styled paragraph, a table, an image, and a shape, then exports it to Word, PDF, and HTML — all from the same DOM.
C#
1using DOM;
2using DOM.Abstracts;
3using DOM.Elements.Graphics.Colors;
4using DOM.Elements.TableElements;
5using DOM.Enums;
6using DOM.MeasurementUnits;
7using DOM.Styles;
8
9// 1. Create the document
10using var doc = new VDocs
11{
12 LicensePath = "license.vegalic"
13};
14
15// 2. Add a styled paragraph
16var p = doc.AddParagraph();
17p.AddText("Hello ").Style = new TextStyle
18{
19 Font = new Font
20 {
21 Latin = new FontPart { FontName = "Calibri", Size = new FontSize(14), IsBold = true },
22 Color = Color.DarkBlue,
23 }
24};
25p.AddText("VDocs!");
26
27// 3. Add a table
28var table = new Table(2, 2);
29table[0, 0].AddText("Name");
30table[0, 1].AddText("Value");
31table[1, 0].AddText("Product");
32table[1, 1].AddText("VDocs");
33doc.AddTable(table);
34
35// 4. Add an image
36doc.AddImage("logo.png")
37.SetDimensions(120, 60, Units.Pt)
38.SetPosition(50, 50, Units.Pt);
39
40// 5. Export to all three formats
41doc.SaveAsWord("Sample.docx");
42doc.SaveAsPdf("Sample.pdf");
43doc.SaveAsHtml("Sample.html");
What's happening here?
- 1.
`new VDocs()`— Creates an empty document. `LicensePath` is optional. - 2.
`AddParagraph()`— Creates and appends a paragraph. Chained `AddText` adds styled runs. - 3.
`new Table(rows, cols)`— Creates a 2×2 table. Cells are accessed via `table[row, col]`. - 4.
`AddImage(path)`— Loads the image and returns it so you can size/position it. - 5.
`SaveAsWord / SaveAsPdf / SaveAsHtml`— Exports the same document to all three formats.
Frequently asked questions
Can I open an existing .docx and re-save it?
Yes — use VDocs.OpenFromWord("input.docx"). See the Word topic for a full example.
Where is the license path applied?
License validation happens inside SaveAs*. Assign LicensePath before calling any save/export method.
How do I reset content and rebuild?
Call doc.RemoveAllChildren() to clear the document body while keeping styles, page setup and settings.