Home Component Writing
New Blog Post: Email: Multi-Service

TppRafMerge and duplex

Long times ago, we modified the TrbRAFMerge for printing with duplex.
If the frist report has 3 pages we add a empty page and then we add the next report.
Can you add this functionality to your TppRafMerge?

TrbRAFMerge = class
private
FAbsolutePageCount: Integer;
FDeleteSourceFiles: Boolean;
FDestinationFile: string;
FmgmUsePrinterSetup: Boolean;
FmgmPrinterSetup: TppPrinterSetup;

FRenumberPages: Boolean;
FSourceFiles: TStringList;
FTag: Integer;
function GetSourceFilesCount: Integer;
public
constructor Create; virtual;
destructor Destroy; override;
procedure DeleteDestinationFile;
procedure Execute;
procedure mgmAddSourceFile(AFileName: TFileName; ADuplexWithNextFile: Boolean);
procedure mgmInit;
property AbsolutePageCount: Integer read FAbsolutePageCount;
property DeleteSourceFiles: Boolean read FDeleteSourceFiles write FDeleteSourceFiles;
property DestinationFile: string read FDestinationFile write FDestinationFile;
property mgmUsePrinterSetup: Boolean read FmgmUsePrinterSetup write FmgmUsePrinterSetup;
property mgmPrinterSetup: TppPrinterSetup read FmgmPrinterSetup write FmgmPrinterSetup;
property RenumberPages: Boolean read FRenumberPages write FRenumberPages;
property SourceFilesCount: Integer read GetSourceFilesCount;
property Tag: Integer read FTag write FTag;
end;

implementation

uses
ppDevice;

constructor TrbRAFMerge.Create;
begin
inherited Create;
FmgmUsePrinterSetup := False;
FmgmPrinterSetup := TppPrinterSetup.Create(nil);
FRenumberPages := False;
FSourceFiles := TStringList.Create;
FTag := 0;
end;

procedure TrbRAFMerge.DeleteDestinationFile;
var
LsTempFile: string;
begin
if FileExists(FDestinationFile) then begin
DeleteFile(FDestinationFile);
end;
LsTempFile := ChangeFileExt(FDestinationFile, '.tmp');
if FileExists(LsTempFile) then begin
DeleteFile(LsTempFile);
end;
end;

destructor TrbRAFMerge.Destroy;
begin
FreeAndNil(FmgmPrinterSetup);
FSourceFiles.Free;
FSourceFiles := nil;
inherited Destroy;
end;

procedure TrbRAFMerge.Execute;
var
LoArchiveReader: TppArchiveReader;
LoArchiveDevice: TppArchiveDevice;
LbDoublexNewPage: Boolean;
LiIndex: Integer;
LoPage: TppPage;
begin
// create arcive reader
LoArchiveReader := TppArchiveReader.Create(nil);

// create archive device
LoArchiveDevice := TppArchiveDevice.Create(nil);
LoArchiveDevice.Publisher := LoArchiveReader.Publisher;
LoArchiveDevice.FileName := FDestinationFile;
try
// for each source file, generate pages
for LiIndex := 0 to FSourceFiles.Count - 1 do begin
LbDoublexNewPage := (Integer(FSourceFiles.Objects[LiIndex]) = 1);
if LbDoublexNewPage and (LiIndex <> 0) and (Odd(FAbsolutePageCount)) then begin
LoPage := TppPage.Create(nil);
LoPage.Final := True;
LoPage.AbsolutePageNo := 1;
//LoPage.PageDef.Assign();
LoArchiveDevice.ReceivePage(LoPage);
FreeAndNil(LoPage);
end;
LoArchiveReader.ArchiveFileName := FSourceFiles[LiIndex];
LoArchiveDevice.StartPrintJob := (LiIndex = 0);
LoArchiveDevice.EndPrintJob := (LiIndex = FSourceFiles.Count-1);
LoArchiveReader.PrintToDevices;
FAbsolutePageCount := FAbsolutePageCount + LoArchiveReader.ArchivePageCount;
end;
finally
// free archive device
LoArchiveDevice.Free;
// free archive reader
LoArchiveReader.Free;
end;

// delete source files, if needed
if FDeleteSourceFiles then begin
for LiIndex := 0 to FSourceFiles.Count - 1 do begin
DeleteFile(FSourceFiles[LiIndex]);
end;
end;
end;

function TrbRAFMerge.GetSourceFilesCount: Integer;
begin
Result := FSourceFiles.Count;
end;

procedure TrbRAFMerge.mgmAddSourceFile(AFileName: TFileName;
ADuplexWithNextFile: Boolean);
begin
if ADuplexWithNextFile then begin
FSourceFiles.AddObject(AFileName, TObject(1))
end else begin
FSourceFiles.AddObject(AFileName, TObject(0));
end;
end;

procedure TrbRAFMerge.mgmInit;
begin
FSourceFiles.Clear;
FDeleteSourceFiles := False;
FAbsolutePageCount := 0;
end;

Comments

  • Hi Thomas,

    Try this...

    Create a BlankPage.raf - an archive containing blank page.

    Add the BlankPage.raf to TppRAFMerge.SourceFiles wherever needed.

    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
Sign In or Register to comment.