[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[文件操作] 批处理怎么把多个目录内图片批量打印?

怎么把多个目录内图片批量打印,如10个文件夹内有上百个图片,如何一次性批量打印。救急

本帖最后由 ivor 于 2019-2-24 13:34 编辑

PS
  1. function print-image {
  2. param([string]$imageName = $(throw "Enter image name to print"),
  3.     [string]$printer = "",
  4.     [bool]$fitImageToPaper = $true)
  5. trap { break; }
  6. # check out Lee Holmes' blog(http://www.leeholmes.com/blog/HowDoIEasilyLoadAssembliesWhenLoadWithPartialNameHasBeenDeprecated.aspx)
  7. # on how to avoid using deprecated "LoadWithPartialName" function
  8. # To load assembly containing System.Drawing.Printing.PrintDocument
  9. [void][System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
  10. # Bitmap image to use to print image
  11. $bitmap = $null
  12. $doc = new-object System.Drawing.Printing.PrintDocument
  13. # if printer name not given, use default printer
  14. if ($printer -ne "") {
  15.   $doc.PrinterSettings.PrinterName = $printer
  16. }
  17. $doc.DocumentName = [System.IO.Path]::GetFileName($imageName)
  18. $doc.add_BeginPrint({
  19.   Write-Host "==================== $($doc.DocumentName) ===================="
  20. })
  21. # clean up after printing...
  22. $doc.add_EndPrint({
  23.   if ($bitmap -ne $null) {
  24.    $bitmap.Dispose()
  25.    $bitmap = $null
  26.   }
  27.   Write-Host "xxxxxxxxxxxxxxxxxxxx $($doc.DocumentName) xxxxxxxxxxxxxxxxxxxx"
  28. })
  29. # Adjust image size to fit into paper and print image
  30. $doc.add_PrintPage({
  31.   Write-Host "Printing $imageName..."
  32.   $g = $_.Graphics
  33.   $pageBounds = $_.MarginBounds
  34.   $img = new-object Drawing.Bitmap($imageName)
  35.   
  36.   $adjustedImageSize = $img.Size
  37.   $ratio = [double] 1;
  38.   
  39.   # Adjust image size to fit on the paper
  40.   if ($fitImageToPaper) {
  41.    $fitWidth = [bool] ($img.Size.Width > $img.Size.Height)
  42.    if (($img.Size.Width -le $_.MarginBounds.Width) -and
  43.     ($img.Size.Height -le $_.MarginBounds.Height)) {
  44.     $adjustedImageSize = new-object System.Drawing.SizeF($img.Size.Width, $img.Size.Height)
  45.    } else {
  46.     if ($fitWidth) {
  47.      $ratio = [double] ($_.MarginBounds.Width / $img.Size.Width);
  48.     } else {
  49.      $ratio = [double] ($_.MarginBounds.Height / $img.Size.Height)
  50.     }
  51.    
  52.     $adjustedImageSize = new-object System.Drawing.SizeF($_.MarginBounds.Width, [float]($img.Size.Height * $ratio))
  53.    }
  54.   }
  55.   # calculate destination and source sizes
  56.   $recDest = new-object Drawing.RectangleF($pageBounds.Location, $adjustedImageSize)
  57.   $recSrc = new-object Drawing.RectangleF(0, 0, $img.Width, $img.Height)
  58.   
  59.   # Print to the paper
  60.   $_.Graphics.DrawImage($img, $recDest, $recSrc, [Drawing.GraphicsUnit]"Pixel")
  61.   
  62.   $_.HasMorePages = $false; # nothing else to print
  63. })
  64. $doc.Print()
  65. }
  66. #修改图片路径在这里
  67. dir c:\*.jpg -Recurse | %{print-image $_}
复制代码

TOP

谢谢,辛苦了

TOP

返回列表