trichview.com

trichview.support




Re: More on importing (copying and pasting) documents or document sections with styles?


Return to index


Author

Message

Sergey Tkachenko

Posted: 04/23/2004 13:58:07


> Do you have any guidelines about what this should be set to, to be

> equivalent to A4 and to US Letter sizes?


This code allows to resize RichView so that it approximately corresponds

to the size on the page.


Using:


var w, h: Integer;


// rvoClientTextWidth must be excluded from RichViewEdit1.Options.


GetPageSize(RVPrint1, w,h);

RichViewEdit1.MaxTextWidth :=

  w-RichViewEdit1.LeftMargin-RichViewEdit1.RightMargin;

RichViewEdit1.Format;



procedure GetPageSize(RVPrint: TRVPrint;

                            var Width, Height: Integer);

var DC: HDC;

    phoX, phoY, phW, phH, lpy, lpx, LM, TM, RM, BM: Integer;

begin

  DC := RV_GetPrinterDC; // from PtblRV unit


  Width  := GetDeviceCaps(DC, HORZRES);

  Height := GetDeviceCaps(DC, VERTRES);


  lpy := GetDeviceCaps(DC, LOGPIXELSY);

  lpx := GetDeviceCaps(DC, LOGPIXELSX);


  phoX := GetDeviceCaps(DC, PHYSICALOFFSETX);

  phoY := GetDeviceCaps(DC, PHYSICALOFFSETY);

  phW  := GetDeviceCaps(DC, PHYSICALWIDTH);

  phH  := GetDeviceCaps(DC, PHYSICALHEIGHT);


  LM := MulDiv(RVPrint.LeftMarginMM,   5*lpx, 127)- phoX;

  TM := MulDiv(RVPrint.TopMarginMM,    5*lpy, 127)- phoY;

  RM := MulDiv(RVPrint.RightMarginMM,  5*lpx, 127)- (phW-(phoX+Width));

  BM := MulDiv(RVPrint.BottomMarginMM, 5*lpy, 127)- (phH-(phoY+Height));


  if LM<0 then LM := 0;

  if TM<0 then TM := 0;

  if RM<0 then RM := 0;

  if BM<0 then BM := 0;


  dec(Width, LM+RM);

  dec(Height, TM+BM);


  DeleteDC(DC);


  DC := GetDC(0);

  Width  := MulDiv(Width,  GetDeviceCaps(DC, LOGPIXELSX), lpx);

  Height := MulDiv(Height, GetDeviceCaps(DC, LOGPIXELSY), lpy);

  ReleaseDC(0, DC);


end;


The procedure below allows to set paper size to the current printer:


procedure SetPaperSize(PaperSize: Integer);

  var ADevice, ADriver, APort: array[0..79] of Char;

      ADeviceMode: THandle;

      DevMode: PDeviceMode;

  begin

    Printer.GetPrinter(ADevice,ADriver,APort,ADeviceMode);

    if ADeviceMode<>0 then begin

      DevMode := PDeviceMode(GlobalLock(ADeviceMode))

      end

    else

      raise Exception.Create('Error initializing printer');

    DevMode.dmFields := DevMode.dmFields or DM_PAPERSIZE;

    DevMode.dmPaperSize := PaperSize;

    GlobalUnlock(ADeviceMode);

    Printer.SetPrinter(ADevice,ADriver,APort,ADeviceMode);

  end;


You can see a list of available paper sizes in Windows API Help (Delphi

menu: Help | Windows SDK).

Search DEVMODE in the help index, then search for DMPAPER_*** constants.


For example,  SetPaperSize(DMPAPER_A4)







Powered by ABC Amber Outlook Express Converter