Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Print PDF file to printer by part of name
Message
From
19/02/2021 16:11:04
 
 
To
19/02/2021 15:32:25
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
01678474
Message ID:
01678476
Views:
91
This message has been marked as the solution to the initial question of the thread.
Likes (1)
>How to print pdf file to printer whose name contains "labelprinter" in Windows 10 from desktop application ?
>
>I tried code below in Visual Foxpro but it prints to windows default printer.
>Can some bat file or automation used.
>
> * cPDFFile - name of PDF file to print
>
>    nprinter  = aprinters(aprinterid)
>    for i=1 to nPrinters
>      if 'labelprinter'$lowe( aprinterid[i,1] )
>        DECLARE INTEGER ShellExecute IN shell32.dll ;
>        INTEGER hndWin, ;
>        STRING cAction, ;
>        STRING cFileName, ;
>        STRING cParams, ;
>        STRING cDir, ;
>        INTEGER nShowWin
>        set printer to name (aprinterid[i,1])
>        ShellExecute(0, "print", cPDFFile , "", "", 1)
>        exit
>        endif
>      endfor
Andrus, setting VFP's printer won't change the printer used by the application that prints PDF documents in your system. You must set the default printer in your system, not in VFP.

So,
DECLARE INTEGER SetDefaultPrinter IN winspool.drv STRING PrinterName
SetDefaultPrinter(aprinterid[i,1])
Probably you should also consider getting the current default printer previously, to restore it later, so that your users won't get confused.
DECLARE INTEGER GetDefaultPrinter IN winspool.drv STRING @ PrinterName, INTEGER @ NameLength

LOCAL DefaultPrinter AS String
LOCAL NameLength AS Integer

m.NameLength = 0

GetDefaultPrinter(NULL, @m.NameLength)

m.DefaultPrinter = SPACE(m.NameLength + 1)

GetDefaultPrinter(@m.DefaultPrinter, @m.NameLength)

m.DefaultPrinter = LEFT(m.DefaultPrinter, m.NameLength - 1)
----------------------------------
António Tavares Lopes
Previous
Reply
Map
View

Click here to load this message in the networking platform