跳到主要内容

Adding footer with date and company name

Create a document with footer containing date and company name. Used for standard document formatting: memos, reports, letters, and templates. Placed in the footer where current date is shown on one side and organization name on the other. This helps with document identification and simplifies versioning:

let doc = Api.GetDocument();

// Add main document content
let paragraph1 = Api.CreateParagraph();
paragraph1.AddText("This is the main document content with footer containing date and company name.");
doc.Push(paragraph1);

let paragraph2 = Api.CreateParagraph();
paragraph2.AddText("The footer will appear on all pages with company name on the left and date on the right.");
doc.Push(paragraph2);

// Add page break to demonstrate footer on multiple pages
let paragraph3 = Api.CreateParagraph();
paragraph3.AddPageBreak();
paragraph3.AddText("Second page content - footer remains consistent across all pages.");
doc.Push(paragraph3);

// Create footer
let section = doc.GetFinalSection();
let footer = section.GetFooter("default", true);

// Position date paragraph on the same line by using tabs
let footerParagraph = footer.GetElement(0);
footerParagraph.SetJc("left");
footerParagraph.SetFontFamily("Arial");
footerParagraph.SetFontSize(20);

// Add company name
footerParagraph.AddText("ONLYOFFICE Inc.");

footerParagraph.AddTabStop();
footerParagraph.AddTabStop();

// Add current date field
let range = footerParagraph.GetRange();
let endPos = range.GetEndPos();
range = footerParagraph.GetRange(endPos, endPos);
range.AddField('TIME \\@ "dddd, MMMM d, yyyy"');