Duplex printing error

General TRichView support forum. Please post your questions here
Post Reply
alisichkin
Posts: 7
Joined: Fri Jul 20, 2018 8:24 am

Duplex printing error

Post by alisichkin »

Hello!
Thanks for helping to solve the print header/footer problem.
In our extended version of RichView (15.1.2), an error occurred in two-sided printing (duplex) for multiple copies.
The error appears in the module SRVPrint.pas
The TSRVPrint.PrintPages procedure does not use the TDeviceMode.dmDuplex value.
Therefore, when print 2 pages report, with two-sided pages, with 2 copies, with turned off collate parameter, the indexPage variable is not correctly calculated.
indexPage changes 1,1; 2,2
But should be 1,2; 1,2.

Code: Select all

procedure TSRVPrint.PrintPages(firstPgNo, lastPgNo: Integer; Title: String;
  Copies: Integer; Collate: Boolean);
var
  Step, indexPage, indexCopys, indexCopys2, PrintCopies, OldPrintCopies,
    CountPageAtPaper, j, EP: Integer;
  OldOrientation:            TPrinterOrientation;
  StartPrint:                Boolean;
begin
  if Printer.Printers.Count = 0 then
    exit;
  SRVPrtInfo.UpdateCurPrinterData;

  Printer.Title := Title;
  firstPgNo := Max(Min(firstPgNo, FSRichViewEdit.PageCount), 1);
  lastPgNo := Max(Min(lastPgNo, FSRichViewEdit.PageCount), 1);

  OldPrintCopies := Printer.Copies;
  if Collate then
  begin
    Printer.Copies := 1;
    PrintCopies := Copies;
  end
  else
  begin
    Printer.Copies := 1;
    PrintCopies := 1;
  end;

  if PrintMode = srvpTiles then
    CountPageAtPaper := Max((Floor(PageWidthPix) div Floor(TotalFrameWPix)), 1)
      * Max((Floor(PageHeightPix) div Floor(TotalFrameHPix)), 1)
  else
    CountPageAtPaper := 1;

  lastPgNo := Min(SRichViewEdit.LastPageNo, lastPgNo);

  BeginUpdate;
  StartPrint := True;
  OldOrientation := Orientation;
  Printer.Orientation := Orientation;
  Printer.BeginDoc;
  if Assigned(FOnSendingToPrinter) then
    FOnSendingToPrinter(SRichViewEdit, 0, 0, rvpsStarting);
  for indexCopys := 1 to PrintCopies do
  begin
    if (FPrintMode = srvpGrid) then
      Step := PageColCount * PageColCount
    else
      Step := CountPageAtPaper;

    indexPage := Max(SRichViewEdit.FirstPageNo, firstPgNo);
    while (indexPage <= lastPgNo) do
    begin
      if not Collate then
        for indexCopys2 := 1 to Copies do
        begin
          if not StartPrint then
            Printer.NewPage;
          StartPrint := False;
          EP := Min(indexPage + CountPageAtPaper - 1, lastPgNo) - 1;
          EP := (EP div CountPageAtPaper) * CountPageAtPaper +
            (EP mod CountPageAtPaper) + 1;
          for j := indexPage to EP do
            PrintFramesEx(j);
        end
      else
      begin
        if not StartPrint then
          Printer.NewPage;
        StartPrint := False;
        EP := Min(indexPage + CountPageAtPaper - 1, lastPgNo) - 1;
        EP := (EP div CountPageAtPaper) * CountPageAtPaper +
          (EP mod CountPageAtPaper) + 1;
        for j := indexPage to EP do
          PrintFramesEx(j);
      end;
      indexPage := (((indexPage - 1 + Step) div CountPageAtPaper) *
        CountPageAtPaper) + 1;
    end;
  end;
  Printer.EndDoc;
  Printer.Orientation := OldOrientation;
  if Assigned(FOnSendingToPrinter) then
    FOnSendingToPrinter(SRichViewEdit, 0, 0, rvpsFinished);
  EndUpdate;
  Printer.Copies := OldPrintCopies;
end;
Could you help me to fix this procedure?

Alexander.
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Duplex printing error

Post by Sergey Tkachenko »

In newer version of the components, if collate is turned off, and the printer supports copies, TSRVPrint allows printer to handle copies itself.
MitchellBon
Posts: 1
Joined: Tue Nov 06, 2018 9:33 am

Re: Duplex printing error

Post by MitchellBon »

Why does the collate have to be turned off for the TSRVPrint to allow printer to handle copies btw? What am I missing?
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Duplex printing error

Post by Sergey Tkachenko »

There are printers that do not support copies. For these printers, SRVPrint handles copies and collating itself.
There are printers that support copies but do not support collating. For these printers, SRVPrint relies on the printer when printing without collating, and handles copies and collating itself otherwise.
There are printers that support collating. SRVPrint does not have a special support for them and handles them like previous printer.
Do you have a printer that supports collating itself?
Post Reply