Solved

batch to append pictures in one file

Posted on 2014-07-31
18
523 Views
Last Modified: 2014-07-31
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
0
Comment
Question by:coerrace
  • 8
  • 3
  • 3
  • +3
18 Comments
 
LVL 6

Expert Comment

by:LHT_ST
ID: 40231770
change the %%F.jpg to single_image.jpg and retry it.
0
 
LVL 10

Expert Comment

by:Korbus
ID: 40231792
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.
0
 

Author Comment

by:coerrace
ID: 40231794
I need to name the file like the PDF source not just single_image.
Thank you
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 10

Expert Comment

by:Korbus
ID: 40231826
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

0
 

Author Comment

by:coerrace
ID: 40231831
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
0
 

Author Comment

by:coerrace
ID: 40231853
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?
0
 
LVL 33

Expert Comment

by:sarabande
ID: 40232133
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
0
 

Author Comment

by:coerrace
ID: 40232324
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
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 40232422
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.
0
 

Author Comment

by:coerrace
ID: 40232485
convert "%%F-*" -append %%F.jpg 

Open in new window

not work give a lot of errors like this  unable to open image
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 40232928
I cannot see you specifying the leading blank. Please review my prior comment.
0
 
LVL 10

Expert Comment

by:Korbus
ID: 40232980
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.
0
 
LVL 52

Expert Comment

by:Joe Winograd, EE MVE
ID: 40232999
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
0
 
LVL 69

Accepted Solution

by:
Qlemo earned 500 total points
ID: 40233038
That's correct, Joe. I missed that the original "Junk.txt" file is not available anymore. However, we (certainly) still have the PDF (?), so generating it again would not be an issue.

But even if not it is not that hard to split the file name into its parts - assuming there is no dash in the orignal PDF file name.
@echo off
setlocal EnableDelayedExpansion

set priorPDF=
for /R "C:\Data" %%A in (*-*.jpg) do for /F "delims=- tokens=1-2" %%B in ("%%~nA") do (
  set curPDF=%%~dpA%%B
  if not "%priorPDF%" == "!curPDF!"  convert "!curPDF!-*" -append "!curPDF!.jpg" &   set priorPDF=!curPDF!
)

Open in new window

0
 
LVL 52

Expert Comment

by:Joe Winograd, EE MVE
ID: 40233064
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
0
 

Author Comment

by:coerrace
ID: 40233065
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.
0
 

Author Comment

by:coerrace
ID: 40233072
WOW QLEMO I didn´t saw your message is what I needed works perfect!!!
0
 

Author Closing Comment

by:coerrace
ID: 40233074
Perfect and clean script
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Arduino EDI - Programming Language - Voice Recorder 4 81
iSeries email authority 6 57
Check folder every for files and print them 5 37
Help Required 2 33
This article will show, step by step, how to integrate R code into a R Sweave document
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question