Извините я не очень дружен с английским, но знаю что здесь много русско говорящих программистов. Надеюсь мне помогут. У меня есть несколько TRichViewEdit в них лежат направления. Мне нужно сэкономить бумагу. Было бы неплохо несколько направлений размещать на одном листе. Направления должны печататься целиком, нельзя чтобы у направления начало печаталось на одном листе, а конец на другом. Высота направления заранее неизвестна.
How to save paper
How to save paper
The original question was in Russian. A brief translation: how to print several small documents on the same paper sheet, so that page breaks were possible only between documents, not inside them. [Sergey Tkachenko]
-
- Site Admin
- Posts: 17559
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
There are several ways to solve this problem.
1) Use TRVReportHelper component for printing. When printing the next document, compare GetLastPageHeight and the space remaining on the page. Start a new page if greater.
2) Create a large document containing all these small documents. Add rvpaoKeepLinesTogether and rvpaoKeepWithNext in Options of all paragraphs of these documents. Place an empty line without these options between documents.
3) Create a large document containing all these small documents. Place each document inside a table with rvtoRowsSplit excluded from Options.
I'll create an example for #3.
1) Use TRVReportHelper component for printing. When printing the next document, compare GetLastPageHeight and the space remaining on the page. Start a new page if greater.
2) Create a large document containing all these small documents. Add rvpaoKeepLinesTogether and rvpaoKeepWithNext in Options of all paragraphs of these documents. Place an empty line without these options between documents.
3) Create a large document containing all these small documents. Place each document inside a table with rvtoRowsSplit excluded from Options.
I'll create an example for #3.
-
- Site Admin
- Posts: 17559
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
The code below adds the content of Source to the end of Dest inside a table.
This code may look more complicated than expected, because it needs to solve the following problem: Cell.LoadRVFFromStream does not support RVF containing collections of text or paragraph styles.
To solve this problem, we create a temporal hidden TRichView (tempRV) linked to the same RVStyle as Dest, and insert data from Source to tempRV. All necessary styles are added in RVStyle, linked to Dest and tempRV.
After that, the copy data from tempRV to the cell. This RVF does not contain styles (rvfoSaveTextStyles, rvfoSaveParaStyles are excluded from tempRV.RVFOptions), but they are not needed, because tempRV uses the same styles as Dest.
The same technique is used in the demo Assorted\Fields\MailMerge2\
Now, you can add many documents in the same RichView and print it:
This code may look more complicated than expected, because it needs to solve the following problem: Cell.LoadRVFFromStream does not support RVF containing collections of text or paragraph styles.
To solve this problem, we create a temporal hidden TRichView (tempRV) linked to the same RVStyle as Dest, and insert data from Source to tempRV. All necessary styles are added in RVStyle, linked to Dest and tempRV.
After that, the copy data from tempRV to the cell. This RVF does not contain styles (rvfoSaveTextStyles, rvfoSaveParaStyles are excluded from tempRV.RVFOptions), but they are not needed, because tempRV uses the same styles as Dest.
The same technique is used in the demo Assorted\Fields\MailMerge2\
Code: Select all
procedure AddDocInTable(Source, Dest: TCustomRichView);
var table: TRVTableItemInfo;
Stream: TMemoryStream;
tempRV: TCustomRichView;
Color: TColor;
begin
tempRV := TCustomRichView.Create(nil);
try
tempRV.Visible := False;
tempRV.Style := Dest.Style;
tempRV.Parent := Dest.Parent;
tempRV.RVFTextStylesReadMode := rvf_sInsertMerge;
tempRV.RVFParaStylesReadMode := rvf_sInsertMerge;
tempRV.Options := Dest.Options;
tempRV.RVFOptions := Dest.RVFOptions - [rvfoSaveTextStyles, rvfoSaveParaStyles];
Stream := TMemoryStream.Create;
try
Source.SaveRVFToStream(Stream, False);
Stream.Position := 0;
tempRV.Clear;
tempRV.InsertRVFFromStream(Stream, 0);
finally
Stream.Free;
end;
Stream := TMemoryStream.Create;
try
tempRV.SaveRVFToStream(Stream, False);
table := TRVTableItemInfo.CreateEx(1,1,Dest.RVData);
table.BorderWidth := 0;
table.CellBorderWidth := 0;
table.CellPadding := 0;
table.CellHSpacing := 0;
table.CellVSpacing := 0;
table.PrintOptions := table.PrintOptions - [rvtoRowSplit];
Stream.Position := 0;
table.Cells[0,0].LoadRVFFromStream(Stream, Color, nil, nil);
Dest.AddItem('', table);
finally
Stream.Free;
end;
finally
tempRV.Free;
end;
Dest.Format; // <-- remove if you do not need to display Dest
end;
Code: Select all
rvForPrinting.Clear;
AddDocInTable(rvDoc1, RVForPrinting);
AddDocInTable(rvDoc2, RVForPrinting);
AddDocInTable(rvDoc3, RVForPrinting);
<print RVForPrinting here>
Извините я не очень дружен с английским, не удаляйте пожалуйста мой пост. У меня остались вопросы. Очень много бумаги остается из-за не оптимальной компоновки направлений на листах. Имея данные о высоте направлений и листов можно компоновать их более плотно и тратить меньше бумаги. Как мне определить высоту направлений и высоту печатаемой области листа?
-
- Site Admin
- Posts: 17559
- Joined: Sat Aug 27, 2005 10:28 am
- Contact: