BATCH Prints images multiple times on one sheet
I got 1000 images in a folder and I want to resize and print 12 to 24 images per sheet. Using a BATCH script to collect images from a folder and output a HTML script with 3 columns and 6 lines per page, open in firefox (squeeze to fit and print).
how to add filename, date to each image in html script.
del "c:\zz.html"
setlocal EnableDelayedExpansion
set /a "p=1"
set /a "m=2"
set /a "w=4"
echo ^<table cellspacing="5" style="border:1px solid black;"^> >>"c:\zz.html"
for /f "delims=" %%i in ('dir /s/b /a-d f:\jpeg\mdl\*.jpg') do (
set /a "p=p+1"
echo !p!
if !p! == !m! (
set "bo=")
if !p! == !w! (
set "p=1"
set "bo=<tr>")
echo !bo!^<td^>^<img width=320 height=260 src="file:\\%%i"^> >>"c:\zz.html"
)
start C:\Program Files\Mozilla Firefox\firefox.exe "c:\zz.html" &exit
Here is some helpful code
del "c:\zz.html"
setlocal EnableDelayedExpansion
set /a "p=1"
set /a "m=2"
set /a "w=4"
echo ^<table cellspacing="5" style="border:1px solid black;"^> >>"c:\zz.html"
for /f "delims=" %%i in ( 'dir /s/b /a-d %1\*.*' ) do (
echo %1
set /a "p=p+1"
echo !p!
if !p! == !m! (
set "bo=")
if !p! == !w! (
set "p=1"
set "bo=<tr>")
echo !bo!^<td^>^<img width=320 height=260 src="file:\\%%i"^>^<br^>%%~nxi >>"c:\zz.html"
)
start I:\HEVC\m-oz\m.f -no-remote -profile "I:\HEVC\m-ozy" "c:\zz.html" &exit
This registry key grants click right to print any folder. (change the source folder as you like)
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\shell\==jam==j]
@="Print===ALL=IN=1=="
[HKEY_CLASSES_ROOT\Directory\shell\==jam==j\Command]
@="I:\\s\\PPP_Print\\p.cmd \"%1\""
source to share
I understand that you put a little effort into getting your project up and running, but you seem to need a lot of help. I appreciate your sharing of your progress. I think it makes you worthy of a Christmas present. :)
There are several questions in your question that I see.
1. I want to resize and print 12 to 24 images per sheet.
Pick one. Do you want 12 or 24? If you want the number to be variable depending on the height of the images you are printing, you are probably better off researching Imagemagick as suggested above.
2.Using a BATCH script to collect images from a folder and output a HTML script with 3 columns and 6 lines per page
3 * 6 = 18. Let him go with that. An 8.5 "x11" page will handle over 900 pixels high, so set the height of your table cells to 150 pixels. (150 * 6 = 900.)
3.open in firefox (shrink to match and print)
You can invoke the print dialog by including some JavaScript to invoke it window.print();
. You still need to click "Print".
4. how to add filename, date to each image in html script.
Let's assume that %%I
is a variable assigned to store the filenames in your loop for
. To get the basename.ext
file use %%~nxI
. To get the date and time when a file was last modified, use %%~tI
. See the last two pages help for
in the console window for more information on this syntax.
Use CSS position: absolute
for both your text and your images and the position: relative
elements td
that contain them. Either that, or you can load images as background images and just display the text in the line at the top. This requires you to configure Firefox to print background images that may not have been configured.
To fit 18 images per page, loop through the image files 18 at a time, then create an HTML table after the 18th image is found. In the CSS, add a declaration @media print
to ensure that each table causes a page break when printed. To generate your HTML, I suggest making the code clearer and easier to use in order to use the batch heredoc function .
Merry Christmas!
@echo off
setlocal enabledelayedexpansion
:: thumbnails.bat
:: generates print layout of *.jpg in current folder
:: https://stackoverflow.com/a/27652107/1683264
set "htmlfile=out.html"
call :heredoc head >"%htmlfile%" && goto end_head
<^!doctype "html">
<html>
<head>
<style type="text/css">
a { text-decoration: none; }
img {
max-width: 200px;
max-height: 150px;
position: absolute;
left: 0px;
bottom: 0px;
}
td {
border: 1px solid black;
position: relative;
width: 200px;
height: 150px;
}
span {
position: absolute;
left: 5px;
top: 5px;
color: purple;
font-family: "Times New Roman";
font-size: 11px;
background: rgba(255, 255, 255, 0.6);
top: 3px;
left: 3px;
}
@media print {
table { page-break-after: always; }
}
</style>
<script type="text/javascript">
addEventListener('load', function() { window.print(); }, false);
</script>
</head>
<body>
:end_head
set count=1
set images=
for %%I in (*.jpg) do (
set images=!images! "%%~fI"
if !count! equ 18 (
call :build_table !images:~1!
set images=
set count=0
)
set /a count+=1
)
if %count% gtr 1 call :build_table !images:~1!
call :heredoc body >>"%htmlfile%" && goto end_body
</body>
</html>
:end_body
start "" "firefox" -new-tab "file:///%CD:\=/%/%htmlfile%"
:: End of main script
goto :EOF
:build_table <img1> <img2> ... <img18>
setlocal enabledelayedexpansion
set count=1
for %%I in (%*) do (
set "src=%%~I"
set "img!count!=<a href="file:///!src:\=/!"><img src="file:///!src:\=/!" />"
set "desc!count!=<span>%%~nxI<br />%%~tI</span></a>"
set /a count+=1
)
call :heredoc table >>"%htmlfile%" && goto end_table
<table cellspacing="5">
<tr>
<td>!img1!!desc1!</td>
<td>!img2!!desc2!</td>
<td>!img3!!desc3!</td>
</tr>
<tr>
<td>!img4!!desc4!</td>
<td>!img5!!desc5!</td>
<td>!img6!!desc6!</td>
</tr>
<tr>
<td>!img7!!desc7!</td>
<td>!img8!!desc8!</td>
<td>!img9!!desc9!</td>
</tr>
<tr>
<td>!img10!!desc10!</td>
<td>!img11!!desc11!</td>
<td>!img12!!desc12!</td>
</tr>
<tr>
<td>!img13!!desc13!</td>
<td>!img14!!desc14!</td>
<td>!img15!!desc15!</td>
</tr>
<tr>
<td>!img16!!desc16!</td>
<td>!img17!!desc17!</td>
<td>!img18!!desc18!</td>
</tr>
</table>
:end_table
endlocal
goto :EOF
:: /questions/28435/heredoc-for-windows-batch/208449#208449
:heredoc <uniqueIDX>
setlocal enabledelayedexpansion
set go=
for /f "delims=" %%A in ('findstr /n "^" "%~f0"') do (
set "line=%%A" && set "line=!line:*:=!"
if defined go (if #!line:~1!==#!go::=! (goto :EOF) else echo(!line!)
if "!line:~0,13!"=="call :heredoc" (
for /f "tokens=3 delims=>^ " %%i in ("!line!") do (
if #%%i==#%1 (
for /f "tokens=2 delims=&" %%I in ("!line!") do (
for /f "tokens=2" %%x in ("%%I") do set "go=%%x"
)
)
)
)
)
goto :EOF
source to share