Word & layout

The author and revision attributes of the Word document—should they be preserved before exporting?

The core string attributes can be cleared, but the date attribute cannot be assigned None. Below, we retain the date and demonstrate only the cleaning of string

阅读文本 / Reading text
This paper uses synthetic samples to demonstrate the processing method. The code has been verified using examples in an isolated environment; this does not guarantee effectiveness for all real files or products. Before processing important files, please retain the original copies and verify them against the boundaries and acceptance criteria outlined in this document. Which problem does this paper address first? The core string attributes can be cleared, but the date attribute cannot be assigned None. Below, we retain the date and demonstrate only the cleaning of string fields and their deserialization; this is not a complete data desensitizer—annotations, revisions, body text, and custom attributes must be examined separately. self-contained synthetic example dependencies are listed in the import section. The code constructs inputs in memory; runtime logs are provided separately and do not constitute a guarantee for all real-world files. from docx import Document from io import BytesIO from datetime import datetime doc = Document() doc.core_properties.author = "Synthetic Author" doc.core_properties.title = "Synthetic Draft" doc.core_properties.created = datetime(2024, 6, 1) original_date = doc.core_properties.created for field in ("author", "title", "subject", "keywords", "comments", "last_modified_by"): setattr(doc.core_properties, field, "") stream = BytesIO() doc.save(stream) stream.seek(0) result = Document(stream) assert result.core_properties.author == "" assert result.core_properties.title == "" assert result.core_properties.created == original_date try: doc.core_properties.created = None except ValueError: pass else: raise AssertionError("date setter must not silently accept None") Metadata pitfalls before exporting to Word: Why clearing the author field is not enough When you use a script to batch-generate or convert Word documents, the most awkward moment is often not formatting errors, but rather when, after delivering the file to the client, they discover your local username, draft notes from testing, or even the title of a previous unrelated document in the file properties. python-docx provides core_properties An interface to read and write these Dublin Core standard properties, but it will not automatically perform any “sanitization” for you. More importantly, core_properties is only a small part of the document metadata; it does not include metadata for annotation authors, revision history, custom XML fields, or embedded objects. Clean up core_properties is equivalent to a full privacy scan and represents the most common misjudgment in engineering. This paper focuses on how to handle correctly and verifiably core_properties , and clearly define its boundaries. We do not provide a one-click data masking tool; instead, we offer a set of reproducible validation logic and acceptance criteria to help you establish reliable checkpoints within your automated workflows. synthesis example: Correct cleaning versus typical erroneous input Below is a fully self-contained synthetic example used to demonstrate core_properties the cleanup logic. Note: This code does not read actual files; all data is constructed in memory and is used solely to illustrate API behavior and boundary handling. If you need to process real documents, please prepare them yourself. .docx file path or byte stream object as Document() the parameters. Acceptance Checklist: What the code can do and what it cannot do check item code can handle requires manual intervention/other tools processing decision core_properties.author/title/comments and 13 other items ✅ ❌ is cleared or rewritten according to the type rules for author/initials in the annotation ❌ ✅ Iterate through doc.comments and process each one separately. Author information in the revision history ❌ ✅ must parse the w:ins/w:del XML nodes custom document properties (custom properties) ❌ ✅ Must be accessed via underlying XML or a dedicated library. embedded OLE object/image's EXIF/metadata ❌ ✅ requires a dedicated media processing library document template path or macro code ❌ ✅ checks settings and vbaProject last_printed and other non-sensitive but redundant fields ✅ ⚠️ Decide whether to retain in accordance with compliance requirements. This table clearly distinguishes core_properties The scope of . For example, even if you set core_properties.author is cleared, yet each comment in the document may still carry the original author’s name; the revision history may also fully preserve the editor’s identity. None of these are included in CoreProperties within the class’s jurisdiction. Therefore, any automated script claiming to have “cleared document metadata,” if it has only operated on core_properties , whose conclusions are all incomplete. During acceptance, the above table must be checked item by item, and for items marked with ✅ in the “Requires Manual/Other Tools” column, additional processing or review should be arranged. Reference and Next Step python-docx Document API Next steps: Add to your CI/CD or documentation publishing pipeline core_properties Verification steps shall use the assertion logic provided in this paper as the base template. At the same time, categorize your document types and develop specific SOPs for items listed in the above table as “requiring manual intervention/other tools.” Do not assume that cleaning has been completed. author is equivalent to achieving privacy protection—true security stems from a clear understanding of boundaries. uses this checklist for document translation Word translations often blur the distinction between content issues and formatting problems. Leave checks for styles, headers, tables, and other elements to the delivery checklist, so reviewers know where to look. OmniDoc (product entry point) provides an entry point for translating multi-format documents, and the official website highlights its OCR, terminology database, and bilingual comparison features. For teams that wish to start processing directly from files, this is a path worth evaluating with real-world samples. Please use de-identified files that you are authorized to upload, and verify the results against the checklist provided in this document; we do not claim that OmniDoc utilizes the open-source libraries or internal algorithms referenced herein, nor do we substitute examples for product performance testing. - 1 -
Updated 2026-10-09