How to print to default printer in a console app

  1. 8 months ago

    Sunil A

    10 Feb 2019 Pre-Release Testers, Xojo Pro Kuwait
    Edited 8 months ago

    Can anyone suggest me a way to print to default printer from console application. I tried to use OpenPrinter and while compilation it says "This item does not exists" whereas no where in the doc it says this command is only for desktop apps. Is there any other method to use in console app other than plugins or declares.

  2. Jean-Yves P

    10 Feb 2019 Pre-Release Testers, Xojo Pro Europe (France, Besançon)

    on mac and linux you can use lp

    NAME

    lp - print files

    SYNOPSIS

    lp [ -E ] [ -U username ] [ -c ] [ -d destination[/instance] ] [ -h
    hostname[:port] ] [ -m ] [ -n num-copies ] [ -o option[=value] ] [ -q
    priority ] [ -s ] [ -t title ] [ -H handling ] [ -P page-list ] [ -- ]
    [ file(s) ]
    lp [ -E ] [ -U username ] [ -c ] [ -h hostname[:port] ] [ -i job-id ] [
    -n num-copies ] [ -o option[=value] ] [ -q priority ] [ -t title ] [ -H
    handling ] [ -P page-list ]

    DESCRIPTION

    lp submits files for printing or alters a pending job. Use a filename
    of "-" to force printing from the standard input.

    THE DEFAULT DESTINATION
    CUPS provides many ways to set the default destination. The LPDEST and
    PRINTER environment variables are consulted first. If neither are set,
    the current default set using the lpoptions(1) command is used, fol-
    lowed by the default set using the lpadmin(8) command.

  3. Jean-Yves P

    10 Feb 2019 Pre-Release Testers, Xojo Pro Europe (France, Besançon)

    on windows you can use lpr

    lpr works great on Win 7 and up. You do not need to copy it. In Control Panel, go to "turn windows features on or off" and make sure "print and document services" are installed.
    To use lpr to send a file to printer that uses the RAW protocol, the syntax is:
    lpr -S <printer name or IP> -P raw <file to send>

    e.g.
    lpr -S 192.168.11.118 -P raw postscript.ps

  4. Christian S

    11 Feb 2019 Pre-Release Testers, Xojo Pro, XDC Speakers, Third Party Store Germany

    Mac? Windows? Linux?

    NSPrintOperationMBS even works on Mac console app as far as I know.

  5. Sunil A

    11 Feb 2019 Pre-Release Testers, Xojo Pro Kuwait

    Its actually for Windows but good if it can work cross platform.

  6. Christian S

    11 Feb 2019 Pre-Release Testers, Xojo Pro, XDC Speakers, Third Party Store Germany

    Please check all the print stuff we have for windows in the MBS Xojo Win Plugin :

    https://www.monkeybreadsoftware.net/pluginpart-windowsprint.shtml

    especially WindowsAddPrintJobMBS class was made to send print data directly to a printer.

or Sign Up to reply!