If I place an author field in the document I create, and set the document author via BuiltInDocumentProperties.Author, and save as ODT, I find that the DocInformation:Created (Author) field is present in the output document, but I can’t get it to display the author name I supplied in BuiltInDocumentProperties.Author. Could it be that BuiltInDocumentProperties.Author is not translating to ODT?
Below is code that reproduces the problem.
static void doDoc()
{
Document _toDoc = new Document();
_toDoc.BuiltInDocumentProperties.Title = "hello";
_toDoc.BuiltInDocumentProperties.Author = "me";
_toDoc.BuiltInDocumentProperties.Pages = 1;
_toDoc.BuiltInDocumentProperties.NameOfApplication = "foo";
_toDoc.RemoveAllChildren(); // removes default section
Section _section = new Section(_toDoc);
_section.ClearHeadersFooters();
_toDoc.AppendChild(_section);
Body body = new Body(_toDoc);
_section.AppendChild(body);
_section.PageSetup.LeftMargin = 72.0;
_section.PageSetup.TopMargin = 72.0;
_section.PageSetup.RightMargin = 72.0;
_section.PageSetup.BottomMargin = 72.0;
_section.PageSetup.PageWidth = 612.0;
_section.PageSetup.PageHeight = 792.0;
_section.PageSetup.HeaderDistance = 20.0;
_section.PageSetup.FooterDistance = 20.0;
addParagraph(_toDoc, body);
_toDoc.Save("c:\\temp\\test.odt", SaveFormat.Odt);
}
static void addParagraph(Document _toDoc, Body body)
{
Paragraph asposePara = new Paragraph(_toDoc);
asposePara.ParagraphFormat.FirstLineIndent = 0.0;
asposePara.ParagraphFormat.LeftIndent = 0.0;
asposePara.ParagraphFormat.RightIndent = 0.0;
TabStop stop = new TabStop(36.0);
stop.Alignment = TabAlignment.Left;
asposePara.ParagraphFormat.TabStops.Add(stop);
asposePara.ParagraphFormat.Alignment = ParagraphAlignment.Left;
asposePara.ParagraphFormat.LineSpacing = 12.0;
asposePara.ParagraphFormat.SpaceAfter = 0.0;
asposePara.ParagraphFormat.SpaceBefore = 0.0;
body.AppendChild(asposePara);
Run asposeRun = new Run(_toDoc, "hello");
asposeRun.Font.Name = "Times New Roman";
asposeRun.Font.Size = 12.0;
asposePara.AppendChild(asposeRun);
DocumentBuilder builder = new DocumentBuilder(_toDoc);
builder.MoveTo(asposePara);
string fieldCode = @"SAVEDATE \@ ""MMMM d, yyyy"" \* MERGEFORMAT";
string fieldValue = DateTime.UtcNow.ToString("MMMM d, yyyy");
builder.InsertField(fieldCode, fieldValue);
fieldCode = @"AUTHOR \* MERGEFORMAT";
fieldValue = "Bartholomew";
builder.InsertField(fieldCode, fieldValue);
}