1. william yau
  2. PowerBuilder
  3. Thursday, 7 November 2024 09:09 AM UTC

Dear Guru,

I have a question. I have an application built with PowerBuilder 7.0 that contains a script similar to the one below. There is a function that opens, edits, and saves a document as a PDF. This function was working fine before, but last week, on some desktops, when running this function, the text can be converted to PDF, but the pictures in Word documents are not being correctly converted to PDF.

ls_wscript = 'Dim objDoc, objWord' // Declare variables
ls_wscript = ls_wscript + '~r~n' + 'Set objWord = CreateObject( "Word.Application" )' // Create a Word object
ls_wscript = ls_wscript + '~r~n' + 'With objWord'
ls_wscript = ls_wscript + '~r~n' + '.Visible = True' // True: make Word visible; False: invisible
ls_wscript = ls_wscript + '~r~n' + '.WindowState = 2' // True: make Word visible; False: invisible
ls_wscript = ls_wscript + '~r~n' + '.Documents.Open "' + ls_doc_path + '"' // Open the Word document
ls_wscript = ls_wscript + '~r~n' + 'Set objDoc = .ActiveDocument' // Make the opened file the active document
ls_wscript = ls_wscript + '~r~n' + 'objDoc.SaveAs "' + ls_photo_path + '", 17' // ' Save as pdf, file format of pdf = 17
ls_wscript = ls_wscript + '~r~n' + 'objDoc.Close' // Close the active document
ls_wscript = ls_wscript + '~r~n' + '.Quit' // Close Word
ls_wscript = ls_wscript + '~r~n' + 'End With'

 

li_FileNum = FileOpen(ls_wscript_path, StreamMode!, Write!, LockReadWrite!, Replace!)
filewrite(li_FileNum, ls_wscript)
fileclose(li_FileNum)

// run Wscript
li_rc = wsh.Run('wscript.exe "' + ls_wscript_path + '"' , MINIMIZED, WAIT)

 

Please help me and give advice

 

William

 

 

 

 

René Ullrich Accepted Answer Pending Moderation
  1. Thursday, 7 November 2024 10:21 AM UTC
  2. PowerBuilder
  3. # 1

I think this is a Word problem and not a PowerBuilder problem. You should ask this in a forum with Word experts.

 

BTW: You could also access word directly from PB using OLE instead of create and run a script. I think it should also work with PB 7. 

Comment
There are no comments made yet.
william yau Accepted Answer Pending Moderation
  1. Friday, 8 November 2024 00:48 AM UTC
  2. PowerBuilder
  3. # 2

Rene Ullrich 

 

Thank you for your quick and helpful response. Could you please provide me with an example for reference on creating an OLE method

 

best regards

 

William 

 

 

 

 

 

 

 

 

 

 

 

 

Comment
There are no comments made yet.
René Ullrich Accepted Answer Pending Moderation
  1. Friday, 8 November 2024 05:31 AM UTC
  2. PowerBuilder
  3. # 3

I don't have a example with Word but I think you can replace your code in this way: (not tested)

OLEObject lole_word, lole_doc

lole_word = CREATE oleobject
lole_word.ConnectToNewObject ("Word.Application")

lole_word.Visible = True
lole_word.WindowState = 2
lole_word.Documents.Open (ls_doc_path)
lole_doc = lole_word.ActiveDocument
lole_doc.SaveAs (ls_photo_path, 17)
lole_doc.Close ()
lole_word.Quit ()

lole_word.Disconnectobject ()
DESTROY lole_word

Comment
  1. Armeen Mazda @Appeon
  2. Saturday, 9 November 2024 01:33 AM UTC
Thanks Rene for your great help!
  1. Helpful
There are no comments made yet.
william yau Accepted Answer Pending Moderation
  1. Thursday, 14 November 2024 06:41 AM UTC
  2. PowerBuilder
  3. # 4

René Ullrich

 


I used your method, but it still does not work. I try to modify your statement to maximize Word, wait for 30 seconds to allow more time for the picture to load into Word, and then save the Word document as a PDF. I don't understand why it needs to be maximized and to wait 30 seconds before it can work. Do you have any suggestions for improving this?.

 

William

Comment
  1. René Ullrich
  2. Thursday, 14 November 2024 07:19 AM UTC
My method is only a replacement four your solution with the external script. It does the same.

As I already wrote I think it is a problem with Word. I don't have an idea why Word have this problem.
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.