This tool utilizes PowerShell to drive the Word COM interface, automating the conversion of .docx files to PDF. The workflow includes document cleanup (removing comments and hidden revisions), inserting a PBC stamp on the first page, and generating dynamic footers.
- Document Cleanup & Standardization:
- Executes
Comments.DeleteAll()to remove all comments. - Sets
ShowRevisionsAndComments = $falseto hide all tracked changes. - Automatically configures page margins (
BottomMargin: 15,FooterDistance: 16).
- Executes
- First-Page Stamp Insertion:
- Inserts
pbc_stamp.png(width set to 3.0cm) in the top-left corner of the first page. - Uses absolute positioning relative to the page (
Top: 10,Left: 20).
- Inserts
- Filename Parsing & Footer Generation:
- Parsing Logic: Extracts the string before the first underscore (
_) in the filename to use as the title. - Footer Layout:
- Left side: Static text
By Ariel Lin. - Right side: Displays
[Parsed Title] P.[Auto Page Number]. - Font: Times New Roman, Size 6.
- Left side: Static text
- Parsing Logic: Extracts the string before the first underscore (
- Input File:
ProjectA_2026_v1.docx - Process:
- Delete all comments and hide revision tracks.
- Extract
ProjectAas the unique identifier. - Place the PBC stamp in the top-left margin of the first page.
- Insert footer:
By Ariel Lin[Tab]ProjectA P.1.
- Output File:
ProjectA_2026_v1.pdf
- Language: PowerShell
- Key Technical Points:
- Word COM Object: Utilizes
New-Object -ComObject Word.Applicationfor background processing. - Unit Conversion: Defines
$cmToPoints = 28.35for precise coordinate mapping. - Page Object Model: Iterates through
Sections.Footersand usesShapes.AddPicturefor layout manipulation. - Field Codes: Uses
wdFieldPage(33) to insert dynamic page numbering.
- Word COM Object: Utilizes
- Place
pbc_stamp.pngin the same folder as the script. - Place the Word documents (
.docx) to be processed in the same folder. - Run the PowerShell script.
- The processed PDF files will be generated in the same directory.