找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 24620|回复: 2

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

[复制链接]
发表于 2019-2-24 12:56:02 | 显示全部楼层 |阅读模式
怎么把多个目录内图片批量打印,如10个文件夹内有上百个图片,如何一次性批量打印。救急
发表于 2019-2-24 13:23:04 | 显示全部楼层
本帖最后由 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 $_}
复制代码
 楼主| 发表于 2019-2-27 14:08:50 | 显示全部楼层
谢谢,辛苦了
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-18 23:58 , Processed in 0.017056 second(s), 8 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表