I can'n to win the margins in preview

General TRichView support forum. Please post your questions here
Post Reply
+ 1
Posts: 11
Joined: Tue Jun 13, 2017 6:13 am

I can'n to win the margins in preview

Post by + 1 »

Hi!
How to delete the margins?
Снимок3.jpg
Снимок3.jpg (39.7 KiB) Viewed 33264 times
Снимок4.jpg
Снимок4.jpg (32.04 KiB) Viewed 33264 times
Снимок5.jpg
Снимок5.jpg (47.31 KiB) Viewed 33264 times
+ 1
Posts: 11
Joined: Tue Jun 13, 2017 6:13 am

Re: I can'n to win the margins in preview

Post by + 1 »

Снимок6.jpg
Снимок6.jpg (39.24 KiB) Viewed 33258 times
C++ Builder RAD Studio 2010
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: I can'n to win the margins in preview

Post by Sergey Tkachenko »

As I can see, you removed all margins, by assigning RVPrint1.Margins = (0, 0, 0, 0), RVPrint1.FixMarginsMode = rvfmmIgnore,
RichViewEdit1.BottomMargin = 0 (I assume that LeftMargin, RightMargin, TopMargin are 0 as well).

With these properties, document must be printed without margins. So the only idea I have, these properties are somehow modified before printing/previewing.

If you can reproduce the problem in a simple project, please send it to me (or attach to the forum)
+ 1
Posts: 11
Joined: Tue Jun 13, 2017 6:13 am

Re: I can'n to win the margins in preview

Post by + 1 »

RVPrint1->BottomMarginMM = 0;
RVPrint1->TopMarginMM = 0;
RVPrint1->LeftMarginMM = 0;
RVPrint1->RightMarginMM = 0;
Снимок9.jpg
Снимок9.jpg (17.86 KiB) Viewed 33230 times
Projects.rar
(5.66 KiB) Downloaded 1745 times
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: I can'n to win the margins in preview

Post by Sergey Tkachenko »

This is the correct result. Printers have "physical margins": they cannot print too close to sheet edges, and the preview shows it.
If you change RVPrint1->FixMarginsMode back to rvfmmAutoCorrect, RVPrint1 sets margins to minimal values (physical margins) preventing this problem.
+ 1
Posts: 11
Joined: Tue Jun 13, 2017 6:13 am

Re: I can'n to win the margins in preview

Post by + 1 »

I do not think so. If width of paper in my printer is 25 mm?
And left margins may be 1 mm?
And this trouble is too. How I can to change size of paper?
Снимок15.jpg
Снимок15.jpg (33.4 KiB) Viewed 33226 times
Снимок14.jpg
Снимок14.jpg (26.98 KiB) Viewed 33226 times
This in trial version only?
+ 1
Posts: 11
Joined: Tue Jun 13, 2017 6:13 am

Re: I can'n to win the margins in preview

Post by + 1 »

И вообще, откуда он знает, какие непечатаемые поля у моего принтера? Мож у меня вообще принтера нет? Или он может загибать текст назад, если он не умещается на лицевой стороне? Это же уже в превью так отображается.
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: I can'n to win the margins in preview

Post by Sergey Tkachenko »

About TRichView.DocParameters.
DocParameters are used to store page information in files, in RTF, DocX and RVF formats, see additional notes in the help topic.
It is not used for printing.
Only RVPrint properties (like Margins) are important, and also a page size of the current printer (see notes about the global Printer below).
You can assign TRichView.DocParameters to TRVPrint using TRVPrint.AssignDocParameters, but it does not assign page size. I can explain how to set paper size for the current printer, if you need.


In Russian, about printer physical margins:
Печать в TRVPrint всегда привязана к конкретному принтеру, тому, который сейчас выбран в приложении (см. объект, который возвращает глобальная функция Printers, принтер выбирается Printer.PrinterIndex). Если нет никакого принтера, то TRVPrint не будет работать. Потому, перед попыткой печати, нужно всегда проверять, чтобы Printer.Printers.Count >= 0.
И, поверьте, у каждого принтера действительно есть "слепая" область по краям страницы. Посмотрите GetDeviceCaps,PHYSICALOFFSETX и PHYSICALOFFSETY - это размеры этой слепой области слева и сверху; размеры с противоположных сторон можно вычислить на основании других значений.

Попробуйте в Microsoft Word установить нулевые поля. Сначала он обругается "Некоторые поля лежат вне области печати", и предложит их исправить. Нажмите "Пропустить", чтобы не исправлять. А теперь перейдите к печати. И вы увидите, что уже на превью края будут точно так же обрезаны! Ну и при печати, разумеется, тоже.
MSWordPhysicalMargins.png
MSWordPhysicalMargins.png (42.68 KiB) Viewed 33215 times
Это ограничение hardware, тут программы ничего делать не могут.
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: I can'n to win the margins in preview

Post by Sergey Tkachenko »

How to change paper size.

TRVPrint uses settings of the current printer. They are returned by the global Printer function.
To change paper orientation (portrait/landscape), assign Printer.Orientation property.

As for changing page format, it's more difficult, we need to use WinAPI functions.

Code: Select all

uses Printers;

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
    DevMode := PDeviceMode(GlobalLock(ADeviceMode))
  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;

function GetPaperSize: 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');
  Result := DevMode.dmPaperSize;
end;
The function SetPaperSize sets page format, GetPaperSize returns page format. They work for the current printer.
All possible page formats are listed here:
https://msdn.microsoft.com/en-us/librar ... s.85).aspx
(DMPAPER_* constant)
For example, SetPaperSize(DMPAPER_A4)
It's also possible to define custom page size instead of choosing a standard format. I can explain how to do it, if you need.
Of course, it works only if the printer supports the specified format.

After changing paper size or orientation, call RVPrint1->FormatPages() before printing/previewing.
+ 1
Posts: 11
Joined: Tue Jun 13, 2017 6:13 am

Re: I can'n to win the margins in preview

Post by + 1 »

Thank You wery match.
Post Reply