Search code examples
pdfprintingvisual-foxprowindows-scripting

How to print PDF file to printer by printer name part


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 used to set pritner by name.

* 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

Solution

  • You can use the "printto" verb to specify a printer name:

    ShellExecute(0, "printto", cPDFFile , "printername", "", 1)