Printing - new papersize creation lazarus / 23-Operating Systems ---------------------------------------------------------------------- drschwarcz · 2014-09-05 19:33 Hi! I would need to create size A5 if does not exist in the system, which is half of size A4. I have no any solution for now. If someone has experience in printing, then I would really appreciate it. Thanks in advance. Op. system: Windows 8.1, or Windows 7 ---------------------------------------------------------------------- howardpc · 2014-09-05 21:45 All modern printers support A5 as a paper size (even American ones which default to inches rather than metric and have Letter as default size). Drop a TPageSetupDialog (rightmost icon on Dialogs tab) on your form, and invoke it say in a button OnClick handler viaCode: [Select]  PageSetupDialog1.Execute; at runtime. In the "Paper" groupbox of the dialog there is a "Size" dropdown which will reveal A5 along with various other settings for your default printer. See image below. ---------------------------------------------------------------------- rvk · 2014-09-05 22:29 Quote from: howardpc on September 05, 2014, 11:45:57 pmDrop a TPageSetupDialog (rightmost icon on Dialogs tab) on your form, and invoke it say in a button OnClick handler via...Or if you don't want the user of your program to do this manually you can do it in code: Code: [Select]Printer.PaperSize.PaperName:='A5'; ---------------------------------------------------------------------- drschwarcz · 2014-09-05 22:32 It's clear for me. I do not want to use Dialog, I would like to handle from my application. ...and unfortunately, size A5 is not known by each printer, for instance my printer does not have this size in defaults. RVK: Yes, I can set the name if it exists. ---------------------------------------------------------------------- rvk · 2014-09-05 22:59 Quote from: drschwarcz on September 06, 2014, 12:32:03 am...and unfortunately, size A5 is not known by each printer, for instance my printer does not have this size in defaults. There is a topic here where there is some code to add a custom papersize (if A5 does not exists) but it's for Delphi (and no answer for FPC). It should get you started. (I can't test this myself at the moment). I take it you get an exception if you try to set A5 and A5 is not defined. You can catch that exception and try to add the custom size and try to set it again. If it fails again your routine should end and not print (because the custom size failed too). B.T.W. Did you try adding A5 manually as custom papersize in the printer configuration? And did that work when you choose that papername from Lazarus? (Just to make sure that A5 is supported on the printer itself because there might be a reason it's not in the default papersizes.) ---------------------------------------------------------------------- drschwarcz · 2014-09-05 23:12 Physically, the printer is able to print in A5 format if I add it to list and I can also choose from. THX for your tips. I will check that during the day. ---------------------------------------------------------------------- rvk · 2014-09-06 11:33 I'm not sure if you've already got around to it... But here is an attempt to set the custom papersize to A5. (i can't test this for myself at this moment but i'm sure you can) (You need to decide if it's 21x14,85 or 14,85x21) I'm sure i did some things wrong (i.e. not setting a GlobalLock and Unlock on devmode etc.) but this should work for now. We can worry about cleaning it up when it works. (preferably as a separate function to set custom-paper size.) Code: [Select]uses Printers, OSPrinters, Windows, WinUtilPrn; // ... const   DMPAPER_USER = 0; // Why is this not defined in defines.inc ?????? procedure TForm1.Button1Click(Sender: TObject); var   PDev: TPrinterDevice;   dmW: PDeviceModeW;   dmA: PDeviceModeA; begin   PDev := TPrinterDevice(Printer.Printers.Objects[Printer.PrinterIndex]);   if UseUnicode then   begin     dmW := PDev.DevModeW;     dmW^.dmFields := DM_PAPERLENGTH or DM_PAPERWIDTH or DM_PAPERSIZE or DM_SCALE;     dmW^.dmPaperLength := round(21 * 100); // 1/10 of mm     dmW^.dmPaperWidth := round(14.85 * 100); // 1/10 of mm     dmW^.dmPaperSize := DMPAPER_USER; // Custom Size, DMPAPER_A5     dmW^.dmScale := 100;     ResetDCW(Printer.Canvas.Handle, dmW);   end   else   begin     dmA := PDev.DevModeA;     dmA^.dmFields := DM_PAPERLENGTH or DM_PAPERWIDTH or DM_PAPERSIZE or DM_SCALE;     dmA^.dmPaperLength := round(21 * 100); // 1/10 of mm     dmA^.dmPaperWidth := round(14.85 * 100); // 1/10 of mm     dmA^.dmPaperSize := DMPAPER_USER; // Custom Size, DMPAPER_A5     dmA^.dmScale := 100;     ResetDCA(Printer.Canvas.Handle, dmA);   end;   Printer.BeginDoc;   // ... do you thing   Printer.EndDoc; end; ---------------------------------------------------------------------- drschwarcz · 2014-09-06 16:34 THX, it looks great. I will try your code soon. ---------------------------------------------------------------------- drschwarcz · 2014-10-01 19:28 Hi RVK, Code is pasted to my program. The print preview is fine, but the real papersize is still A4. I currently testing with Abode Acrobat (I have no printer at home), but I going to test it in a real printer tomorrow and I will come back with the result.  Good night!