Hi Dennis,
if Office is installed the conversion can be done as follows.
Basically, the script opens the file with the corresponding Office product and saves it as a PDF.
Works very well for us in practice, the good thing is, the resulting PDF is always created correctly, because, for example, Word interprets the formatting and saves the content as a PDF.
We have explicitly not hidden word and co in the automation, because otherwise the process would hang and the user could not react to queries from Word, e.g. specify intials.
I hope i could help you.
String ls_filetype
long ll_ret
choose case lower(ls_filetype)
case "doc","docx","dot","dotx","rtf","odt"
try
oleobject ole_doc
ole_doc = create oleobject
ll_ret = ole_doc.ConnectToNewObject("Word.Application")
if ll_ret <> 0 then
MessageBox("Error", "Could not create Word object (" + string(ll_Ret) + ")!~nIs Microsoft Word installed?", Exclamation!)
destroy ole_doc
return false
end if
// PDF speichern
ole_doc.Visible = true;
ole_doc.Documents.Open(as_sourcefile)
ole_doc.ActiveDocument.saveas(as_filename,17)
ole_doc.ActiveDocument.Close(false)
ole_doc.Options.SaveNormalPrompt = false
ole_doc.Options.SavePropertiesPrompt = false
ole_doc.NormalTemplate.Saved = true
ole_doc.Quit()
ole_doc.DisconnectObject()
return true
catch ( NullObjectError noe1 )
Messagebox("Error","An error occurred during communication with Word!~n NOE: "+noe1.GetMessage())
return false
catch ( PBXRuntimeError pbxre1 )
Messagebox("Error","An error occurred while communicating with Word!~n PBXRE: "+pbxre1.GetMessage())
return false
catch ( OleRunTimeError ort1)
Messagebox("Error","An error occurred during communication with Word!~n PBXRE: "+ort1.GetMessage())
return false
catch ( RunTimeError rtn1)
Messagebox("Error","An error occurred during communication with Word!~n PBXRE: "+rtn1.GetMessage())
return false
catch ( CorbaUserException cue1)
Messagebox("Error","An error occurred during communication with Word!~n PBXRE: "+cue1.GetMessage())
return false
catch ( Throwable oe1 )
Messagebox("Error","An error occurred while communicating with Word!~n OE: "+oe1.GetMessage())
return false
end try
case "xls","xlsx"
try
oleobject ole_excel
ole_excel = create oleobject
ll_ret = ole_excel.ConnectToNewObject("Excel.Application")
if ll_ret <> 0 then
MessageBox("Error", "Could not create Excel object (" + string(ll_Ret) + ")!~nIs Microsoft Excel installed?", Exclamation!)
destroy ole_excel
return false
end if
ole_excel.Visible = true;
// PDF speichern
ole_excel.WorkBooks.Open(as_sourcefile)
oleobject lole_worksheet,lole_workbook
lole_workbook = ole_excel.application.workbooks(1)
lole_worksheet = lole_workbook.worksheets(1)
lole_worksheet.SaveAs(as_filename, 57);
ole_excel.Quit()
ole_excel.DisconnectObject()
return true
catch ( NullObjectError noe2 )
Messagebox("Error","An error occurred while communicating with Excel!~n NOE: "+noe2.GetMessage())
return false
catch ( PBXRuntimeError pbxre2 )
Messagebox("Error","An error occurred while communicating with Excel!~n PBXRE: "+pbxre2.GetMessage())
return false
catch ( OleRunTimeError ort2)
Messagebox("Error","An error occurred while communicating with Excel!~n PBXRE: "+ort2.GetMessage())
return false
catch ( RunTimeError rtn2)
Messagebox("Error","An error occurred while communicating with Excel!~n PBXRE: "+rtn2.GetMessage())
return false
catch ( CorbaUserException cue2)
Messagebox("Error","An error occurred while communicating with Excel!~n PBXRE: "+cue2.GetMessage())
return false
catch ( Throwable oe2 )
Messagebox("Error","An error occurred while communicating with Excel!~n OE: "+oe2.GetMessage())
return false
end try
case "ppt","pptx"
try
oleobject ole_powerpoint
ole_powerpoint = create oleobject
ll_ret = ole_powerpoint.ConnectToNewObject("powerpoint.Application")
if ll_ret <> 0 then
MessageBox("Error", "Could not create PowerPoint object (" + string(ll_Ret) + ")!~nIs Microsoft PowerPoint installed?", Exclamation!)
destroy ole_powerpoint
return false
end if
ole_powerpoint.Visible = true;
// PDF speichern
ole_powerpoint.Presentations.Open(as_sourcefile)
ole_powerpoint.ActivePresentation.saveas(as_filename,32)
ole_powerpoint.Quit()
ole_powerpoint.DisconnectObject()
return true
catch ( NullObjectError noe3 )
Messagebox("Error","An error occurred while communicating with PowerPoint!~n NOE: "+noe3.GetMessage())
return false
catch ( PBXRuntimeError pbxre3 )
Messagebox("Error","An error occurred while communicating with Powerpoint!~n PBXRE: "+pbxre3.GetMessage())
return false
catch ( OleRunTimeError ort3)
Messagebox("Error","An error occurred while communicating with PowerPoint!~n PBXRE: "+ort3.GetMessage())
return false
catch ( RunTimeError rtn3)
Messagebox("Error","An error occurred while communicating with PowerPoint!~n PBXRE: "+rtn3.GetMessage())
return false
catch ( CorbaUserException cue3)
Messagebox("Error","An error occurred while communicating with Powerpoint!~n PBXRE: "+cue3.GetMessage())
return false
catch ( Throwable oe3 )
Messagebox("Error","An error occurred while communicating with PowerPoint!~n OE: "+oe3.GetMessage())
return false
end try
case else
Messagebox("Error","File type "+ls_filetype+" not supported".)
Return False
end choose
Return true
Regards Tobi