Skip to content

iponaive/Word-PDF-Batch-AutoFooter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Word to PDF Batch Converter & Automated Page Processor PowerShell

English | 繁體中文

Demo

image

Introduction

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.

Core Features

  • Document Cleanup & Standardization:
    • Executes Comments.DeleteAll() to remove all comments.
    • Sets ShowRevisionsAndComments = $false to hide all tracked changes.
    • Automatically configures page margins (BottomMargin: 15, FooterDistance: 16).
  • 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).
  • 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.

Logic Example

  • Input File: ProjectA_2026_v1.docx
  • Process:
    1. Delete all comments and hide revision tracks.
    2. Extract ProjectA as the unique identifier.
    3. Place the PBC stamp in the top-left margin of the first page.
    4. Insert footer: By Ariel Lin [Tab] ProjectA P.1.
  • Output File: ProjectA_2026_v1.pdf

Technical Implementation

  • Language: PowerShell
  • Key Technical Points:
    • Word COM Object: Utilizes New-Object -ComObject Word.Application for background processing.
    • Unit Conversion: Defines $cmToPoints = 28.35 for precise coordinate mapping.
    • Page Object Model: Iterates through Sections.Footers and uses Shapes.AddPicture for layout manipulation.
    • Field Codes: Uses wdFieldPage (33) to insert dynamic page numbering.

Execution Steps

  1. Place pbc_stamp.png in the same folder as the script.
  2. Place the Word documents (.docx) to be processed in the same folder.
  3. Run the PowerShell script.
  4. The processed PDF files will be generated in the same directory.

About

Word-PDF-AutoFooter / Word 批次轉 PDF 暨自動化頁尾生成工具

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors