Quantcast
Channel: Recent Discussions on pdfforge Forums
Viewing all articles
Browse latest Browse all 10270

PDFCreator 2.0 and Visual FoxPro 9.0

$
0
0
I have a client who has been happily using PDFCreator for the past 3 years with her Visual FoxPro 9.0 program. It works like a whistle. Even after PDFCreator updates. No problems. Until now. We have had to revert back to PDFCreator 1.7 so they continue to convert foxpro reports to PDF.

I am adding the PDF conversion code that I have had written. You'll see that I am now checking to see which version of PDFCreator a person has before moving forward. I have looked over the PDFCreator Manual and looked at the COM Object. But I keep getting error after error message.

FUNCTION PrintPDF
* output report to PDF file
* lcReport = name of the FoxPro report file
* lcName = name of the PDF file
***********************************************************
PARAMETERS lcReport, lcName
LOCAL lcNewFile, lcReportFile, lnCount, lcSeconds
lcSeconds = 0
lcNewFile = 'c:\temp\NewFile.pdf'
lcReportFile = STRTRAN(lcName, '"', "_")

IF FILE(lcReportFile)   
    DELETE FILE (lcReportFile)
ENDIF

IF FILE(lcNewFile)   
    DELETE FILE (lcNewFile)
ENDIF

WAIT "Preparing PDF Attachments..." WINDOW AT 35, 35 NOWAIT TIMEOUT 5

LOCAL opdfcreator, isrunning, xpdfversion, oPdfCreatorQueue

isrunning = .F.
xPdfVersion = 0

*!*    *Check to see which version of PDFCreator user is using.
LOCAL xfileName, theString
xfileName = "C:\Program Files\PDFCreator\pdfcreator.exe"

IF FILE(xfilename)
    DIMENSION verArray(1)
    theVal = AGETFILEVERSION(verArray,xfilename)
   
    IF theVal != 0
        theString = ALLTRIM(verArray(4))
        xPdfVersion = VAL(LEFT(theString,1))   
    ENDIF   
ENDIF


IF xpdfVersion >= 2
    *PDFCreator is new version, 2.0 or higher
    opdfcreator = CREATEOBJECT("PDFCreatorBeta.PDFCreator")
   
    isrunning = opdfcreator.IsInstanceRunning()
   
    IF isrunning = .F.
        IF FILE("C:\Program Files\PDFCreator\pdfcreator.exe")
            RUN /n2 "C:\Program Files\PDFCreator\pdfcreator.exe"
        ENDIF
           
    ENDIF
   
    _screen.MousePointer = 11
   

    oPdfCreatorQueue = CREATEOBJECT("PDFCreatorBeta.JobQueue")   
    oPdfCreatorQueue.Initialize()
   
    REPORT FORM (lcReport) TO PRINTER
    SET PRINTER TO default   
       
    * allow up to [LCSECONDS] sec for PDF file to be created
    FOR lnCount = 1 TO lcseconds
        =INKEY(1, 'H')
        IF FILE(lcNewFile)
            EXIT
        ENDIF
    ENDFOR
    =INKEY(1, 'H')
   
       
    IF FILE(lcNewFile)   
        RENAME (lcNewFile) TO (lcReportFile)
    ELSE   
        MESSAGEBOX("PDF File was not created. Please inform System Programmer.")
    ENDIF

    oPdfCreatorQueue.releasecom()
ELSE
    *PDFCreator is a version below 2.0.
    opdfcreator = CREATEOBJECT("PDFCreator.clsPDFCreator")   
                   
    isrunning = opdfcreator.cProgramIsRunning()

    IF isrunning = .F.
        IF FILE("C:\Program Files\PDFCreator\pdfcreator.exe")
            RUN /n2 "C:\Program Files\PDFCreator\pdfcreator.exe"
        ENDIF           
    endif

    _screen.MousePointer = 11


    lcSeconds = 60
    SET PRINTER TO NAME PDFCreator       

    REPORT FORM (lcReport) TO PRINTER
    SET PRINTER TO default

    * allow up to [LCSECONDS] sec for PDF file to be created
    FOR lnCount = 1 TO lcseconds
        =INKEY(1, 'H')
        IF FILE(lcNewFile)
            EXIT
        ENDIF
    ENDFOR
    =INKEY(1, 'H')

    IF FILE(lcNewFile)   
        RENAME (lcNewFile) TO (lcReportFile)
    ELSE   
        MESSAGEBOX("PDF File was not created. Please inform System Programmer.")
    ENDIF
ENDIF

RELEASE opdfcreator, isrunning, xPdfVersion, opdfcreatorqueue
RELEASE xfileName, theString

_screen.MousePointer = 1
RETURN




I have been trying to get the code to work with FoxPro using PDFCreatorQueue.NextJob to create a job object but it isn't working.

oJob = oPDFCreatorQueue.NextJob()

That keeps telling me Ole IDispatcher exception code 0 from PDFCreator: Invalid Index. Please check index parameter.

Followed by:

ojob not an object.

Is there anybody out there who has successfully gotten Visual FoxPro to talk to and use PDFCreator 2.0 COM object?

Thank you
Brandy Williams

Viewing all articles
Browse latest Browse all 10270

Trending Articles