ansi编码,保存test.bat
用来打印图片资料非常方便- #&cls&@ cd /d "%~dp0" & powershell -c "Get-Content '%~0' | Out-String | Invoke-Expression" &pause&exit
- cls
- [void][System.Reflection.Assembly]::LoadWithPartialName('System.Drawing')
- #函数 打印整个文件夹图片
- function Print-ImgList($img_dir,$filter){
- #读取图片
- $img_list = New-Object 'System.Collections.ArrayList'
- Get-ChildItem -Path $img_dir -Filter $filter | foreach { [void]$img_list.Add([System.Drawing.Image]::FromFile($_.FullName)) }
- #创建打印机
- $pd = New-Object 'System.Drawing.Printing.PrintDocument'
- #打印机设置
- $ps = New-Object 'System.Drawing.Printing.PrinterSettings'
- $ps.PrinterName = 'Microsoft Print to PDF'
- $ps.PrintToFile = $true
- $out_pdf = '{0}\{1}.pdf' -f $img_dir,[System.IO.Path]::GetFileName($img_dir).ToUpper()
- $ps.PrintFileName = $out_pdf
- $pd.PrinterSettings = $ps
- #打印方向 true横向 false纵向
- $pd.DefaultPageSettings.Landscape = $true
- #设置打印事件
- $pd.add_PrintPage({
- #打印首张图片
- $_.Graphics.DrawImage($img_list[0],$_.MarginBounds)
- $img_list[0].Dispose()
- $img_list.RemoveAt(0)
- if($img_list.Count -gt 0){ $_.HasMorePages = $true } else { $_.HasMorePages = $false }
- })
- $pd.add_EndPrint({
- Write-Host $out_pdf
- $pd.Dispose()
- Write-Host '--------------------'
- })
- #开始打印
- $pd.Print()
- }
- #遍历打印
- Get-ChildItem | Where-Object { [System.IO.Directory]::Exists($_.FullName)} | foreach {
- Write-Host $_.FullName
- Print-ImgList -img_dir $_.FullName -filter '*.jpg'
- }
复制代码
|