Print Using Custom Page Sizes on Windows NT and Windows 2000

Please post bug reports, feature requests, or any question regarding the DELPHI AREA products here.

Print Using Custom Page Sizes on Windows NT and Windows 2000

Postby mc » June 17th, 2004, 8:17 pm

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 June 22nd, 2004, 9:37 pm, edited 2 times in total.
mc
Active Member
Active Member
 
Posts: 9
Joined: June 17th, 2004, 8:01 pm

Postby Kambiz » June 18th, 2004, 8:43 pm

I try to include it in TPrintPreview during this weekend.

Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2408
Joined: March 7th, 2003, 7:10 pm

Postby mc » June 18th, 2004, 9:29 pm

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 http://www.developpez.com/ in forum http://www.developpez.net/forums/viewtopic.php?t=209356

mc
mc
Active Member
Active Member
 
Posts: 9
Joined: June 17th, 2004, 8:01 pm

Postby Kambiz » June 19th, 2004, 4:24 am

Thank you very much.
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2408
Joined: March 7th, 2003, 7:10 pm

Postby Kambiz » June 19th, 2004, 7:37 pm

It's done. :wink:

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
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2408
Joined: March 7th, 2003, 7:10 pm

Postby mc » June 20th, 2004, 8:18 am

Bravo :D
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: :oops: how can define margins with PrintPreview and how to save user defined printer's parameters to use them in the next printing.

mc
mc
Active Member
Active Member
 
Posts: 9
Joined: June 17th, 2004, 8:01 pm

Postby Kambiz » June 20th, 2004, 8:55 am

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.
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2408
Joined: March 7th, 2003, 7:10 pm

Postby mc » June 20th, 2004, 9:58 pm

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
mc
Active Member
Active Member
 
Posts: 9
Joined: June 17th, 2004, 8:01 pm

Postby Kambiz » June 20th, 2004, 10:35 pm

Did you try something like this?

Code: Select all
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;
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2408
Joined: March 7th, 2003, 7:10 pm

Postby mc » June 20th, 2004, 10:38 pm

Yes I do... of corse
On what OS you are working please?
mc
Last edited by mc on June 22nd, 2004, 9:38 pm, edited 1 time in total.
mc
Active Member
Active Member
 
Posts: 9
Joined: June 17th, 2004, 8:01 pm

Postby Kambiz » June 21st, 2004, 9:22 am

Windows XP!

I don't have NT 4.0 or 2000 around.
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2408
Joined: March 7th, 2003, 7:10 pm

Postby mc » June 21st, 2004, 8:23 pm

Hello Kambiz

In the article on Microsoft Knowledge Base published under Q282474 :
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
mc
Active Member
Active Member
 
Posts: 9
Joined: June 17th, 2004, 8:01 pm

Postby Kambiz » June 22nd, 2004, 7:55 am

Well, I thought Delphi's printer object does this task, but I was wrong.

Please replace the SetPrinterOptions method with the following one:

Code: Select all
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.
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2408
Joined: March 7th, 2003, 7:10 pm

Postby mc » June 22nd, 2004, 9:00 pm

Hi Kambiz
Not yet, there is no change :cry:
Have you please someone that have Windows 2000 or Windows NT to try Forms and to see by yourself?
Thank you.
mc
mc
Active Member
Active Member
 
Posts: 9
Joined: June 17th, 2004, 8:01 pm

Postby Kambiz » June 23rd, 2004, 10:00 am

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
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2408
Joined: March 7th, 2003, 7:10 pm

Next

Return to DELPHI AREA Products

Who is online

Users browsing this forum: No registered users and 2 guests