Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save equinox79/2a78fe9e262d7bc3fa70fbd563b84256 to your computer and use it in GitHub Desktop.
Save equinox79/2a78fe9e262d7bc3fa70fbd563b84256 to your computer and use it in GitHub Desktop.
フォルダ内のdocxからpdf生成(pdfないものだけ)※右クリックして「Powershellで実行」
$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