Sign in to follow this  
Followers 0
Ravel

convert word .doc files to .pdf

63 posts in this topic

I am fairly familiar to writing scritps with Autoit, but only basic scripts. What I am asking help on is over my head. I currently have a script that i use to transfer files from one folder to multiple others and divy them up according to the name of the file. What i would like to do is during the process of transfering the files have them converted from .doc to .pdf. I use this script at work to transfer files, but the only programs that i have installed to do this is an add in for word 2007, and PDF reDirect. I am not sure how to automate this process, and would like to know if someone here can provide assistance. Here attached the script that I am currently using to tranfer the files.

copyreports.au3

Share this post


Link to post
Share on other sites



Maybe you could use _WordDocPrint and print to a PDF printer.

Share this post


Link to post
Share on other sites

This will use the builtin Word functions with CutePDF printer installed (freeware):

#include 
$oWordApp = _WordCreate ("")
$oDoc = _WordDocOpen ($oWordApp, @ScriptDir & "\TODO.doc")

$oDoc = _WordDocGetCollection ($oWordApp, 0)
_WordDocPrint ($oDoc, 0, 1, 0, 1, "CutePDF Writer")
;WinWaitActive ( "Save As" )
$SET = ControlSetText ( "Save As", "", "Edit1", "test.pdf")
If $SET = 0 Then MsgBox(0,"","Error changing filename")
ControlClick ( "Save As", "", "Button2" )
_WordQuit ($oWordApp, 0)

Share this post


Link to post
Share on other sites

This will use the builtin Word functions with CutePDF printer installed (freeware):

#include 
$oWordApp = _WordCreate ("")
$oDoc = _WordDocOpen ($oWordApp, @ScriptDir & "\TODO.doc")

$oDoc = _WordDocGetCollection ($oWordApp, 0)
_WordDocPrint ($oDoc, 0, 1, 0, 1, "CutePDF Writer")
;WinWaitActive ( "Save As" )
$SET = ControlSetText ( "Save As", "", "Edit1", "test.pdf")
If $SET = 0 Then MsgBox(0,"","Error changing filename")
ControlClick ( "Save As", "", "Button2" )
_WordQuit ($oWordApp, 0)
I was looking at this... Since this is a company computer, I will not be able to install CutePDF writer. They already have PDFRedirect installed so I either have to use that or use the Microsoft 2007 Add in pdf converter. Is there anyway of taking this code and using the pdf add in?

here is the link to the add in that I am referring to:

2007 Microsoft Office Add-in: Microsoft Save as PDF

It is important to note that I cannot install any new software, I have to use either PDF Redirect, or the above add in. Any thoughts?

Share this post


Link to post
Share on other sites

@All

Maybe this can get you all started.

PDFCreator in AU3

regards,

ptrex

Well I tried looking to implement that but it looks greek to me. I also couldn't use it because i can install pdf Creator on this pc.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

It looks like there is a VBScript that uses the Save-As PDF add in here : http://www.suodenjoki.dk/us/productions/ar...es/word2pdf.htm

I only have Office 2003 so I will not be much help testing.

You could attempt an automatic VBScript to AutoIT conversion: http://www.autoitscript.com/forum/index.php?showtopic=12143

Edited by weaponx

Share this post


Link to post
Share on other sites

It looks like there is a VBScript that uses the Save-As PDF add in here : http://www.suodenjoki.dk/us/productions/ar...es/word2pdf.htm

I only have Office 2003 so I will not be much help testing.

You could attempt an automatic VBScript to AutoIT conversion: http://www.autoitscript.com/forum/index.php?showtopic=12143

Thanks I have checked it out. It looks promising. I'll have to see if I can figure it out.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

It looks like there is a VBScript that uses the Save-As PDF add in here : http://www.suodenjoki.dk/us/productions/ar...es/word2pdf.htm

I only have Office 2003 so I will not be much help testing.

You could attempt an automatic VBScript to AutoIT conversion: http://www.autoitscript.com/forum/index.php?showtopic=12143

Ok, I was looking at the the file. I changed it over to .au3, but for the life of me I cannot find where I am supposed to input the file that I want to convert. On top of that The file that I originally attached has a lot of separate lines to move separate files. Will I have to take this converted script and create one script for each of the lines i have in the original script?

doc2pdf.au3

ORIGINALcopyreports.au3

Edited by Ravel

Share this post


Link to post
Share on other sites

Looks like you call the function like this:

DOC2PDF( $sDocFile, $sPDFFile )

$sDocFile is the path to your Word Doc

$sPDFFile is the output name of your pdf

Share this post


Link to post
Share on other sites

Looks like you call the function like this:

DOC2PDF( $sDocFile, $sPDFFile )

$sDocFile is the path to your Word Doc

$sPDFFile is the output name of your pdf

LOL I completely missed that section of the script. Let me give that a try. Also on another note is there away to incorporate what I already have into this script? I mean that is a lot of lines that I have. It seems that it would be possible, but I am not sure yet. Any thoughts?

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Maybe like this:

#include "doc2pdf.au3"
While 1
DOC2PDF( "\\P533FP2\MATCTRL_REPORTS\208-280TH (METNAV)\JANUARY 07\11-04. D23 Daily Report*.doc", "\\P533FP2\45SW_ERM\45SCS_SCBMM\15 - Priority Monitor Report\15-B - D231 January\*.doc" )
;etc...
WEnd

I'm not sure if it will create folders if they don't already exist.

EDIT: Also why are you using Sleep after each filecopy? It won't attempt the next copy until the previous completes so this is wasteful.

Edited by weaponx

Share this post


Link to post
Share on other sites

I just realized that you were using a wildcard for the source and destination. You will have to do a FileListToArray on each folder and call the function for each item in the array.

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Maybe like this:

#include "doc2pdf.au3"
While 1
DOC2PDF( "\\P533FP2\MATCTRL_REPORTS\208-280TH (METNAV)\JANUARY 07\11-04. D23 Daily Report*.doc", "\\P533FP2\45SW_ERM\45SCS_SCBMM\15 - Priority Monitor Report\15-B - D231 January\*.doc" )
;etc...
WEnd

I'm not sure if it will create folders if they don't already exist.

EDIT: Also why are you using Sleep after each filecopy? It won't attempt the next copy until the previous completes so this is wasteful.

Really? I didn't realize that. I can remove the sleep command. As for the creation of the folders, I designed it to do that so that the folders would be created if they were not already there.

Also if I am include the doc2pdf.au3 won't i have to specify what file would be converted in that script or is it set up default as a wildcard, allowing me to just add it to the my original script? At the end were it would have originally just transferred the file to the new folder as a doc, wont i have to make the destination .... January\*.pdf" instead?

I just realized that you were using a wildcard for the source and destination. You will have to do a FileListToArray on each folder and call the function for each item in the array.

I don't quite no what the filelistToArray is, but i'll look it up in the help file to see if I can figure it out.

EDIT: I was running the script... doc2pdf.au3 and I am getting a syntax error at 22,7? not sure what this is really asking me to correct. I am assuming that this is the $ symbol before the W, but not sure what that means.

Edited by Ravel

Share this post


Link to post
Share on other sites

Line 22: $onst $WdDoNotSaveChanges = 0

Should probably be Const $WdDoNotSaveChanges = 0

Share this post


Link to post
Share on other sites

I just realized that you were using a wildcard for the source and destination. You will have to do a FileListToArray on each folder and call the function for each item in the array.

Is that in the help file? I can't seem to find it

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

When I run this script i am getting all sorts of errors, and I cannot figure out how to solve them. Anyone else have any suggestions?

Edited by Ravel

Share this post


Link to post
Share on other sites

When I run this script i am getting all sorts of errors, and I cannot figure out how to solve them. Anyone else have any suggestions?

Bump..

Can anyone help with these scripts.

Share this post


Link to post
Share on other sites

I'm throwing something together for you. The vbscript that you converted had a few errors, I cleaned it up and will post it along with a method for using wildcards soon.

Share this post


Link to post
Share on other sites

I'm throwing something together for you. The vbscript that you converted had a few errors, I cleaned it up and will post it along with a method for using wildcards soon.

Thanks I appreciate it!

Share this post


Link to post
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
Sign in to follow this  
Followers 0