Solved

How to trap events for an OLE object in PowerBuilder

Posted on 2008-10-20
2
2,681 Views
Last Modified: 2013-12-26
I am trying to use Adobe Distiller to convert postscript files to PDFs using OLE automation. My sample script (attached) works fine for a single file using the FileToPdf function in Distiller. However, I will be running this in  a multi-threaded application, so need to set bSpoolJobs to true so that Distiller will queue the requests. Otherwise, PowerBuilder processes the requests faster than Distiller can handle them, causing an error.

I believe that queueing up the Distiller requests will solve the problem. However, I then need to know when each Distiller process finishes, so that I can move the PDF file, cleanup the files, etc. If I could get at the onJobDone event in the Distiller object, I believe I could then do my cleanup there. However, I have no idea how to get at or code to the events in the ole object.

If I use ConnectToNewObject, as in my attached code example, then there is no visual object in which to code events. I have tried creating an external visual user object and assigning the DLL and class to it, but it just errors out when I try to set any properties or call any functions within the DLL.

Is there any way to create this object around the acrodistdll.dll dll and be able to get at the onJobDone and onJobError events? In visual basic, you can use the "WithEvents" clause to generate the events. Is there any way to do it with PowerBuilder?
integer		li_rc
OLEObject	ole_distill
string		ls_orig_printer, ls_ps_file, ls_pdf_file
string		ls_filename = 'C:\testapp\testapp'
 
// Cleanup from previous run
ls_ps_file  = ls_filename + '.ps'
ls_pdf_file = ls_filename + '.pdf'
FileDelete(ls_ps_file)
FileDelete(ls_pdf_file)
 
// Create and connect to Distiller object
ole_distill = Create OLEObject
li_rc = ole_distill.ConnectToNewObject("PdfDistiller.PdfDistiller.1")
If li_rc <> 0 Then
   Destroy ole_distill 
   Return  
End if
 
// Set distiller properties
ole_distill.bShowWindow = False
ole_distill.bSpoolJobs  = True
 
// Backup original printer and change to PS
ls_orig_printer = PrintGetPrinter()
PrintSetPrinter('Sybase Datawindow PS')
 
// Print to postscript file
dw_1.object.datawindow.print.filename = ls_ps_file
dw_1.object.datawindow.print.printername = 'Sybase Datawindow PS'
dw_1.Print()
 
// Use Distiller to convert postscript file to pdf
li_rc = ole_distill.FileToPdf(ls_ps_file, ls_pdf_file, 'Standard.joboptions')
 
// Reset printer and cleanup
PrintSetPrinter(ls_orig_printer)
Destroy ole_distill

Open in new window

0
Comment
Question by:stanner
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 14

Assisted Solution

by:sandeep_patel
sandeep_patel earned 100 total points
ID: 22767413
As far I know it is possible only if you can paste (insert) the control on userobject or window.

Regards,
Sandeep
0
 
LVL 1

Accepted Solution

by:
stanner earned 0 total points
ID: 23349949
I was unable to get this working with PowerBuilder alone. I finally solved the problem by creating a Visual Basic 6 OCX that interfaced with the Distiller API. I could then place the VB OCX object on a PowerBuilder window and relay the events to PowerBuilder events. This is a bit cumbersome, but seems to work effectively.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is in response to a question here (http://www.experts-exchange.com/Other/URLs/Q_28283850.html) at Experts Exchange. The Original Poster has a scanned signature and wants to make the background transparent so that the signature may be pl…
In a previous article published here at Experts Exchange, Signature Image with Transparent Background (http://www.experts-exchange.com/Web_Development/Document_Imaging/A_12380-Signature-Image-with-Transparent-Background.html), I explained how to cre…
In this video, we show how to perform Bates Numbering/Stamping of PDF documents using Power PDF Advanced, the newest product from the Document Imaging division of Nuance Communications. There are two editions of Power PDF — Standard and Advanced. Th…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question