Author Topic: Printers parameters  (Read 3286 times)

0 Members and 1 Guest are viewing this topic.

Offline Juanjogomez

  • Forum Regular
  • Posts: 117
    • View Profile
Printers parameters
« on: November 13, 2020, 01:50:25 am »
Hello everyone,
A question that I do not know if it is easy or difficult ..... Is it possible to access the printer parameters and change them ?, such as printing double-sided or not? (the printer that has that function)
Thanks

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Printers parameters
« Reply #1 on: November 13, 2020, 04:26:13 am »
In the good 'ol days, we could achieve this by using printer esc codes with the LPRINT statement. Now that those days are behind us, it would mean slaving out to Wordpad, and using .rtf codes. That would take writing an .rtf template, and then saving your text file within that template, and making a SHELL call to print the document. Of course the other alternative is to use a Windows API call. (assuming you are running in Windows). If not, I don't know of any Linux or Apple possibilities. For API calls, https://www.codeproject.com/Articles/132365/Configuring-Printer-Settings-Programmatically and https://docs.microsoft.com/en-us/troubleshoot/windows/win32/modify-printer-settings-setprinter-api might give you some idea of what would be involved.

@ SpriggsySpriggs has made quite a few API library additions. See his work here for what's involved: https://www.qb64.org/forum/index.php?topic=2930.0

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Printers parameters
« Reply #2 on: November 13, 2020, 04:31:24 am »
https://www.qb64.org/forum/index.php?topic=1858.msg111221#msg111221

If you’re using windows, you can use the PRINTER API above to change those settings.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Juanjogomez

  • Forum Regular
  • Posts: 117
    • View Profile
Re: Printers parameters
« Reply #3 on: November 13, 2020, 10:58:45 am »
thanks. I will look at these options

Offline Juanjogomez

  • Forum Regular
  • Posts: 117
    • View Profile
Re: Printers parameters
« Reply #4 on: November 13, 2020, 10:59:48 am »
I use windows

Offline Juanjogomez

  • Forum Regular
  • Posts: 117
    • View Profile
Re: Printers parameters
« Reply #5 on: November 13, 2020, 01:29:04 pm »
I keep trying things.
I have seen that with the command ...

Code: QB64: [Select]
  1. SHELL _HIDE "cmd/c wmic printerconfig where name='printer name' > printer.txt"

The file "printer.txt" has the configuration parameters of the printer.
The value of DUPLEX is FALSE when the printer has the option to write on both sides disabled and TRUE when it is enabled.

I have tried changing that value with .....

Code: QB64: [Select]
  1. SHELL _HIDE "cmd/c wmic printer where name='printer name' set DUPLEX=TRUE"

but since I don't know how to write it, it gives me an error. Does anyone know what the WMIC command would look like to change any printer parameter?

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Printers parameters
« Reply #6 on: November 13, 2020, 02:35:02 pm »
Since I'm not at a PC right now I can't check anything for you but as soon as I get home I will look into this for you and see what would be a good way to fix it.
Shuwatch!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Printers parameters
« Reply #8 on: November 13, 2020, 03:50:58 pm »
@SMcNeill PowerShell is an excellent resource for things like this.
Shuwatch!

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Printers parameters
« Reply #9 on: November 14, 2020, 01:12:33 am »
Here you go, @Juanjogomez
It worked for me. Not sure if it will work exactly for you. Here is the code I used and a screenshot showing what it changed.

Code: QB64: [Select]
  1. printerName$ = "Canon MFC733C"
  2. SHELL _HIDE "PowerShell Get-Printer -Name \" + CHR$(34) + printerName$ + "\" + CHR$(34) + " | Set-PrintConfiguration -DuplexingMode TwoSidedLongEdge"

  [ You are not allowed to view this attachment ]  
Shuwatch!

Offline Juanjogomez

  • Forum Regular
  • Posts: 117
    • View Profile
Re: Printers parameters
« Reply #10 on: November 14, 2020, 05:01:35 am »
Hi SpriggsySpriggs,

I tried your code but it didn´t work
The code that I tried is:

Code: QB64: [Select]
  1. printerName$ = "Brother HL-3150CDW series"
  2. SHELL _HIDE "PowerShell Get-Printer -Name \" + CHR$(34) + printerName$ + "\" + CHR$(34) + "| Set-PrintConfiguration -DuplexingMode TwoSidedLongEdge"
  3.  

Is there any mistake in the code that i didn't see?


Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Printers parameters
« Reply #11 on: November 14, 2020, 01:33:14 pm »
@Juanjogomez What is your build version of Windows and your version of PowerShell? Can you screenshot your Control Panel's Devices and Printers screen? I want to see what the printer's name is as it appears there. By the way, this doesn't change the preferences of the printer. It changes the Printing Defaults. Also, you can try escaping the dash in the printerName$ by putting a caret ^ before the dash. Try that and see if it works. Or, if you only have one printer with Brother in the name, you can change the value of printerName$ to "*brother*". The asterisks are wildcards.
« Last Edit: November 14, 2020, 01:49:15 pm by SpriggsySpriggs »
Shuwatch!

Offline Juanjogomez

  • Forum Regular
  • Posts: 117
    • View Profile
Re: Printers parameters
« Reply #12 on: November 14, 2020, 03:24:00 pm »
My version of Windows is Windows 10 Pro, version 1909, the version of PowerShell is 5.1.18362.1171

I tried width "*Brother*" and "Brother HL^-3150 CDW series" and it didn't work.

I attach the screenshot that you asked me.

Thanks for your interest