1) Scaling images 50% of paper/orientation selection (rve2 image table has 2 cells) with aspect ratio preserved
Code: Select all
procedure TfRichView.Print1Click(Sender: TObject);
var
PrintIt, Filtered: Boolean;
ClientName, s: String;
table, table2: TRVTableItemInfo;
i, j, k, l, r, c, w: Integer;
ItemInfo: TCustomRVItemInfo;
//
jpeg: TJPEGImage;
bm: TBitmap;
//
RVData: TCustomRVFormattedData;
CRLF, CaptionInfo: String;
//
ClientImagesCount, ModCount, RowCount, CellCount, ClassificationNotesCount, CurTextStyleNo, CurParStyleNo, ID: Integer;
bs, bsF: TEDBBlobStream;
mss: TStringStream;
ms: TMemoryStream;
begin
//
ClassificationNotesCount:= 0;
ClientImagesCount:= 0;
RowCount:= 0;
CellCount:= 0;
if rve.DataSource = fMain.dsTable0 then begin
ClientImagesCount:= fMain.ImageEnMView2.MultiSelectedImagesCount;
if fClassificationNotes.ShowModal <> mrOK then Exit;
for i:= 0 to fClassificationNotes.clClassifications.Items.Count-1 do begin
if fClassificationNotes.clClassifications.Items[i].Checked = True then begin
Inc(ClassificationNotesCount);
end;
end;
ModCount:= ClientImagesCount mod 2;
RowCount:= ClientImagesCount div 2;
if ModCount > 0 then Inc(RowCount);
CellCount:= 2;
end;
//
CRLF:= #10+#13;
PrintIt:= psd.Execute;
if PrintIt then begin
//
ClientName:= '';
case fMain.Table0.FieldByName('Gender').AsInteger of
1: ClientName:= 'Mr ';
2: ClientName:= 'Mrs ';
3: ClientName:= 'Ms ';
4: ClientName:= 'Miss ';
end;
ClientName:= ClientName+fMain.Table0.FieldByName('FirstName').AsString+' '+fMain.Table0.FieldByName('LastName').AsString;
////////////////////////////////////////////////////////////////////////////
//rvs2.ResetTextStyles; // Add Defaults
rvs2.TextStyles.Clear;
rvs2.TextStyles.AddFont('Times New Roman', 14, clBlack, clWhite, [fsBold]);
rvs2.TextStyles.AddFont('Times New Roman', 12, clBlack, clWhite, []);
//rvs2.ResetParaStyles; // Add Defaults
rvs2.ParaStyles.Clear;
rvs2.ParaStyles.Add;
rvs2.ParaStyles[0].Alignment:= rvaCenter;
rvs2.ParaStyles.Add;
rvs2.ParaStyles[1].Alignment:= rvaLeft;
//
rve2.Style:= rvs2;
////////////////////////////////////////////////////////////////////////////
rve2.Clear;
rve2.AddNL('My Business Name', 0, 0);
rve2.AddNL('My Business Address', 0, 0);
rve2.AddNL('', 0, 0);
rve2.AddNL('CLIENT NOTES', 1, 0);
rve2.AddNL(ClientName, 1, 0);
rve2.AddNL('', 0, 1);
rve2.FormatTail;
////////////////////////////////////////////////////////////////////////////
// Append Original RVF to rve2
RVCopy(rve, rve2);
rve2.FormatTail;
////////////////////////////////////////////////////////////////////////////
// Add Images to rve2 MyImageTable
if RowCount > 0 then begin
rve2.AddNL('', 0, 1);
rve2.FormatTail;
//////////////////////////////////////////////////////////////////////////
table:= TRVTableItemInfo.CreateEx(RowCount, CellCount, rve2.RVData);
table.BorderStyle:= rvtbRaisedColor;
table.CellBorderStyle:= rvtbLoweredColor;
table.BorderWidth:= 1;
table.CellBorderWidth:= 1;
table.CellPadding:= 5;
table.CellVSpacing:= 1;
table.CellHSpacing:= 1;
table.BorderVSpacing:= 1;
table.BorderHSpacing:= 1;
rve2.AddItem('MyImageTable', table);
rve2.FormatTail;
// Init
fMain.Table1.IndexName:= ''; // ID
r:= 0;
c:= -1;
//////////////////////////////////////////////////////////////////////////
// Locate MyImageTable
for i:= 0 to rve2.ItemCount -1 do begin
if (rve2.GetItemStyle(i) = rvsTable) and (rve2.GetItemText(i) = 'MyImageTable') then begin
// Fetch Table
table:= TRVTableItemInfo(rve2.GetItem(i));
//
for j:= 0 to fMain.ImageEnMView2.MultiSelectedImagesCount-1 do begin
k:= fMain.ImageEnMView2.MultiSelectedImages[j];
l:= fMain.ImageEnMView2.ImageID[k];
if fMain.Table1.FindKey([l]) = True then begin
CaptionInfo:= fMain.Table1.FieldByName('Caption').AsString;
CaptionInfo:= Trim(CaptionInfo)+' '+DateToStr(fMain.Table1.FieldByName('CreatedOn').AsDateTime);
CaptionInfo:= Trim(CaptionInfo);
//
bm:= TBitmap.Create; // Do Not Free, gets destroyed by rve after use ???
jpeg:= TJPEGImage.Create;
bsF:= TEDBBlobStream.Create(TBlobField(fmain.Table1.FieldByName('JpgFrame')), bmRead);
bsF.Seek(0, soFromBeginning);
bsF.Position:= 0;
jpeg.LoadFromStream(bsF);
bm.Width:= jpeg.Width;
bm.Height:= jpeg.Height;
bm.Canvas.Draw(0, 0, jpeg);
jpeg.Free;
bsF.Free;
//
if c < 1 then begin
Inc(c);
end else begin
Inc(r);
c:= 0;
end;
// Place Cell In Edit Mode (zero based)
table.EditCell(r, c);
// Move caret to the beginning of this cell
RVData:= TCustomRVFormattedData(table.Cells[r, c].GetRVData);
RVData.SetSelectionBounds(0, RVData.GetOffsBeforeItem(0), 0, RVData.GetOffsBeforeItem(0));
// Insert Image
if bm <> nil then begin
w:= rve2.TopLevelEditor.Width - (rve2.TopLevelEditor.LeftMargin + rve2.TopLevelEditor.RightMargin);
try
if rve2.TopLevelEditor.InsertPicture('', bm, rvvaAbsMiddle) then begin
rve2.TopLevelEditor.SetCurrentItemExtraIntProperty(rvepImageHeight, 240, True);
rve2.TopLevelEditor.SetCurrentItemExtraIntProperty(rvepImageWidth, 320, True);
// Save Current Text, Para Info
CurTextStyleNo:= rve2.CurTextStyleNo;
CurParStyleNo:= rve2.CurParaStyleNo;
// Times New Roman, 12pt, style []
rve2.CurTextStyleNo:= 1;
// center
rve2.CurParaStyleNo:= 0;
rve2.TopLevelEditor.InsertText(CRLF+CaptionInfo, True);
// Restore Text, Para Info
rve2.CurTextStyleNo:= CurTextStyleNo;
rve2.CurParaStyleNo:= CurParStyleNo;
end;
finally
end;
end;
//
end; // FindKey
end; // for j
end; // MyImageTable
end; // for i
fMain.Table1.IndexName:= 'ClientIDCreatedOn';
end; // RowCount
////////////////////////////////////////////////////////////////////////////
// Add RVF streams to rve2 MyNotesTable
if ClassificationNotesCount > 0 then begin
rve3.Style:= rvs2;
RowCount:= ClassificationNotesCount;
CellCount:= 1;
rve2.AddNL('', 0, 1);
rve2.FormatTail;
//////////////////////////////////////////////////////////////////////////
table2:= TRVTableItemInfo.CreateEx(RowCount, CellCount, rve2.RVData);
table2.BorderStyle:= rvtbRaisedColor;
table2.CellBorderStyle:= rvtbLoweredColor;
table2.BorderWidth:= 1;
table2.CellBorderWidth:= 1;
table2.CellPadding:= 5;
table2.CellVSpacing:= 1;
table2.CellHSpacing:= 1;
table2.BorderVSpacing:= 1;
table2.BorderHSpacing:= 1;
rve2.AddItem('MyNotesTable', table2);
rve2.FormatTail;
// Init
Filtered:= fMain.Table2.Filtered;
fMain.Table2.Close;
fMain.Table2.Filtered:= False;
fMain.Table2.IndexName:= ''; // ID
fMain.Table2.Open;
r:= -1;
c:= 0;
//////////////////////////////////////////////////////////////////////////
// Locate MyImageTable
for i:= 0 to rve2.ItemCount -1 do begin
if (rve2.GetItemStyle(i) = rvsTable) and (rve2.GetItemText(i) = 'MyNotesTable') then begin
// Fetch Table
table2:= TRVTableItemInfo(rve2.GetItem(i));
//
for j:= 0 to fClassificationNotes.clClassifications.Items.Count-1 do begin
if fClassificationNotes.clClassifications.Items[j].Checked = True then begin
ID:= fClassificationNotes.clClassifications.Items[j].Tag;
if fMain.Table2.FindKey([ID]) = True then begin
// Fetch
bsF:= TEDBBlobStream.Create(TBlobField(fmain.Table2.FieldByName('RichEditNotes')), bmRead);
bsF.Seek(0, soFromBeginning);
bsF.Position:= 0;
// Copy TEDBBlobStream to rve3
rve3.Clear;
rve3.TopLevelEditor.InsertRVFFromStreamEd(bsF);
rve3.InValidate;
// Save rve3 RVF to MemoryStream
ms:= TMemoryStream.Create;
rve3.SaveRVFToStream(ms, False);
// Copy TEDBBlobStream to StringStream
mss:= TStringStream.Create('', TEncoding.Unicode); // TEncoding.Unicode TEncoding.UTF8
bsF.Seek(0, soFromBeginning);
bsF.Position:= 0;
mss.CopyFrom(bsF, bsF.Size);
bsF.Seek(0, soFromBeginning);
bsF.Position:= 0;
// Set Row, Cell
Inc(r);
c:= 0;
// Place Cell In Edit Mode (zero based)
table2.EditCell(r, c);
// Move caret to the beginning of this cell
RVData:= TCustomRVFormattedData(table2.Cells[r, c].GetRVData);
RVData.SetSelectionBounds(0, RVData.GetOffsBeforeItem(0), 0, RVData.GetOffsBeforeItem(0));
// Insert RVF MemoryStream FAILS
rve2.TopLevelEditor.InsertRVFFromStreamEd(ms);
ms.Free;
// Insert RVF MemoryStringStream FAILS
//rve2.TopLevelEditor.InsertRVFFromStreamEd(mss);
mss.Free;
// Insert RVF TEDBBlobStream FAILS
//rve2.TopLevelEditor.InsertRVFFromStreamEd(bsF);
bsF.Free;
end; // FindKey
end; // Tag
end; // for j
end; // MyNotesTable
end; // for i
fMain.Table2.Close;
fMain.Table2.Filtered:= Filtered;
fMain.Table2.IndexName:= 'TypeID';
fMain.Table2.Open;
end; // ClassificationNotesCount
////////////////////////////////////////////////////////////////////////////
rve2.Invalidate; //???
////////////////////////////////////////////////////////////////////////////
RVPrint1.AssignSource(rve2);
//
RVPrint1.LeftMarginMM:= 10;
RVPrint1.RightMarginMM:= 10;
RVPrint1.TopMarginMM:= 10;
RVPrint1.BottomMarginMM:= 10;
RVPrint1.FormatPages(rvdoALL);
//
if RVPrint1.PagesCount > 0 then begin
//RVPrint1.Print('LBAnalysis', 1, False);
fPrintPreview.rvpp.RVPrint:= RVPrint1;
fPrintPreview.Button1Click(nil); // Show First Page
fPrintPreview.ShowModal;
end; // PagesCount
rve2.Clear;
//
end; // PrintIt
end;