| View previous topic :: View next topic |
| Author |
Message |
mc Member
Joined: 17 Jun 2004 Posts: 9
|
Posted: 17/06/04 20:17 Post subject: Print Using Custom Page Sizes on Windows NT and Windows 2000 |
|
|
I just discover your very good TPrinterPreview, and I see that it's Great.
On systems that are running Windows NT and Windows 2000, we must define all page sizes as a form before we can use them...
It's my problem.
I just try TPrintPreview and it's not solving my problem.
I have see an article on the microsoft site that describe my problem.
But the solution is given in VB. Can you help please to adapt it to Delphi and to your good (very good) component.
Thank you in advance.
Sorry for my english.
The article is on Microsoft Knowledge Base published under Q282474
the link is:
http://support.microsoft.com/default.aspx?scid=kb;en-us;282474
mc
Last edited by mc on 22/06/04 21:37; edited 2 times in total |
|
| Back to top |
|
 |
Kambiz Administrator
Joined: 07 Mar 2003 Posts: 518 Location: Tehran, Iran
|
Posted: 18/06/04 20:43 Post subject: |
|
|
I try to include it in TPrintPreview during this weekend.
Kambiz
|
|
| Back to top |
|
 |
mc Member
Joined: 17 Jun 2004 Posts: 9
|
Posted: 18/06/04 21:29 Post subject: |
|
|
I can't believe what I'm reading....
Imagine that I have products that I spend a lot of money to get them and when I ask for a few new improvements, the only answer that I get is that it will be included in the next release (next month or the next year....).
And now, you say that it will be done this weekend I just say I'm very happy.
Sorry for my english. But I hope that you understand me.
Thank you.
I will put links to your web site in every place possible.
I had put-it in a french developpement site [url]http://www.developpez.com/ [/url] in forum http://www.developpez.net/forums/viewtopic.php?t=209356
mc
|
|
| Back to top |
|
 |
Kambiz Administrator
Joined: 07 Mar 2003 Posts: 518 Location: Tehran, Iran
|
Posted: 19/06/04 04:24 Post subject: |
|
|
| Thank you very much.
|
|
| Back to top |
|
 |
Kambiz Administrator
Joined: 07 Mar 2003 Posts: 518 Location: Tehran, Iran
|
Posted: 19/06/04 19:37 Post subject: |
|
|
It's done.
To manage forms, the FormName property and FetchFormNames, GetFormSize, AddNewForm, and RemoveForm methods are added.
Please look at the readme file for more information.
Cheers
Kambiz
|
|
| Back to top |
|
 |
mc Member
Joined: 17 Jun 2004 Posts: 9
|
Posted: 20/06/04 08:18 Post subject: |
|
|
Bravo
You are the best.
I tried it. It works very good but only like your previous pCustum do.
in the PrintPreview window all ok, but like with pCustum, when I send it to printer (print) and if I don't make manually default paper to custum it prints wrong.
If I have for example A4 default paper size, and I sent a job with custom size, it prints on a custum size but the datas are printed proportional custom/A4.
I have a HP Deskjet990Cxi printer but I don't think that the problem is from printer driver because with Microsoft Word and Excel and so on.. when I sent a job to the same printer with custom size and in the same time the default printer's paper size is standard one, it print very good.
An other point: how can define margins with PrintPreview and how to save user defined printer's parameters to use them in the next printing.
mc
|
|
| Back to top |
|
 |
Kambiz Administrator
Joined: 07 Mar 2003 Posts: 518 Location: Tehran, Iran
|
Posted: 20/06/04 08:55 Post subject: |
|
|
The component doesn't automatically add/select a new custom form when the paper is in custom size. So, instead of setting the custom paper size, your program should add a new form, and then select it in the component.
By the way, a printer might be unable to use some forms or custom paper sizes. Please read Windows NT Print Manager and Custom Form Limitations for more information.
Also, the component does handle neither page margins nor user defined printer's parameters. It's the developer's responsibility to manage them in his/her own way.
|
|
| Back to top |
|
 |
mc Member
Joined: 17 Jun 2004 Posts: 9
|
Posted: 20/06/04 21:58 Post subject: |
|
|
On the same machine with the same OS and the same printer, Microsoft Word is doing things very good. It's why I am sure that the solution exists.
I will continue to investigate and search this solution. And every body can help welcome. It's for me and for all the users of PrintPreview.
Thank you for the time reading this.
mc
|
|
| Back to top |
|
 |
Kambiz Administrator
Joined: 07 Mar 2003 Posts: 518 Location: Tehran, Iran
|
Posted: 20/06/04 22:35 Post subject: |
|
|
Did you try something like this?
| Code: | procedure TMainForm.FormCreate(Sender: TObject);
begin
PrintPreview.AddNewForm('My Custom Form', 10000 {x 0.01 mm}, 10000 {x 0.01 mm});
PrintPreview.FormName := 'My Custom Form';
end;
procedure TMainForm.FormDestroy(Sender: TObject);
begin
PrintPreview.RemoveForm('My Custom Form');
end; |
|
|
| Back to top |
|
 |
mc Member
Joined: 17 Jun 2004 Posts: 9
|
Posted: 20/06/04 22:38 Post subject: |
|
|
Yes I do... of corse
On what OS you are working please?
mc
Last edited by mc on 22/06/04 21:38; edited 1 time in total |
|
| Back to top |
|
 |
Kambiz Administrator
Joined: 07 Mar 2003 Posts: 518 Location: Tehran, Iran
|
Posted: 21/06/04 09:22 Post subject: |
|
|
Windows XP!
I don't have NT 4.0 or 2000 around.
|
|
| Back to top |
|
 |
mc Member
Joined: 17 Jun 2004 Posts: 9
|
Posted: 21/06/04 20:23 Post subject: |
|
|
Hello Kambiz
In the article on Microsoft Knowledge Base published under Q282474 :
| Quote: | | Retrieve the printer's DEVMODE structure, set the dmFormName member, and use the ResetDC function to set this form as the current form for the Device Context (DC) of the printer. When this form is selected for the DC, it is only selected for the calling process and does not change the driver's default setting. This does not require any special permissions. This method is preferred for applications that change a printer's settings. |
I had exams your source code and I don't find a call to ResetDC.
What do you think?
mc
|
|
| Back to top |
|
 |
Kambiz Administrator
Joined: 07 Mar 2003 Posts: 518 Location: Tehran, Iran
|
Posted: 22/06/04 07:55 Post subject: |
|
|
Well, I thought Delphi's printer object does this task, but I was wrong.
Please replace the SetPrinterOptions method with the following one:
| Code: | procedure TPrintPreview.SetPrinterOptions;
var
DeviceMode: THandle;
DevMode: PDeviceMode;
Device, Driver, Port: array[0..MAX_PATH] of Char;
PaperSize: TPoint;
DriverInfo2: PDriverInfo2;
DriverInfo2Size: DWORD;
hPrinter: THandle;
TheFormName: String;
begin
if PrinterInstalled then
begin
TheFormName := FormName;
Printer.GetPrinter(Device, Driver, Port, DeviceMode);
OpenPrinter(Device, hPrinter, nil);
try
DevMode := PDevMode(GlobalLock(DeviceMode));
try
with DevMode^ do
begin
dmFields := dmFields or DM_PAPERSIZE;
if IsCustomPaper then
begin
PaperSize := ConvertXY(FPageExt.X, FPageExt.Y, FUnits, mmLoMetric);
if FOrientation = poLandscape then
SwapValues(PaperSize.X, PaperSize.Y);
dmPaperSize := DMPAPER_USER;
dmFields := dmFields or DM_PAPERWIDTH;
dmPaperWidth := PaperSize.X;
dmFields := dmFields or DM_PAPERLENGTH;
dmPaperLength := PaperSize.Y;
end
else
begin
dmPaperSize := PaperSizes[FPaperType].ID;
dmFields := dmFields and not (DM_PAPERWIDTH or DM_PAPERLENGTH);
end;
dmFields := dmFields or DM_ORIENTATION;
case FOrientation of
poPortrait: dmOrientation := DMORIENT_PORTRAIT;
poLandscape: dmOrientation := DMORIENT_LANDSCAPE;
end;
if TheFormName <> '' then
begin
dmFields := dmFields or DM_FORMNAME;
StrPLCopy(dmFormName, TheFormName, CCHFORMNAME);
end;
ResetDC(Printer.Handle, DevMode^);
end;
finally
GlobalUnlock(DeviceMode);
end;
GetPrinterDriver(hPrinter, nil, 2, nil, 0, DriverInfo2Size);
GetMem(DriverInfo2, DriverInfo2Size);
try
GetPrinterDriver(hPrinter, nil, 2, DriverInfo2, DriverInfo2Size, DriverInfo2Size);
StrPCopy(Driver, ExtractFileName(StrPas(DriverInfo2^.PDriverPath)));
finally
FreeMem(DriverInfo2, DriverInfo2Size);
end;
finally
ClosePrinter(hPrinter);
end;
Printer.SetPrinter(Device, Driver, Port, DeviceMode);
end;
end; |
I hope that was the problem.
|
|
| Back to top |
|
 |
mc Member
Joined: 17 Jun 2004 Posts: 9
|
Posted: 22/06/04 21:00 Post subject: |
|
|
Hi Kambiz
Not yet, there is no change
Have you please someone that have Windows 2000 or Windows NT to try Forms and to see by yourself?
Thank you.
mc
|
|
| Back to top |
|
 |
Kambiz Administrator
Joined: 07 Mar 2003 Posts: 518 Location: Tehran, Iran
|
Posted: 23/06/04 10:00 Post subject: |
|
|
I'm sorry, but I don't have access to any NT or W2K machine.
Could you please check out the attached update?
Thank you,
Kambiz
|
|
| Back to top |
|
 |
|