Skip to content Skip to sidebar Skip to footer

Batch Multiple Image Printing On Single Sheet

I got 1000's of images on a folder & I wanna resize & print 12 to 24 images per sheet.Using BATCH script to collect images from a folder and output an HTML script with 3 co

Solution 1:

I recognize that you put a bit of effort into starting your project, but you appear to need lots of help. I appreciate your sharing your progress thusfar. I guess this makes you worthy of a Christmas present. :)

Your question has several component questions that I see.

1. I wanna resize & print 12 to 24 images per sheet.

Pick one. Do you want 12 or 24? If you want the number to be variable based on the height of the images you're printing, you'd probably be better off investigating Imagemagick as suggested above.

2. Using BATCH script to collect images from a folder and output an HTML script with 3 colums & 6 rows per page

3 * 6 = 18. Let's go with that. An 8.5"x11" page will handle a bit over 900px of height, so set the height of your table cells to 150px. (150 * 6 = 900.)

3. open in firefox (shrink to fit &print)

You can trigger the print dialog by including a bit of JavaScript to call window.print();. You still have to click "Print".

4. how to add filename, date on every image on html script.

Assume %%I is the variable assigned to capture filenames in your for loop. To get the basename.ext of a file, use %%~nxI. To get the file's last modified date and time, use %%~tI. See the last two pages of help for in a console window for more information on this syntax.

Use CSS position: absolute on both your text and your images, and position: relative on the td elements containing them. Either that, or you can load your images as background images and just display the text inline on top. This requires you to configure Firefox to print background images, which might not be configured, though.

To put 18 images on a page, loop through your image files 18 at a time, then generate an HTML table once the 18th image is found. In your CSS add a @media print declaration to ensure each table triggers a page break when printed. To generate your HTML, I suggest that it'd make your code a little more readable and easier to maintain, to employ a 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><styletype="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><scripttype="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!=<ahref="file:///!src:\=/!"><imgsrc="file:///!src:\=/!" />"
    set "desc!count!=<span>%%~nxI<br />%%~tI</span></a>"
    set /a count+=1
)
call :heredoc table >>"%htmlfile%" && goto end_table
        <tablecellspacing="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

:: https://stackoverflow.com/a/15032476/1683264
: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

Post a Comment for "Batch Multiple Image Printing On Single Sheet"