Solved

batch to append pictures in one file

Posted on 2014-07-31
18
517 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
Comment Utility
change the %%F.jpg to single_image.jpg and retry it.
0
 
LVL 10

Expert Comment

by:Korbus
Comment Utility
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
Comment Utility
I need to name the file like the PDF source not just single_image.
Thank you
0
 
LVL 10

Expert Comment

by:Korbus
Comment Utility
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
Comment Utility
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
Comment Utility
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 32

Expert Comment

by:sarabande
Comment Utility
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
Comment Utility
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 68

Expert Comment

by:Qlemo
Comment Utility
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:coerrace
Comment Utility
convert "%%F-*" -append %%F.jpg 

Open in new window

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

Expert Comment

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

Expert Comment

by:Korbus
Comment Utility
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 51

Expert Comment

by:Joe Winograd, EE MVE
Comment Utility
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 68

Accepted Solution

by:
Qlemo earned 500 total points
Comment Utility
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 51

Expert Comment

by:Joe Winograd, EE MVE
Comment Utility
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
Comment Utility
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
Comment Utility
WOW QLEMO I didn´t saw your message is what I needed works perfect!!!
0
 

Author Closing Comment

by:coerrace
Comment Utility
Perfect and clean script
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This is an explanation of a simple data model to help parse a JSON feed
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now