- 下載 docx2pdf
- 解壓縮後,將
docx2pdf.cmd
與docx2pdf.ps1
檔案放置於最上層目錄 - 執行
docx2pdf.cmd
Last active
February 27, 2025 09:09
-
-
Save lyshie/4abb0e723ccf7b5fecb1076aa7083e4a to your computer and use it in GitHub Desktop.
Batch convert docx/doc to pdf with powershell (課程計畫上傳PDF使用)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
powershell -noexit -executionpolicy bypass -File "docx2pdf.ps1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Original from: https://gist.github.com/alexisnomine/9408777 | |
# https://stackoverflow.com/questions/19683973 | |
# | |
# Author: lyshie ([email protected]) | |
$FilePath = Get-Location | |
$Files = Get-ChildItem -Path "$FilePath" -Filter "*.doc*" -Recurse | |
$Word = New-Object -ComObject Word.Application | |
Foreach ($File in $Files) { | |
Write-Host "[DOCX2PDF]" $File.FullName | |
# open a Word document, filename from the directory | |
$Doc = $Word.Documents.Open($File.FullName, $False, $True) | |
# Swap out DOCX/DOC with PDF in the Filename | |
$Name=($Doc.FullName) -replace '.doc(x)*?$', ".pdf" | |
# Save this File as a PDF in Word 2010/2013 | |
$Doc.SaveAs([ref] $Name, [ref] 17) | |
$Doc.Close([ref] [Microsoft.Office.Interop.Word.WdSaveOptions]::wdDoNotSaveChanges) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment