Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Printing pdf to specific printer
Message
From
24/01/2019 04:03:13
Lutz Scheffler
Lutz Scheffler Software Ingenieurbüro
Dresden, Germany
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP2
Miscellaneous
Thread ID:
01665681
Message ID:
01665710
Views:
80
>Hi there,
>
>is there a way to set a printer in vfp (set printer to, not changing the default printer)
>and then print a pdf-file? Or do I have to change the default-printer and reset it after ürinting the pdf?
>
>Best regards
>
>Thomas

Hi Thomas,

there is a tricky one pure VFP. It changes the printer backward / forward.

The trick is to get the printer setting from a frx, store it somewhere (the stuff in lcExpr, lcTag, lcTag2, lcPrinter)
main work is SYS(1037,3)
this is a kludge stripped to mostly anything, my code is more tricky, if you need more helpo, let me know
 IF llSetPrinter THEN
*create a report to store recent printer information
  lnOldSelect = SELECT()
  lcRptFile   = ADDBS(GETENV("TEMP"))+"RptRun.FRX"
  lcRptFile2 = SYS(2023)+'\'+SYS(2015)+".FRX"

  CREATE CURSOR TempCur (Temp C (10))

   CREATE REPORT (lcRptFile) FROM TempCur
*/create a report to store recent printer information

  USE IN TempCur
  USE (lcRptFile) EXCLUSIVE ALIAS RptFile
  COPY TO (lcRptFile2)
  SELECT 0
  USE (lcRptFile2) EXCLUSIVE ALIAS RptFile2
  LOCATE
  REPLACE;
   EXPR WITH '',;
   TAG  WITH '',;
   TAG2 WITH ''

    lcOldPrinter =  SET("printer",3)
    SYS(1037,2)

    SELECT RptFile
    LOCATE
    REPLACE;
     EXPR WITH lcExpr,;
     TAG  WITH lcTag,;
     TAG2 WITH lcTag2

    IF VAL(OS(3))*100+VAL(OS(4))>=600 THEN
     TRY
       SET PRINTER TO NAME (lcPrinter)
      CATCH TO loException
     ENDTRY
    ENDIF &&Val(Os(3))*100+Val(Os(4))>=600

    SYS(1037,3)
   CATCH TO loException WHEN loException.ERRORNO=125
* Drucker nicht bereit, vermutlich in SET("Printer")
    llSetErr = True
    USE IN RptFile2
    ERASE (FORCEEXT(lcRptFile2,"*"))
    lcErrMsg = d_GetText("dcDruck_PrintClicked_MB1")
   CATCH TO loException WHEN loException.ERRORNO=1957
* Problem mit Drucker Spooler
    llSetErr = True
    USE IN RptFile2
    ERASE (FORCEEXT(lcRptFile2,"*"))
    lcErrMsg = d_GetText("dcDruck_PrintClicked_MB1")
   CATCH TO loException
* andere Fehler, Standardhandler rufen
    RAISEEVENT(THIS,'ERROR',loException.ERRORNO,loException.PROCEDURE,loException.LINENO)
    llError = doApp.glQuitting
   FINALLY
*
  ENDTRY

  USE IN RptFile
* ERASE (FORCEEXT(lcRptFile,"*"))
  SELECT(lnOldSelect)
 ENDIF &&llSetPrinter

report form .....

  IF llSetPrinter THEN
*nur wenn Bericht, kein Export
   TRY
     SET PRINTER TO NAME (lcOldPrinter)
    CATCH TO loException
   ENDTRY

   SELECT RptFile2
   SYS(1037,3)
   USE IN RptFile2

   SELECT(lnOldSelect)
   ERASE (FORCEEXT(lcRptFile2,"*"))

  ENDIF &&llSetPrinter
and the code to get the printer settings:
lcRptFile  = d_GetTempFileName(,'FRX')	&&SYS(2023)+'\'+SYS(2015)+".FRX"
CREATE CURSOR TempCur (Temp C (10))
CREATE REPORT (lcRptFile) FROM TempCur
USE IN TempCur
USE (lcRptFile) EXCLUSIVE ALIAS RptFile

  IF !EMPTY(SYS(1037,1)) THEN
     lcExpr   = RptFile.EXPR
     lcTag     = RptFile.TAG
     lcTag2   = RptFile.TAG2
     lcPrinter = lcPrinter
  ENDIF &&!EMPTY(SYS(1037,1))

  IF VAL(OS(3))*100+VAL(OS(4))>=600 THEN
   SET PRINTER TO NAME (lcOldPrinter)
  ENDIF &&Val(Os(3))*100+Val(Os(4))>=600

USE IN RptFile
ERASE (FORCEEXT(lcRptFile,"*")
So I use a report to get the printer information the customer needs, store it somewhere and restore this on printing.

I can show you the whole stuff with errorhandling, but this is to much to translate for now.
Words are given to man to enable him to conceal his true feelings.
Charles Maurice de Talleyrand-Périgord

Weeks of programming can save you hours of planning.

Off

There is no place like [::1]
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform