As there is no documentation on AppendField for python - I'm not sure what I am doing wrong.
- Code: Select all
bSec = doc.AddSection()
# Insert a 3-column header in the new section
# Column 0 -> Subject
# Column 1 -> Security
# Column 2 -> Version
header = bSec.HeadersFooters.Header
# Clear any existing paragraphs in the header:
bSec.HeadersFooters.Header.Paragraphs.Clear()
# Create a new table directly on the header, specifying True to enable the default borders or styles
hfTable = bSec.HeadersFooters.Header.AddTable(True)
# Define the table shape
hfTable.ResetCells(1, 3)
# Cell 0: Subject
subjectVal = doc.BuiltinDocumentProperties.Subject or "No Subject"
c0Para = hfTable.Rows[0].Cells[0].AddParagraph()
c0Para.AppendText(subjectVal)
# Cell 1: Security level
securityVal = data.get("security", {}).get("level", "Confidential")
c1Para = hfTable.Rows[0].Cells[1].AddParagraph()
c1Para.AppendText(securityVal)
# Cell 2: A doc variable field named "A1"
c2Para = hfTable.Rows[0].Cells[2].AddParagraph()
c2Para.AppendField("Version", FieldType.FieldDocVariable)
- Code: Select all
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "/workspaces/docgen/docgen/__main__.py", line 4, in <module>
main()
File "/workspaces/docgen/docgen/main.py", line 92, in main
doc.UpdateTableOfContents()
File "/home/vscode/.local/lib/python3.12/site-packages/plum/function.py", line 642, in __call__
return self.f(self.instance, *args, **kw_args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/vscode/.local/lib/python3.12/site-packages/plum/function.py", line 592, in __call__
return _convert(method(*args, **kw_args), return_type)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/vscode/.local/lib/python3.12/site-packages/spire/doc/Document.py", line 1285, in UpdateTableOfContents
CallCFunction(GetDllLibDoc().Document_UpdateTableOfContents,self.Ptr)
File "/home/vscode/.local/lib/python3.12/site-packages/spire/doc/common/__init__.py", line 129, in CallCFunction
raise SpireException(info)
spire.doc.common.SpireException: Cannot found font installed on the system.: at sprdv9..ctor() + 0x69d
at Spire.Doc.Layout.Fields.FieldOptions..ctor() + 0x64
at sprddy.sprc(sprc6g) + 0x3d
at sprddy.sprd(sprc6g) + 0x1c
at sprddy.sprl(sprddr) + 0x6a
at sprddy.spro(sprddr) + 0xbb
at sprddy.sprr(sprddr) + 0x5a
at sprddy.sprb(sprdds) + 0xa7
at sprddy.spra(sprdd1, sprdd1) + 0x5a
at sprddy.spra(DocumentObject, sprddy) + 0x57
at Spire.Doc.Document.sprc() + 0x4c
at Spire.Doc.Document.spra(Boolean, Boolean, ToPdfParameterList, sprevb) + 0x1d8
at Spire.Doc.Document.sprc(ToPdfParameterList) + 0x78
at Spire.Doc.Document.spra(List`1, Boolean) + 0x49
at Spire.Doc.Document.UpdateTableOfContents() + 0xa5
at Spire.Doc.AOT.NLDocument.Document_UpdateTableOfContents(IntPtr, IntPtr) + 0x51
Version is set elsewhere:
- Code: Select all
if version_in_json:
doc.Variables.Add("Version", version_in_json)
else:
logging.warning("Version not found in JSON metadata.")
doc.Variables.Add("Version", "---")
I've also tried:
- Code: Select all
# Cell 2: A doc variable field named "DocumentVersion"
version_style = ParagraphStyle(doc)
version_style.Name = "VersionStyle"
version_style.CharacterFormat.FontName = "Helvetica Neue"
doc.Styles.Add(version_style)
c2Para: Paragraph = hfTable.Rows[0].Cells[2].AddParagraph()
field = c2Para.AppendField("DocumentVersion", FieldType.FieldDocProperty)
field.ApplyCharacterFormat(version_style.CharacterFormat)
which causes the same font error:
- Code: Select all
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "/workspaces/docgen/docgen/__main__.py", line 4, in <module>
main()
File "/workspaces/docgen/docgen/main.py", line 98, in main
doc.UpdateTableOfContents()
File "/home/vscode/.local/lib/python3.12/site-packages/plum/function.py", line 642, in __call__
return self.f(self.instance, *args, **kw_args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/vscode/.local/lib/python3.12/site-packages/plum/function.py", line 592, in __call__
return _convert(method(*args, **kw_args), return_type)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/vscode/.local/lib/python3.12/site-packages/spire/doc/Document.py", line 1285, in UpdateTableOfContents
CallCFunction(GetDllLibDoc().Document_UpdateTableOfContents,self.Ptr)
File "/home/vscode/.local/lib/python3.12/site-packages/spire/doc/common/__init__.py", line 129, in CallCFunction
raise SpireException(info)
spire.doc.common.SpireException: Cannot found font installed on the system.: at sprdv9..ctor() + 0x69d
at Spire.Doc.Layout.Fields.FieldOptions..ctor() + 0x64
at sprddy.sprc(sprc6g) + 0x3d
at sprddy.sprd(sprc6g) + 0x1c
at sprddy.sprl(sprddr) + 0x6a
at sprddy.spro(sprddr) + 0xbb
at sprddy.sprr(sprddr) + 0x5a
at sprddy.sprb(sprdds) + 0xa7
at sprddy.spra(sprdd1, sprdd1) + 0x5a
at sprddy.spra(DocumentObject, sprddy) + 0x57
at Spire.Doc.Document.sprc() + 0x4c
at Spire.Doc.Document.spra(Boolean, Boolean, ToPdfParameterList, sprevb) + 0x1d8
at Spire.Doc.Document.sprc(ToPdfParameterList) + 0x78
at Spire.Doc.Document.spra(List`1, Boolean) + 0x49
at Spire.Doc.Document.UpdateTableOfContents() + 0xa5
at Spire.Doc.AOT.NLDocument.Document_UpdateTableOfContents(IntPtr, IntPtr) + 0x51
I've also tried
- Code: Select all
# Cell 2: A doc variable field named "DocumentVersion"
version_field_name = "DocumentVersion"
version_style = ParagraphStyle(doc)
version_style.Name = "VersionStyle"
version_style.CharacterFormat.FontName = "Helvetica Neue"
version_style.CharacterFormat.FontSize = 10
version_style.CharacterFormat.TextColor = Color.get_Crimson()
doc.Styles.Add(version_style)
version_field = hfTable.Rows[0].Cells[2].AddParagraph().AppendField(
version_field_name, FieldType.FieldDocProperty)
c2Para = version_field.OwnerParagraph
c2Para.ApplyStyle(version_style.Name)
Same error.
I've also tried
- Code: Select all
c2Para: Paragraph = hfTable.Rows[0].Cells[2].AddParagraph()
field = c2Para.AppendField(version_field_name, FieldType.FieldDocVariable)
field.Code = "DOCVARIABLE \"" + version_field_name+"\""
Same error.