AutoHotkey Community

It is currently May 26th, 2012, 5:50 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: April 23rd, 2009, 9:44 am 
Offline

Joined: April 8th, 2009, 7:29 am
Posts: 5
I´m using the PDF converter tool from NicePDF (download) to convert PDFs to version 1.4
The tool can only convert one PDF at the time.

So I want to make an AHK script that is able to read all PDFs in a folder and have them converted to 1.4 with the tool.

I´m pretty hopeless with AHK and the script that I created does not work properly. First I ask the user to select a folder and upon selecting that folder you have to move the mouse quickly out of the way for the script to work. Sometimes it works properly, sometimes the script does nothing and it appears to depend on what the user does with the mouse.
I don´t know exactly what happens here, if someone could have a look at my script, please.


Code:
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
SetTitleMatchMode, 3

FileSelectFolder,WorkingFolder,,0,Seleccionar carpeta con los PDFs
Sleep,200
run pdfversion.exe
WinWait,PDF Version Converter 1.0,, 3
if ErrorLevel
{
    MsgBox, PDF version program not found
    return
}
Teller:=0
Loop %workingfolder%\*.pdf,,1
{
WinActivate,PDF Version Converter 1.0
ControlClick,TButton5,PDF Version Converter 1.0
WinWait,Open PDF
WinActivate,Open PDF
ControlSetText,Edit1,%A_LoopFileFullPath%
ControlClick,Button2,Open PDF
Sleep,100
WinActivate,PDF Version Converter 1.0
ControlClick,TButton4,PDF Version Converter 1.0
WinWait,Save PDF
WinActivate,Save PDF
ControlSetText,Edit1,%A_LoopFileFullPath%
ControlClick,Button2,Save PDF
sleep,100
WinActivate,PDF Version Converter 1.0
ControlFocus,TGroupButton2,PDF Version Converter 1.0
ControlClick,TGroupButton2,PDF Version Converter 1.0
sleep,100
ControlClick,Tbutton3,PDF Version Converter 1.0
WinWait,PDF Version Converter,, 3
if ErrorLevel
{
    MsgBox, Problems converting document %A_LoopFileFullPath%
    Exit
}
WinActivate,PDF Version Converter
ControlClick,TButton1,PDF Version Converter
Teller++1
}
sleep,100
WinActivate,PDF Version Converter 1.0
ControlClick,Tbutton1,PDF Version Converter 1.0
sleep,100
msgbox, Converted %Teller% PDF-files.



Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 23rd, 2009, 9:52 am 
Quote:
Oct 19, 2007 - Nice PDF Creator 3.02 has been released
Add support for very silent installation.
Command line options available.
Multiple language interface.

Would you mind to post those command line options from the NPDFC help file?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 23rd, 2009, 9:59 am 
Offline

Joined: April 8th, 2009, 7:29 am
Posts: 5
GetRidOfThatApp wrote:
Quote:
Oct 19, 2007 - Nice PDF Creator 3.02 has been released
Add support for very silent installation.
Command line options available.
Multiple language interface.

Would you mind to post those command line options from the NPDFC help file?

I´m not working with the PDFCreator. It is not for free :D
I´m working with their free utility PDFversion 1.0, which has a GUI but no command line options (unfortunately).

Thanks


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 23rd, 2009, 2:05 pm 
Code:
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
SetTitleMatchMode, 2

PDFVCTitle := "PDF Version Converter 1.0"
PDFVCPath := A_ScriptDir

FileSelectFolder,WorkingFolder,,0,Seleccionar carpeta con los PDFs
Sleep,200
If FileExist(PDFVCPath "\pdfversion.exe")
   Run %PDFVCPath%\pdfversion.exe
Else
{
    MsgBox, PDF version program not found
    ExitApp
    }

Loop %workingfolder%\*.pdf,,1
{
      Cnt := A_Index
      WinActivate, %PDFVCTitle%
            ControlClick,TButton5,%PDFVCTitle%
      WinWaitActive,Open PDF
            ControlSetText,Edit1,%A_LoopFileFullPath%
            ControlClick,Button2,Open PDF
            Sleep,100
      WinActivate, %PDFVCTitle%
            ControlClick,TButton4,%PDFVCTitle%
      WinWaitActive,Save PDF
            ControlSetText, Edit1,%A_LoopFileFullPath%
            ControlClick, Button2 ,Save PDF
            Sleep,100
      WinWaitActivate, %PDFVCTitle%
            ControlFocus,TGroupButton2,%PDFVCTitle%
            ControlClick,TGroupButton2,%PDFVCTitle%
            Sleep,100
            ControlClick,Tbutton3,%PDFVCTitle%
      WinWait, %PDFVCTitle%,, 3
      if ErrorLevel
      {
            MsgBox, Problems converting document %A_LoopFileFullPath%
            Exit
            }
      WinActivate, %PDFVCTitle%
         ControlClick,TButton1, %PDFVCTitle%      }
Sleep,100
WinActivate,%PDFVCTitle%
      ControlClick,Tbutton1,%PDFVCTitle%
Sleep,100
MsgBox, Converted %Cnt% PDF-files.
Not tested.
Please check you window title settings. SetTitlematchMode, 3 will prevent to be able to identify windows you've set with typos!!

PDF Version Converter 1.0
vs
PDF Version Converter :!:


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 24th, 2009, 11:18 am 
Offline

Joined: April 8th, 2009, 7:29 am
Posts: 5
GetRidOfThatApp wrote:
Not tested.
Please check you window title settings. SetTitlematchMode, 3 will prevent to be able to identify windows you've set with typos!!

PDF Version Converter 1.0
vs
PDF Version Converter :!:


I appreciate you putting your time into this.
Your script unfortunately does not work at all.

Note that I have not made any typos in the window names. If you click the process button of the window named "PDF Version Converter 1.0" a Window with the name "PDF Version Converter" pops up. That´s why I set Titlematchmode to 3.

I´ve put some more time in this but cannot produce anything better than the script in the OP.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 25th, 2009, 2:45 pm 
Offline

Joined: February 7th, 2008, 9:48 pm
Posts: 509
Quote:
I´m pretty hopeless with AHK and the script that I created does not work properly.



I tried it and it works very well. :)


I use a similar solution with the controlclick on buttons on a program and sometimes it works sometimes not ( and it only has 5 controlclicks!! )

The only two problems i could find in the program i use did not function was at a WinWait so i just removed it and put sleep 200 instead and when it had to write to disk so i put a sleep 1000 there.It improved the script but still it does mis a controlclick from time to time so i had to live with that!

If it halts you can go to the tray menu and look in "open" to see the last programlines executed.


Last edited by closed on April 25th, 2009, 2:48 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 25th, 2009, 2:46 pm 
Offline

Joined: August 13th, 2006, 6:45 am
Posts: 354
Location: Germany
Gaby wrote:
I´ve put some more time in this but cannot produce anything better than the script in the OP.


Hi Gaby,

I have put some time in this and the best I can do for you is the following code:
Code:
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
SetTitleMatchMode, 3
onexit, ende

FileSelectFolder,WorkingFolder,,0,Seleccionar carpeta con los PDFs
Sleep,200
if workingfolder =
{
   message = No files selected
   exitapp
}
if ErrorLevel
{
   message = No files selected
   exitapp
}
run pdfversion.exe,,, pid
WinWait,PDF Version Converter 1.0,, 3
if ErrorLevel
{
    MsgBox, PDF version program not found
    return
}
settimer, block, 10000
BlockInput, on
Teller:=0
Loop %workingfolder%\*.pdf,,1
{
   inputcount++
   file := a_loopfilename
   path := a_loopfilefullpath
   stringtrimright, newpath, a_loopfilefullpath, 4
   newpath .= "_v14.pdf"
   ifexist, % newpath
   {
      pdf_already++
      continue
   }
   fileread, data, % a_loopfilefullpath
   stringleft, pdf, data, 8
   if (pdf = "%PDF-1.4")
   {
      pdf14++
      continue
   }
   if (pdf = "%PDF-1.6")
   {
      pdf16++
      continue
   }
   WinWaitActive,PDF Version Converter 1.0
   
   ControlClick,TButton5,PDF Version Converter 1.0
   goon("Open PDF","TButton5")
   WinWaitActive,Open PDF
   ControlSetText,Edit1,%A_LoopFileFullPath%
   ControlClick,Button2,Open PDF
   check("Open PDF","TButton5")
   goon("Open","Button2","Open PDF")
   WinWaitClose,Open PDF
   
   WinWaitActive,PDF Version Converter,, 3
   if ErrorLevel = 0
   {
      WinActivate,PDF Version Converter
      Errors .= A_LoopFileName "`n"
      errorcount++
      ControlClick, Button1, PDF Version Converter
      goon("OK","Button1","PDF Version Converter")
      continue
   }
   goon2()
   ControlClick,TButton4,PDF Version Converter 1.0
   goon("Save PDF","TButton4")
   WinWaitActive,Save PDF
   ControlSetText,Edit1,%newpath%
   ControlClick,Button2,Save PDF
   check("Save PDF","TButton4")
   goon("Store","Button2","Save PDF")
   WinWaitClose,Save PDF
   
   WinWaitActive,PDF Version Converter 1.0
back:
   ControlFocus,TGroupButton2,PDF Version Converter 1.0
   ControlClick,TGroupButton2,PDF Version Converter 1.0
   ControlClick,TButton3,PDF Version Converter 1.0
   goon("Convert","TButton2")
   
   WinWait,PDF Version Converter,, 3
   if ErrorLevel
   {
       MsgBox, Problems converting document %A_LoopFileFullPath%
       Exit
   }
   ControlClick,TButton1,PDF Version Converter
   if ErrorLevel
      goto back
   goon("OK","TButton1","PDF Version Converter")
   goon2()
   Teller++1
}
sleep,100
ende:
WinActivate,PDF Version Converter 1.0
ControlClick,Tbutton1,PDF Version Converter 1.0
sleep,100
if message =
{
   if errorcount > 0
   {
      message = Converted %Teller% of %inputcount% PDF-files with %errorcount% Errors - see filnames below.
      message = %message%`n%pdf_already% already converted by this application
      message = %message%`n%pdf14% not converted, already version 1.4`n%pdf16% not converted, unsupported version 1.6
      message .= "`nErrors:`n-------`n" errors
   }
   else
   {
      message = Converted %Teller% PDF-files without Errors.
      message = %message%`n%pdf_already% already converted by this application
      message = %message%`n%pdf14% not converted, already version 1.4`n%pdf16% not converted, unsupported version 1.6
   }
}
msgbox, % message
exitapp


check(key,button,screen="PDF Version Converter 1.0")
{
   if errolevel =
      return
   ControlClick,%button%,%screen%
}

goon(key,button,screen="PDF Version Converter 1.0")
{
   global
   zkey := key
   zbutton := button
   zscreen := screen
   settimer, buttons, 10000
   timer_buttons = yes
   return
}

goon2()
{
   global zkey =
   settimer, running, 60000
   timer_running = yes
   settimer, buttons, off
   timer_buttons =
   return
}

running:
   if zkey <>
   {
      controlClick,%zbutton%,%zscreen%
      zkey =
   }
   else
   {
      Process, close, % pid
      msgbox, PDF Version Converter cannot process`n`n`t%path%`n`nPlease rename/remove this file and start the application again !
      exitapp
   }
   return

buttons:
   controlClick,%zbutton%,%zscreen%
   settimer, buttons, off
   timer_buttons =
   return

block:
   ifwinexist, Adobe Acrobat
   {
      controlclick, Button2, Adobe Acrobat
   }
   settimer, block, off
   blockinput, off
   return


I try to avoid the processing of files, that are already in Version 1.4 and those, that are in Version 1.6, which leads to an error message. I name the output files with the ending "_v14.pdf" to avoid, that files are destroyed by an error in the converter program - in some cases the output files all had a size of 1KB.

The other thing I try is to repeat missing ControlClicks via timer routines within 10 seconds.

And I fetch the converter program, when looping due to a defect in the file, or if it is incomplete, and kill it and end the application with an message to rename/remove the appropriate file.

After the selection of the folder to be processed, the user input is blocked for 10 seconds.



I know, that this is a very difficult application, because it can only be handled via controlclicks, and all the changing windows that pop up on the screen, are really not state of the art. The user should avoid any action during the run of this application!

But it seems this is the only program that converts from one version to another, I found no other on google. Perhaps, you can get in contact with "NicePDF Software Corporation" to get a new version of the PDF Version Converter that can be run in batch and take arguments(input and output filename and pdf-version).

I hope, this helps you with your difficult task. Don't hesitate to ask further questions or write me per pm.

Hubert


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 27th, 2009, 8:56 am 
Offline

Joined: April 8th, 2009, 7:29 am
Posts: 5
Amazing job Hubert, thanks a lot.

Yes, the application is crappy and yes, it is the only one available on internet of its kind. The alternative is to work with PDF creators (the virtual printers kind).

I do not think nicepdf is going to invest time to improve their app.

I noticed as well that some PDFs are converted badly into 1kb PDFs. It mostly happened when I directly typed the pdf filename into the filename field, instead of browsing for it. Apparently it is important for the converter to read the file and determine the current PDF version before actually converting it.

The only think I do not like in your script is that the filenames are changed, because we need to change them back. I suppose I will be able to fix that. Of course the user is advised to never run the program on the original files.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: batto, BrandonHotkey, G. Sperotto, Google [Bot], Google Feedfetcher, Miguel, Mtes, rafaelloureiro, Yahoo [Bot] and 73 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group