Forum > LCL

[SOLVED] Setting printer properties in PrintDialog

(1/6) > >>

RayoGlauco:
Hi, I want to change some printer settings before printing. (By default, my printer prints only one side and color, but I want to print double-sided and grayscale). I am using a TPrintDialog. When it is displayed, I use the properties button to access the printer properties dialog box that I attached below. Then, I modify the desired options, I accept and send my document to the printer, but the document is printed in color and on one side only, anyway.

Is there something that I am forgetting? Does this dialog work correctly?

This is the code (very simple):


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  with PrintDialog1 do  begin    Copies := 1;    MinPage := 1;    MaxPage := doc.PageCount;    PrintRange := prAllPages;    if Execute then    begin       // Send data to Printer    end;  end;                        
Edit: this test was made on Windows 8. I will test on Windows 10 and Linux, too.

jamie:
Maybe you need to refresh the printer object afterwards ?

Printer.Refresh.

RayoGlauco:
No way. Same result after adding "Printer.Refresh". It seems that the changes I make in the settings are lost/forgotten after closing the TPrintDialog.


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  with PrintDialog1 do  begin    Copies := 1;    MinPage := 1;    MaxPage := doc.PageCount;    PrintRange := prAllPages;    if Execute then    begin      Printer.Refresh;       // Send data to Printer    end;  end;      

wp:
IIRC the printer dialogs are only provided for the user to change parameters. The settings, however, are not transferred to the printer, nor are they stored anywhere automatically. It is your responsibility to apply the settings yourself. Example:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.Button1Click(Sender: TObject);begin  PrintDialog1.Copies := Printer.Copies;  if PrintDialog1.Execute then begin    Printer.Copies := PrintDialog1.Copies;  end;end;

RayoGlauco:
Hello, wp


--- Quote from: wp on May 31, 2018, 03:13:36 pm ---IIRC the printer dialogs are only provided for the user to change parameters. The settings, however, are not transferred to the printer, nor are they stored anywhere automatically. It is your responsibility to apply the settings yourself. Example:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.Button1Click(Sender: TObject);begin  PrintDialog1.Copies := Printer.Copies;  if PrintDialog1.Execute then begin    Printer.Copies := PrintDialog1.Copies;  end;end;
--- End quote ---

I check and use the values in PrintDialog1 (Copies, PrintRange, FromPage, ToPage, etc), but I don't know how to access the values changed in the dialog that opens when the user clicks the button labeled "settings". Can I access these values (duplex, color printing, etc.) by checking some properties of Printer? ... If these values are not transferred to the printer, where are they stored?

edit: I do not know how the temporary configuration of the printer works. What happens when the user changes the configuration using the "settings" dialog offered by TPrinterDialog? Where does Lazarus save the changed parameters? Are they automatically applied to the printout or must the programmer access them to apply them manually?

Navigation

[0] Message Index

[#] Next page

Go to full version