Created
November 24, 2021 06:49
-
-
Save equinox79/2a78fe9e262d7bc3fa70fbd563b84256 to your computer and use it in GitHub Desktop.
フォルダ内のdocxからpdf生成(pdfないものだけ)※右クリックして「Powershellで実行」
This file contains hidden or 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
$word = NEW-OBJECT -COMOBJECT WORD.APPLICATION | |
Write-Host "[フォルダ内のdocxからpdfを生成します]" | |
$files = Get-ChildItem | Where-Object{$_.Name -match "docx$"} | |
Write-Host "[変換開始]" | |
foreach($file in $files) | |
{ | |
try | |
{ | |
$result = (Test-Path $file.FullName.Replace(".docx",".pdf")) | |
if ($result) | |
{ | |
Write-Host "$($file.Name) ... スキップします" | |
}else{ | |
$doc = $word.Documents.OpenNoRepairDialog($file.FullName) | |
$doc.SaveAs([ref] $file.FullName.Replace(".docx",".pdf"),[ref] 17) | |
$doc.Close() | |
Write-Host "$($file.FullName.Replace(".docx",".pdf")) ... PDF出力済" | |
} | |
} | |
catch | |
{ | |
Write-Host "[ERROR]$($file.Name) ... 変換に失敗しました" | |
} | |
} | |
Write-Host "[変換終了]" | |
Pause | |
$word.Quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment