Recent

Author Topic: Printing paragraphs  (Read 2614 times)

rick2691

  • Sr. Member
  • ****
  • Posts: 375
Printing paragraphs
« on: September 14, 2016, 02:33:41 pm »
I have been able to print selective pages by my preview routines.

But whether I print by a standard print or by the preview, it does not wrap the paragraphs at the specified right-side margin.

Left, Top and bottom are correct, providing that there is no paragraph. It prints to the edge of the paper, and wraps by some measure that is off the paper.

It does the same whether it is to real paper or a PDF converter.

Code: Pascal  [Select]
  1. // print and format globals
  2. var cpMin, PixH, PixW: longint;
  3.     ViewScale: double;
  4.     dc: THandle;
  5.     fr: TFormatRange;
  6.     ox, oy, w, h: LongInt;
  7.     MorePages: boolean;
  8.     PageMap, PrintMap: widestring;
  9.     PrtCnt, PgCnt, PgSum: integer;
  10.     PgWide, PgHigh, PgLft, PgRht, PgTop, PgBtm: double;
  11.  
  12. procedure TCmdForm.PrintPageMemo(Sender: TObject);
  13. var
  14.   prm: TPrintParams;
  15. begin
  16.   if PageControl1.PageCount>0 then
  17.      begin
  18.      if PrinterSetupDialog1.Execute then  // choose printer,*paper,*orientation
  19.         begin
  20.         if PageSetupDialog1.Execute then  // choose *paper,*orientation,margins
  21.            begin
  22.            if not Assigned(Printer) then  // "catch all" for exit
  23.               begin
  24.               ShowMessage('No printer assigned.');
  25.               Exit;
  26.               end;
  27.            InitPrintParams(prm);
  28.            prm.SelStart:= PageMemo.SelStart;
  29.            prm.SelLength:= PageMemo.SelLength;
  30.            prm.JobTitle:= 'PageMemo Printing';
  31.            PageSetupToMargins(PageSetupDialog1, prm);   // next below
  32.            PageMemo.Print(prm);
  33.            end else ShowMessage('Cancel selected.');
  34.         end else ShowMessage('Cancel selected.');
  35.      end else showmessage('No active document.');
  36. end;
  37.  
  38. procedure TCmdForm.PageSetupToMargins(pg: TPageSetupDialog; var p: TPrintParams);
  39. var
  40.   md : Single; // multiplier to convert to inches
  41. begin
  42.   if pg.Units=unMM
  43.      then md:= 0.254
  44.      else md:= 0.001;
  45.   p.Margins.Left:= pg.Margins.Left*md*72;  // PgLft*md*72;
  46.   p.Margins.Top:= pg.Margins.Top*md*72;  // PgTop*md*72;
  47.   p.Margins.Right:= -pg.Margins.Right*md*72;  // PgRht*md*72;
  48.   p.Margins.Bottom:= pg.Margins.Bottom*md*72;  // PgBtm*md*72;
  49. end;
  50.  
  51. procedure TCmdForm.PageMemoPrintAction(Sender: TObject; APrintAction: TPrintAction;
  52.                                        PrintCanvas: TCanvas; CurrentPage: Integer;
  53.                                        var AbortPrint: Boolean);
  54. begin
  55.   if APrintAction=paPageStart then
  56.      begin
  57.      PrintCanvas.Brush.Color:= clBlue;
  58.      PrintCanvas.Brush.Style:= bsSolid;
  59.      PrintCanvas.Ellipse(100,100,200,200);
  60.      end;
  61. end;
  62.  

Rick
Windows 10, LAZ 1.6.4, FPC 3.0.2, SVN 54278, i386-win32-win32/win64, forms use windows unit

rvk

  • Hero Member
  • *****
  • Posts: 3842
Re: Printing paragraphs
« Reply #1 on: September 14, 2016, 02:49:38 pm »
-pg.Margins.Right ??
Are you sure you need to set the right margin to a negative value there?

(I only have experience printing directory with RichEd20.dll and range etc. but have never set a negative margin)

Or is the value supplied already negative?

And if Right is positive you might need to do PageWidth-Right to set the correct Right-value for printing.
You set the Margins.Right to a positive value for how much space you want at the right-edge of the paper.
« Last Edit: September 14, 2016, 03:08:23 pm by rvk »

rick2691

  • Sr. Member
  • ****
  • Posts: 375
Re: Printing paragraphs
« Reply #2 on: September 14, 2016, 04:16:13 pm »
rvk,

I think you are correct. That makes sense with how it is wrapping (off the page). I had noticed the negative, but I took the code from a source, and I had assumed that a negative was appropriate. Otherwise, I must have hit the negative key carelessly at some point.

I'll let you know how it works.

Rick
Windows 10, LAZ 1.6.4, FPC 3.0.2, SVN 54278, i386-win32-win32/win64, forms use windows unit

rick2691

  • Sr. Member
  • ****
  • Posts: 375
Re: Printing paragraphs
« Reply #3 on: September 14, 2016, 04:25:27 pm »
That was it. I works perfectly now. Thanks a lot.

Rick
Windows 10, LAZ 1.6.4, FPC 3.0.2, SVN 54278, i386-win32-win32/win64, forms use windows unit