Link to home
Start Free TrialLog in
Avatar of coerrace
coerrace

asked on

batch to append pictures in one file

Hello in other question you helped me with this script to convert pdf to jpg what does the script is just look inside c:\data for sub directories and look on each sub directory for pdf files and convert to pdf here is the original script script:

@echo off
forfiles /p "c:\data" /s /m *.pdf  /C "cmd /c echo @path ">junk.txt
for /f "tokens=1 delims=." %%F in ('type junk.txt') do (convert %%F.pdf" %%F.jpg")
del junk.txt

Open in new window


   Now when the pdf´s are converted are spitted in multiple jpg´s then to add all that jpg´s in one single file I want to use the same script with a minor modification but applying the technique described here:

http://linuxers.org/quick-tips/convert-pdf-file-single-image-using-imagemagickhttp://linuxers.org/quick-tips/convert-pdf-file-single-image-using-imagemagick

   I tested using like the article say:

convert image-* -append single_image.jpg

Open in new window


   And works perfect if you do the command manually then the technique n the article is correct, now I tried to modify the script above to make the batch using same script like this:

cd c:\
forfiles /p "c:\data" /s /m *.pdf  /C "cmd /c echo @path ">junk.txt
for /f "tokens=1 delims=." %%F in ('type junk.txt') do (convert %%F-* -append %%F.jpg")
del junk.txt

Open in new window


   And not work why not work or what is needed to add or modify to make work?

Thank you
Avatar of LHT_ST
LHT_ST

change the %%F.jpg to single_image.jpg and retry it.
Based on hat article, looks to me like this command:
convert image-* -append single_image.png

will take the RESULTS of your previous batch file (all those .jpg files) and stitch them together.
It does not START with the PDF.  For that use your original script.
Avatar of coerrace

ASKER

I need to name the file like the PDF source not just single_image.
Thank you
Example of what I thought article meant (cannot test)

@echo off
forfiles /p "c:\data" /s /m *.pdf  /C "cmd /c echo @path ">junk.txt
for /f "tokens=1 delims=." %%F in ('type junk.txt') do (convert %%F.pdf" %%F.jpg")
del junk.txt

REM stich together results
convert %%F-* -append %%F.jpg"

REM remove temp .jpgs
del %%F-*.jpg

Open in new window

Simply we used the script in hundred of directories and all is done converted from pdf to jpg but like I said the pdf conversion were in multiple jpgs:

@echo off
forfiles /p "c:\data" /s /m *.pdf  /C "cmd /c echo @path ">junk.txt
for /f "tokens=1 delims=." %%F in ('type junk.txt') do (convert %%F.pdf" %%F.jpg")
del junk.txt

Open in new window


   Now like we executed the script here is no way to back and we need now to join all the correspondent sequence of jpgs to the source pdf in one file like the article say and I modded the script like I pasted:

cd c:\
forfiles /p "c:\data" /s /m *.pdf  /C "cmd /c echo @path ">junk.txt
for /f "tokens=1 delims=." %%F in ('type junk.txt') do (convert %%F-* -append %%F.jpg")
del junk.txt

Open in new window


   I changed from:

convert %%F.pdf" %%F.jpg

Open in new window


to:

convert %%F-* -append %%F.jpg

Open in new window


   And not work and is the same format the article use. What I need to modify there to make work?
Thank you
Korbus exactly is what I used and not work I sued the same if you see:

convert %%F-* -append %%F.jpg

Open in new window


And not work any other mod?
Avatar of sarabande
why did you use a minus character after %%F ?

to understand what happens in the moment you may replace the 'convert' command by 'echo'.

I need to name the file like the PDF source not just single_image.
how should that work if you have different files which you would merge into one file? if the first file is xxx.pdf and the second file is yyy.pdf how will you name the jpg file? xxx.jpg or yyy.jpg?

in my opinion you just could make your batch like

@echo off
if NOT EXIST "%1" GOTO :EOF
for /F %%F in ("%1") DO (convert "%1"\*.pdf -append %%~nF.jpg)

Open in new window



this would name the jpg like the subdirectory name of the path you pass as argument to the batch file.

Sara
look this is the original post where the main pdf to jpg worked and is the main original script I posted:

http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/Q_28487439.html#a40232102

   i don't want to take the name of the directory if you see the main script goal was to convert from pdf to jpg is ok but that conversion left form slme PDFs multiple pdfs for one pdf and that files like the article say it works manually to join the files:

http://linuxers.org/quick-tips/convert-pdf-file-single-image-using-imagemagick

   But I want to use this script specifi no other way to change:

@echo off
forfiles /p "c:\data" /s /m *.pdf  /C "cmd /c echo @path ">junk.txt
for /f "tokens=1 delims=." %%F in ('type junk.txt') do (convert %%F.pdf" %%F.jpg")
del junk.txt

Open in new window


   worked perfect to convert from pdf to jpg reading su directories like these:
c:\data\one, c:\two and so on with hundred of directories with inside of c:\data then the conversion is TO CONVERT THE PDF TO JOG BUT THE DESTINATION JPG MUST HAVE THE NAME OF THE ORIGINAL PDF WHERE WAS CREATED not the name of the subdirectory and to join all jogs in one file I want to use the original name of the PDF like reference because all jogs has at the beginning the name of the source file our PDF in this case and then the minus, etc. like the article say. And the script I pasted works perfect for conversion and search for pdf names in their routes the I just want to modify the script I pasted here but now to convert just taking names of the PDFs that the script search and then apply the command convert but with the append function:

convert %%F.pdf" %%F.jpg"

Open in new window

to apply to similar like

convert %%F-* -append %%F.jpg

Open in new window

I know this not work for the minus you said but if there is a way to fix the script to work without alter the function and the purpose of why was made of read from c:\data and process al subdirectories there looking for files pdfs and convert to jogs just the modification now is instead of convert to jpgs just will take the name of the pdfs in this case %%F and use append to join all the jpgs with resulting name of the PDF source in other words %%F.jpg but something not work like you said for the minus or don't know what could be the fix then to the same script?
Thank you
Gosh, please use punctuation characters!

Since you had the errornous
   convert %%F.pdf" %%F.jpg"
your resulting files all have a leading blank, like in " ThisIsTheFileName.jpg". Probably
   convert " %%F-*" -append %%F.jpg
will work then.
convert "%%F-*" -append %%F.jpg 

Open in new window

not work give a lot of errors like this  unable to open image
I cannot see you specifying the leading blank. Please review my prior comment.
Sorry, I read through twice, but I am unable to really understand your replies, coerrace.

I can see that you said what you changed "from" and "to", but that does not address the point I made in my two posts:  that it appears the "convert -append" is run ONLY ONCE, not in a loop. (as in my example above- what are the results of that script?)

While the command, without the "-append", must be run FIRST, in a loop, just as you were doing.
The problem is that the prefixes are different because you have more than one PDF in each folder. For example, let's say a folder has:

testA.pdf
testB.pdf

When you run Convert using Duncan's script or Mogrify using my script, it will create, for example:

testA-1.jpg
testA-2.jpg
testA-3.jpg
testB-1.jpg
testB-2.jpg

Of course, it will create as many JPGs as there are pages in the PDF files. So, you would need two commands in the example above:

convert testA-* -append testA_single_image.jpg
convert testB-* -append testB_single_image.jpg

Problem is, for an arbitrary number of PDF files in each of your folders/subfolders, it's tricky. I'm sure there's a way to do it with enough programming, but I don't have an answer for you off the top of my head. Regards, Joe
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Qlemo,
That's a brilliant piece of code! Works perfectly (if, as you noted, there is no hyphen in the PDF file name). Awesome job! Regards, Joe
Korbus if I use your suggestion:

forfiles /p "C:\inetpub\wwwroot\esp\alianza\actividades\bachiACCENDOmodulo1alitLITGI5T" /s /m *.pdf  /C "cmd /c echo @path ">junk.txt
for /f "tokens=1 delims=." %%F in ('type junk.txt') do (convert %%F.pdf" %%F.jpg")
del junk.txt

REM stich together results
convert %%F-* -append %%F.jpg"

REM remove temp .jpgs

Open in new window


Convert the PDF to JPGS perfect like it was but not join the multiple JPG´s in one file is very close that because the script is doing good converting PDF´s to JPG´s and take and save in the right directory is just needed maybe format better the

convert %%F-* -append %%F.jpg"

Open in new window


The original script does all perfect.
WOW QLEMO I didn´t saw your message is what I needed works perfect!!!
Perfect and clean script