none
Command Line Printing of PDF File from VFP RRS feed

  • Question

  • We have a directory where PDF files from another company will be kept.  Using Visual FoxPro 7.0, I need to be able to go to this directory, find a specific file, then print it to the printer (on our network and mapped) specified by the user.  I have found hundreds of solutions for creating the PDF's but none for simply printing them.  Please help!
    Pat McLaughlin
    Tuesday, November 30, 2010 9:17 PM

Answers

  • Hi Pat,

    I assume, that this is just one of the already found 100 solutions, but to print a pdf you can use SHELLEXECUTE with "printto" option.

    DECLARE Integer ShellExecute ;
       IN shell32.dll ;
       Integer hwndParent, ;
       String cVerb, ;
       String cFilename, ;
       String cParameters, ;
       String cDirectory, ;
       Integer nCmdShow
    
    ShellExecute( _SCREEN.HWnd , [printto] , lcFile , ["] + lcPrinter + ["] , [] , 0 )
    
    CLEAR DLLS [ShellExecute]
    

    Just replace lcFile by your PDF file and lcPrinter by the user specific printer.

     


    Gruss / Best regards -Tom 010101100100011001010000011110000101001001101111011000110110101101110011
    • Edited by Tom BorgmannEditor Wednesday, December 1, 2010 6:40 AM changed 1.Param in Shellexecute
    • Marked as answer by Pat McLaughlin Wednesday, December 1, 2010 2:22 PM
    • Unmarked as answer by Pat McLaughlin Friday, December 10, 2010 1:34 PM
    • Marked as answer by Martin_Xie Tuesday, December 14, 2010 4:33 AM
    Tuesday, November 30, 2010 10:19 PM
    Moderator
  • you can terminate Acrobate reader.

    check following link

    How to terminate other windows process

    http://www.tek-tips.com/viewthread.cfm?qid=1398446&page=9

     


    Please "Mark as Answer" if this post answered your question. :)

    Kalpesh Chhatrala | Software Developer | Rajkot | India

    Kalpesh 's Blog

    VFP Form to C#, Vb.Net Conversion Utility
    • Marked as answer by Martin_Xie Tuesday, December 14, 2010 4:33 AM
    Friday, December 10, 2010 1:52 PM
    Answerer
  • I found my answer is the following code placed after the "ENDFOR"

     

    DDEChan = DDEInitiate("Acroview", "Control")

    =DDEExecute(DDEChan, '[CloseAllDocs()]')

    =DDEEXECUTE(ddechan, ' [AppExit] ' )

     

    Now all is happy on this application.  Thank you for your help!


    Pat McLaughlin
    • Marked as answer by Pat McLaughlin Tuesday, December 14, 2010 3:43 PM
    Tuesday, December 14, 2010 3:41 PM

All replies

  • Hi Pat,

    I assume, that this is just one of the already found 100 solutions, but to print a pdf you can use SHELLEXECUTE with "printto" option.

    DECLARE Integer ShellExecute ;
       IN shell32.dll ;
       Integer hwndParent, ;
       String cVerb, ;
       String cFilename, ;
       String cParameters, ;
       String cDirectory, ;
       Integer nCmdShow
    
    ShellExecute( _SCREEN.HWnd , [printto] , lcFile , ["] + lcPrinter + ["] , [] , 0 )
    
    CLEAR DLLS [ShellExecute]
    

    Just replace lcFile by your PDF file and lcPrinter by the user specific printer.

     


    Gruss / Best regards -Tom 010101100100011001010000011110000101001001101111011000110110101101110011
    • Edited by Tom BorgmannEditor Wednesday, December 1, 2010 6:40 AM changed 1.Param in Shellexecute
    • Marked as answer by Pat McLaughlin Wednesday, December 1, 2010 2:22 PM
    • Unmarked as answer by Pat McLaughlin Friday, December 10, 2010 1:34 PM
    • Marked as answer by Martin_Xie Tuesday, December 14, 2010 4:33 AM
    Tuesday, November 30, 2010 10:19 PM
    Moderator
  • Why do you need to use VFP for this task?

    Many other tools exist, e.g. http://www.a-pdf.com/batch-print/, http://www.traction-software.co.uk/batchprint/index.html

    Another option is to print PDF by executing BAT file from VFP: http://www.robvanderwoude.com/printfiles.php#PrintPDF

     

    Tuesday, November 30, 2010 10:24 PM
    Moderator
  • Wow are we close...    The exception being that with this code, I get (Error 1300) Function Name is missing.  Help states that either the current line (ShellExecute Line ) contains a left parenthesis which has not been matched.  (Not that I can see )  or The function contains too many arguments and thus the right parenthesis is undetected.

     


    Pat McLaughlin
    Wednesday, December 1, 2010 2:21 PM
  • Got it!  All I needed was [brackets] around the printer name!  Thank you soooooo much!

    Pat McLaughlin
    Wednesday, December 1, 2010 2:22 PM
  • Our organization runs all of its computer information both PC and mainframe through a "Hub" program written in VFP that works like a traffic cop, parsing and distributing all the data, fax, emails etc both incoming and outbound.  Until we finish writing a new application to replace it we must work within its bounds.

    Pat McLaughlin
    Wednesday, December 1, 2010 2:27 PM
  • Cool! 

    Then the question is: Why do you need to replace it?

    Wednesday, December 1, 2010 2:32 PM
    Moderator
  • Only because it is getting harder and harder to get support and it is proving to be a real challenge to evolve i.e. Windows 7 and 64bit etc.

    Pat McLaughlin
    Wednesday, December 1, 2010 2:36 PM
  • Hmm, VFP works well on W7/64, I would not rate it as a challenge because applications are almost 100% compatible, the support is still excellent (you've got the answer in one hour for a free :-), so what else to ask?

    I am guessing even Windows 8 will be moreless compatible. The challenge will come with the Windows 9 and I may bet even your new non-VFP solution will have problems... But that is far in the future (and beyond 2012 :-).

    So, have a nice times with porting VFP app to "somewhere else". I still believe in (VFP compatible) xBase language.

    Wednesday, December 1, 2010 2:54 PM
    Moderator
  • This solution does everything I needed, better than I expected but with one small hook.  When the "ShellExecute" is executed, the program opens Adobe Reader, prints the document, returns control to the Foxpro program to continue but fails to close the Adobe Reader program.  Any suggestions for how to complete the process?  See my code below...

     

    LParameters tnCopies, tnTray, tcPrinter, tcRptName
    ** The following routine necessary to print to specific printer **
    LOCAL lcTempRpt, lcPrConfig, lnOrientation, lnPaperSize, lnCopies

    DO WRITELOG WITH "******** Starting " + SYS(16)

    DECLARE Integer ShellExecute ;
       IN shell32.dll ;
       Integer hwndParent, ;
       String cVerb, ;
       String cFilename, ;
       String cParameters, ;
       String cDirectory, ;
       Integer nCmdShow

    lnOrientation=0  && Portrait
    lnPaperSize=1    && Letter (8 1/2 x 11")
    lnCopies = 1

    lcNA_FName = "F:\FormProc\retlstkr\DKY_Not_Available.pdf"

    SELECT TMRETLHD
    lcFname = ALLTRIM(TMRETLHD.Pdffile)
        IF FILE(lcFname)
            && Name stays the same
        ELSE
            lcFname = (lcNA_FName)
        ENDIF
    Select netprint
    Seek tcPrinter
    If Found() THEN
        lcPName = Alltrim(netprint.queue)
    Else
        Do WRITELOG With "[ERR] Printer name invalid -" + lcPrinter
        COPY TO ('c:\printerlist.csv') TYPE DELIMITED
        DO SIMPEM01 WITH "wilbiradmin@winnebagoind.com", "dba@winnebagoind.com", "Printer not mapped correctly in RSREPT03", "", "", "KA", "c:\printerlist.csv"
        llError = .T.
    Endif


    lcPrConfig=printconfig(netprint.generic,lnOrientation,lnPaperSize,lnCopies,tnTray)

    FOR X = 1 TO tnCopies

    * Copy report structure to temporary file and change setting on temp file
        SELECT 0
        USE RSREPT03.FRX
        COPY To RSREPTTM.FRX
        USE RSREPTTM.FRX
        LOCATE For OBJTYPE = 1 And OBJCODE = 53
        REPLACE TAG With ""
        REPLACE TAG2 With ""
        REPLACE EXPR With lcPrConfig
        USE

        * Create Macro variable so this code won't cause an error at compile time
        lcTempRpt = "RSREPTTM"
        SELECT TMRETLHD
       
        IF glPreview
           Report Form (lcTempRpt) Preview
        ELSE
           REPORT Form (lcTempRpt) To Printer NoConsole
        ENDIF

        ShellExecute( _SCREEN.HWnd , [printto] , (lcFName) , ["] + (lcPName) + ["] , [] , 0 )
       
         
       ENDFOR


        CLEAR DLLS [ShellExecute]
     
    RETURN


    Pat McLaughlin
    Friday, December 10, 2010 1:43 PM
  • you can terminate Acrobate reader.

    check following link

    How to terminate other windows process

    http://www.tek-tips.com/viewthread.cfm?qid=1398446&page=9

     


    Please "Mark as Answer" if this post answered your question. :)

    Kalpesh Chhatrala | Software Developer | Rajkot | India

    Kalpesh 's Blog

    VFP Form to C#, Vb.Net Conversion Utility
    • Marked as answer by Martin_Xie Tuesday, December 14, 2010 4:33 AM
    Friday, December 10, 2010 1:52 PM
    Answerer
  • I found my answer is the following code placed after the "ENDFOR"

     

    DDEChan = DDEInitiate("Acroview", "Control")

    =DDEExecute(DDEChan, '[CloseAllDocs()]')

    =DDEEXECUTE(ddechan, ' [AppExit] ' )

     

    Now all is happy on this application.  Thank you for your help!


    Pat McLaughlin
    • Marked as answer by Pat McLaughlin Tuesday, December 14, 2010 3:43 PM
    Tuesday, December 14, 2010 3:41 PM