Page 1 of 1

Duplex printing error

Posted: Mon Oct 29, 2018 9:09 am
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.

Re: Duplex printing error

Posted: Mon Oct 29, 2018 12:17 pm
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.

Re: Duplex printing error

Posted: Mon Nov 12, 2018 12:02 pm
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?

Re: Duplex printing error

Posted: Mon Nov 12, 2018 7:46 pm
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?