Sign in to follow this  
Followers 0
Santana

printing word applications to pdf

5 posts in this topic

Hi all, The following is a function that creates a bunch of MS Word documents and then convert them to .pdf

it also deletes the word document after the pdf is created (I only need the pdf version of the file)

func print($getfile)
if FileExists($iresultfolder & "\TDBK3077_" & $p -1  & ".doc") then FileDelete($iresultfolder & "\TDBK3077_" & $p -1  & ".doc")
$oWordApp = _WordCreate ($iresultfolder & "\TDBK3077_" & $p & ".doc", 0,0,0)

$oDoc = _WordDocGetCollection ($oWordApp, 0)
$oShape = _WordDocAddPicture ($oDoc, $sPath & $getfile, 0, 1)
If Not @error Then $oShape.Range.InsertAfter (@CRLF)
_WordDocPrint ($oDoc)
;sleep(500)
 ProcessWaitClose("Acrobat.exe")
_WordDocClose ($oDoc)
$p +=1
EndFunc

The problem is that most of the time I get the following error and I have to run the script two or three times, then it works fine.

ERROR:

C:\Program Files\AutoIt3\Include\Word.au3 (366) : ==> The requested action with this object has failed.:

$o_doc = $o_object.Documents.Add ($s_Template, $f_NewTemplate, $i_DocumentType)

$o_doc = $o_object.Documents.Add ($s_Template, $f_NewTemplate, $i_DocumentType)^ ERROR

Can anyone give me a hint of what am I doing wrong?

Thanks


Just another special date with a different challenge

Share this post


Link to post
Share on other sites



ERROR:

C:\Program Files\AutoIt3\Include\Word.au3 (366) : ==> The requested action with this object has failed.:

$o_doc = $o_object.Documents.Add ($s_Template, $f_NewTemplate, $i_DocumentType)

$o_doc = $o_object.Documents.Add ($s_Template, $f_NewTemplate, $i_DocumentType)^ ERROR

Can anyone give me a hint of what am I doing wrong?

Thanks

I think it's because your script is trying to process the document before the whole file is available for opening. I do a very similar task with MS Office and found that if the document hadn't finished copying to the input folder, I would get that error.

Try this function code:

If _CheckFileAvailable($SourceFile) <> -1 Then ;check source file is available for reading/conversion
...
...
...
EndIf


Func _CheckFileAvailable($File)

    $File = FileOpen($File, 0)

    FileClose($File)

    Return $File

EndFunc

Share this post


Link to post
Share on other sites

Thanks. I'll give it a try


Just another special date with a different challenge

Share this post


Link to post
Share on other sites

Tried that. Same error.

any other input???

Thanks


Just another special date with a different challenge

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

 modify your word.au3 - udf

Function: _WordDocAdd(...)

Line: ~37x

$o_doc = $o_object.Documents.Add ($s_Template, $f_NewTemplate, $i_DocumentType)

To:

If $o_object.Application.Version () <= 8 Then

        ;MsgBox(0,"WordVersion " & $o_object.Application.Version (), "ups... Word 97 installed?")

       $o_doc = $o_object.Documents.Add ($s_Template, $f_NewTemplate);, $i_DocumentType)

   Else

       $o_doc = $o_object.Documents.Add ($s_Template, $f_NewTemplate, $i_DocumentType)

   EndIf
Edited by JoKurt

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