本帖最后由 ivor 于 2019-4-17 17:42 编辑
保存为批处理运行,扫描批处理当前目录下面 =》子目录的所有JPG图片,然后打包成pdf,使用子目录名作为每个pdf文件名。- <# :
- @echo off
- rem 增强代码兼容性,代码保存为 ".bat"、".cmd"、".ps1"均可执行
- more +7 "%~f0" >"%~dpn0.ps1"
- powershell -ExecutionPolicy bypass -File "%~dpn0.ps1"
- del "%~dpn0.ps1" & pause & exit /b
- #>
- dir | ?{$_.GetType() -eq [System.IO.DirectoryInfo]} | %{$pdfPath=(Split-Path -Parent $MyInvocation.MyCommand.Definition)+"\"+$_.BaseName+".pdf"
- $word = New-Object -ComObject Word.Application
- $word.Visible = $false
- $objDoc = $word.Documents.Add()
- $objSelection = $Word.Selection
-
- dir *.jpg -path $_ | %{
- $objShape = $objSelection.InlineShapes.AddPicture($_.FullName)
- }
- Write-Host $pdfPath
- $objDoc.SaveAs([ref] $pdfPath, [ref] 17)
- $objDoc.Close(0)
- $word.Quit()
- }
复制代码
|