Print Using Custom Page Sizes on Windows NT and Windows 2000
Select messages from
# through # FAQ
[/[Print]\]
Goto page 1, 2  Next  :| |:
DELPHI AREA -> DELPHI AREA's Products

#1: Print Using Custom Page Sizes on Windows NT and Windows 2000 Author: mc PostPosted: 17/06/04 20:17
    —
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

#2:  Author: KambizLocation: Tehran, Iran PostPosted: 18/06/04 20:43
    —
I try to include it in TPrintPreview during this weekend.

Kambiz

#3:  Author: mc PostPosted: 18/06/04 21:29
    —
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

#4:  Author: KambizLocation: Tehran, Iran PostPosted: 19/06/04 04:24
    —
Thank you very much.

#5:  Author: KambizLocation: Tehran, Iran PostPosted: 19/06/04 19:37
    —
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

#6:  Author: mc PostPosted: 20/06/04 08:18
    —
Bravo Very Happy
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: Embarassed how can define margins with PrintPreview and how to save user defined printer's parameters to use them in the next printing.

mc

#7:  Author: KambizLocation: Tehran, Iran PostPosted: 20/06/04 08:55
    —
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.

#8:  Author: mc PostPosted: 20/06/04 21:58
    —
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

#9:  Author: KambizLocation: Tehran, Iran PostPosted: 20/06/04 22:35
    —
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;

#10:  Author: mc PostPosted: 20/06/04 22:38
    —
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

#11:  Author: KambizLocation: Tehran, Iran PostPosted: 21/06/04 09:22
    —
Windows XP!

I don't have NT 4.0 or 2000 around.

#12:  Author: mc PostPosted: 21/06/04 20:23
    —
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

#13:  Author: KambizLocation: Tehran, Iran PostPosted: 22/06/04 07:55
    —
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.

#14:  Author: mc PostPosted: 22/06/04 21:00
    —
Hi Kambiz
Not yet, there is no change Crying or Very sad
Have you please someone that have Windows 2000 or Windows NT to try Forms and to see by yourself?
Thank you.
mc

#15:  Author: KambizLocation: Tehran, Iran PostPosted: 23/06/04 10:00
    —
I'm sorry, but I don't have access to any NT or W2K machine. Sad

Could you please check out the attached update?

Thank you,
Kambiz



DELPHI AREA -> DELPHI AREA's Products


output generated using printer-friendly topic mod. All times are GMT

Goto page 1, 2  Next  :| |:
Page 1 of 2

Powered by phpBB © 2001, 2005 phpBB Group