Jump to content

Batch Compression of pdfs


Recommended Posts

I am a new autoit user and need some suggestions for implementing usefully for some tasks at work. My employer wants me to optimize over 14000 pdf files and has taught me how to do so only one at a time. I rejected this notion and came across autoit as I searched frantically for other ways to handle this extremely repetative task.

I need to use autoit to (1)transfer company pdf files to a temp folder, (2)open each pdf file one at a time, (3)optimize each one, (4)close the file, (5)transfer each file back to its original folder. Steps 2,3, and 4 will just involve series of mouse clicks; if I know how to do one step, then I know how to do all others. Steps 1 and 5 are easy to teach a human, but I suspect they will be difficult to write into code. Each document comes from a very specific folder, which is usually hidden away in one of various sub-folders. So getting the computer to find each file - let's say each file above 5MB - and extract it from the folder to put into the temp, and then to finally replace it in its original folder seems complicated.

I really need some suggestions.

At the very least I would like some suggestions and how and where to learn autoit.

Thanks

Link to comment
Share on other sites

  • Replies 92
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

I need to use autoit to (1)transfer company pdf files to a temp folder, (2)open each pdf file one at a time, (3)optimize each one, (4)close the file, (5)transfer each file back to its original folder. Steps 2,3, and 4 will just involve series of mouse clicks; if I know how to do one step, then I know how to do all others. Steps 1 and 5 are easy to teach a human, but I suspect they will be difficult to write into code. Each document comes from a very specific folder, which is usually hidden away in one of various sub-folders. So getting the computer to find each file - let's say each file above 5MB - and extract it from the folder to put into the temp, and then to finally replace it in its original folder seems complicated.

I would almost say 1 and 5 are easier for a computer than a human! Humans have a tendency to get sidetracked and distracted, and do the same file over again, or miss one out completely. Computers are very single minded, give them a list and they will go from top to bottom perfectly, every time.

I have a few suggestions, but the first question I'd ask is, what software are you using to do the optimization? Secondly, is there a real need to move to a temp folder?

Link to comment
Share on other sites

I am a new autoit user and need some suggestions for implementing usefully for some tasks at work. My employer wants me to optimize over 14000 pdf files and has taught me how to do so only one at a time. I rejected this notion and came across autoit as I searched frantically for other ways to handle this extremely repetative task.

I need to use autoit to (1)transfer company pdf files to a temp folder, (2)open each pdf file one at a time, (3)optimize each one, (4)close the file, (5)transfer each file back to its original folder. Steps 2,3, and 4 will just involve series of mouse clicks; if I know how to do one step, then I know how to do all others. Steps 1 and 5 are easy to teach a human, but I suspect they will be difficult to write into code. Each document comes from a very specific folder, which is usually hidden away in one of various sub-folders. So getting the computer to find each file - let's say each file above 5MB - and extract it from the folder to put into the temp, and then to finally replace it in its original folder seems complicated.

I really need some suggestions.

At the very least I would like some suggestions and how and where to learn autoit.

Thanks

The whole exercise sounds pretty easy. You could certainly automate all five of those steps in AutoIt.

If you haven't done so yet, download the latest production version 3.2.4.9 of AutoIt, and the latest version of SciTE.

Go straight to the help file for AutoIt and scan the whole thing to get a sense of it. Then do the simple tutorials included. Then copy and run the demo scripts with FileCopy(), WinExists(), WinActivate(), WinWait(), MouseClick(), and Send(). After doing all that, you'll have the basics down to start writing your script.

When you get stuck, post the broken code here and you'll get plenty of help.

:whistle:

P.S. When installing AutoIt and SciTE, always select the option to "Edit Script" on double-clicking a file. Much safer for starting out (mine stays that way now, and I wish it was the default).

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

I would almost say 1 and 5 are easier for a computer than a human! Humans have a tendency to get sidetracked and distracted, and do the same file over again, or miss one out completely. Computers are very single minded, give them a list and they will go from top to bottom perfectly, every time.

I have a few suggestions, but the first question I'd ask is, what software are you using to do the optimization? Secondly, is there a real need to move to a temp folder?

I will be using adobe acrobat to compress the pdfs. I was told I need a temp folder because I am altering files off a network drive. What do you think?

Link to comment
Share on other sites

I will be using adobe acrobat to compress the pdfs. I was told I need a temp folder because I am altering files off a network drive. What do you think?

Have you tried it? If it's a slow network or you don't have write perms maybe a temp dir makes sense, but you should be able to work right on the UNC path ("\\Server\Share\Folder\File.pdf"). AutoIt, at least, won't have a problem with that.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

The whole exercise sounds pretty easy. You could certainly automate all five of those steps in AutoIt.

If you haven't done so yet, download the latest production version 3.2.4.9 of AutoIt, and the latest version of SciTE.

Go straight to the help file for AutoIt and scan the whole thing to get a sense of it. Then do the simple tutorials included. Then copy and run the demo scripts with FileCopy(), WinExists(), WinActivate(), WinWait(), MouseClick(), and Send(). After doing all that, you'll have the basics down to start writing your script.

When you get stuck, post the broken code here and you'll get plenty of help.

:)

P.S. When installing AutoIt and SciTE, always select the option to "Edit Script" on double-clicking a file. Much safer for starting out (mine stays that way now, and I wish it was the default).

Would you recommend anything from autoit_123? I downloaded it, but nearly every sample code seems far too complicated.

Link to comment
Share on other sites

I am using

FileCopy("S:\*.pdf", "temp")

to copy all the pdf files from the company directory into a temp folder. However, when I run this line nothing happens; I don't even get error messages. I also don't want to copy all the pdfs because for the moment my company wants to compress those only of a size greater than or equal to 5MB. I also don't want to copy files that have been compressed before by someone at the office. How can I create such filters to work with FileCopy.

Link to comment
Share on other sites

I am using

FileCopy("S:\*.pdf", "temp")

to copy all the pdf files from the company directory into a temp folder. However, when I run this line nothing happens; I don't even get error messages. I also don't want to copy all the pdfs because for the moment my company wants to compress those only of a size greater than or equal to 5MB. I also don't want to copy files that have been compressed before by someone at the office. How can I create such filters to work with FileCopy.

The code below verifies that FileCopy("S:\*.pdf", "temp") is not working:

$checker = FileCopy("S:\*.pdf", "temp")

If $Checker = 1 Then

MsgBox(0, "Script Operations", "It's Working")

Else

MsgBox(0, "Script Operations", "It's NOT Working")

EndIf

Link to comment
Share on other sites

I am using

FileCopy("S:\*.pdf", "temp")

to copy all the pdf files from the company directory into a temp folder. However, when I run this line nothing happens; I don't even get error messages. I also don't want to copy all the pdfs because for the moment my company wants to compress those only of a size greater than or equal to 5MB. I also don't want to copy files that have been compressed before by someone at the office. How can I create such filters to work with FileCopy.

"temp" is not a valid destination directory. Try:

FileCopy("S:\*.pdf", @ScriptDir & "\Temp\", 8)

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

"temp" is not a valid destination directory. Try:

FileCopy("S:\*.pdf", @ScriptDir & "\Temp\", 8)

:)

I've had problems using fileCopy that way

Error: Can not find file *.pdf

Better to put it through a FileFindFirstFile() FileFindNextFile() process.

EDIT: With 98 that always worked but XP will sometimes take it as a literal string so the wildcard throws it off.

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

"I will be using adobe acrobat to compress the pdfs."

For Adobe Acrobat > v5 there is a batch sequence "Fast Web View" that optimize the pdf file. You can choose the files and save to a different directory (if wanted).

If you don't have it by hand or on CD, or your CD not by hand I may send it to you.

"I was told I need a temp folder because I am altering files off a network drive. What do you think?"

There is not really a need to copy it to a temp dir. The process is sure and if really something happens the IT guys will be happy to copy it back from theirs dayly savings of network drives (at least it would be a good test).

If you unsure of this use good old DOS XCopy.exe to save the files in front of optimize.

Best regards, Reinhard

Edited by ReFran
Link to comment
Share on other sites

"temp" is not a valid destination directory. Try:

FileCopy("S:\*.pdf", @ScriptDir & "\Temp\", 8)

:)

Can you explain why FileCopy("S:\*.pdf", @ScriptDir & "\Temp\", 8) is better and what it is all about?

I tried it and it did not work anyway, but I would like to know the thinking behind it none the less.

By the way, temp is just a folder I keep in the desktop.

Link to comment
Share on other sites

Do yourself a favor and get a Professional version of Acrobat 7 or 8. Use the built-in batch processing on the File menu in conjunction with the PDF optimizer.

http://www.adobeforums.com/cgi-bin/webx/.3bc2c522

I'm just an intern so I don't want to make any software requests. Besides, at least this way I can put my mind to work and learn something this summer.

Link to comment
Share on other sites

"I will be using adobe acrobat to compress the pdfs."

For Adobe Acrobat > v5 there is a batch sequence "Fast Web View" that optimize the pdf file. You can choose the files and save to a different directory (if wanted).

If you don't have it by hand or on CD, or your CD not by hand I may send it to you.

"I was told I need a temp folder because I am altering files off a network drive. What do you think?"

There is not really a need to copy it to a temp dir. The process is sure and if really something happens the IT guys will be happy to copy it back from theirs dayly savings of network drives (at least it would be a good test).

If you unsure of this use good old DOS XCopy.exe to save the files in front of optimize.

Best regards, Reinhard

The IT guys told me specifically that they do not want any problems. They even mentioned their loathing of copying things back from their daily savings of network drives.

Link to comment
Share on other sites

"I will be using adobe acrobat to compress the pdfs."

For Adobe Acrobat > v5 there is a batch sequence "Fast Web View" that optimize the pdf file. You can choose the files and save to a different directory (if wanted).

If you don't have it by hand or on CD, or your CD not by hand I may send it to you.

"I was told I need a temp folder because I am altering files off a network drive. What do you think?"

There is not really a need to copy it to a temp dir. The process is sure and if really something happens the IT guys will be happy to copy it back from theirs dayly savings of network drives (at least it would be a good test).

If you unsure of this use good old DOS XCopy.exe to save the files in front of optimize.

Best regards, Reinhard

Can you explain this a little more: If you unsure of this use good old DOS XCopy.exe to save the files in front of optimize.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...