WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Samples from Users

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Convert Word Doc to PDF


Update: Check out the 2007 Microsoft Office Add-in: Microsoft Save as PDF http://www.microsoft.com/downloads/details.aspx?FamilyId=F1FC413C-6D89-4F15-991B-63B07BA5F2E5&displaylang=en


;///////////////////////////////////////////////////////////////////
; Winbatch 2005C - 
; Saving a Word File as PDF and attaching a password
; NOTE: must have full version of Acrobat Installed
; Should work with versions 5.0 or higher
;
; Stan Littlefield, April 24, 2005
;
; Version NOTE: use sendkeys rather than AcroApp.MenuItemExecute
;///////////////////////////////////////////////////////////////////

AddExtender("wwctl44i.dll")
IntControl(54,"",1,0,0)
dfile = StrCat(dirscript(),"debug.txt")
If FileExist(dfile) Then FileDelete(dfile)

cPDF = StrCat(dirscript(),"flowchart.doc")
cPDF1 = StrReplace( StrUpper(cPDF),".DOC",".pdf")
If FileExist(cPDF1) Then FileDelete(cPDF1)
If ! FileExist(cPDF) Then Exit

debugtrace(@ON,dfile)
BoxOpen("Converting %cPDF%","to %cPDF1%")
;Create Objects
AcroApp = CreateObject("AcroExch.App")
AvDoc = CreateObject("AcroExch.AVDoc")
PdDoc = CreateObject("AcroExch.PDDoc")

If AvDoc.Open(cPDF,"Winbatch Demo")
   BoxShut()
   AcroApp.Show()
   AvDoc = AcroApp.GetActiveDoc()
   pdDoc = avDoc.GetPDDoc()  
   TimeDelay(1)
   SendKey(`!fd{TAB}{DOWN}`)
   TimeDelay(1)
   Sendkey( `{TAB}` )
   TimeDelay(1)
   Sendkey( `{SPACE}` )
   TimeDelay(1)
   SendKey( "password~" )
   TimeDelay(1)
   SendKey( "password~~" )
   Sendkey( `{TAB}` )
   Sendkey( `{TAB}` )
   Sendkey( `{TAB}` )
   Sendkey( `{TAB}~` )
   TimeDelay(1)

   ;in case you want to see what doesn't work
   ;goto setpw
Else
   BoxText(StrCat("Unable to open the PDF-file",@CRLF,"Program Terminating"))
   TimeDelay(2)
   BoxShut()
   goto close
EndIf

:close
PDDoc.Save(1|4|32,"%cPDF1%")

PDDoc.Close()
AVDoc.Close(@TRUE)
AcroApp.Exit()

:end
AvDoc = 0
PDDoc = 0
AcroApp = 0
If ! FileExist(cPDF1) Then Display(2,"Unable To Create File",cPDF1)
Exit

:setpw
AcroApp.MenuItemExecute("SecureApplyPwdSecurity")
w=0
w=DllHwnd("Password Security - Settings")
If w==0 Then Return
message("",w)
cSetFocus(w)
s= cWndByName(w,"Require a password to open the document")
chk=cCheckbox(s,-1)
Message("Current Password Setting is",chk)
s= cWndByName(w,"Cancel")
cClickButton(s)
PDDoc.Save(1|4|32,"%cPDF1%")
PDDoc.Close()
AVDoc.Close(@TRUE)
AcroApp.Exit()
goto end

:Cancel
goto close



; if you need to quickly copy and paste text to clipboard
App.MenuItemExecute('Edit');
App.MenuItemExecute('SelectAll');
App.MenuItemExecute('Edit');
App.MenuItemExecute('Copy');

Article ID:   W17192
File Created: 2007:07:20:08:54:24
Last Updated: 2007:07:20:08:54:24