Recent

Author Topic: Printing: Paper "" not supported  (Read 3712 times)

Arbee

  • Full Member
  • ***
  • Posts: 223
Printing: Paper "" not supported
« on: June 17, 2011, 05:59:35 pm »
I have a SYNEDIT which I want to print and I created this onclick event for it:

Code: [Select]
procedure TParmFileEditForm.PrintClick(Sender: TObject);
//==============================================================================
//          ********************************************************************
//          * Print the contents of the SynEdit lines                          *
//          * to the default printer                                           *
//          ********************************************************************
//------------------------------------------------------------------------------
const
   LEFTMARGIN = 100;
//------------------------------------------------------------------------------
var
   YPos, LineHeight, VerticalMargin, i, MaxLines, LineCount: Integer;
   MyPrinter : TPrinter;
//------------------------------------------------------------------------------
begin
   MyPrinter := Printer;
   MyPrinter.BeginDoc;

   // Set characteristics for the print
   with MyPrinter.Canvas.Font do begin
      Name := SynTab123Editor.Font.Name;
      Size := 10;
      Color := clBlack;
   end;
   LineHeight := Round(1.2 * Abs(MyPrinter.Canvas.TextHeight('I')));
   VerticalMargin := 4 * LineHeight;
   MaxLines := (MyPrinter.PageHeight - (2 * VerticalMargin)) div LineHeight;
   YPos := VerticalMargin;
   LineCount := 0;
   //---------------------------------------------------------------------------

   // Print all lines
   for i := 0 to SynTab123Editor.Lines.Count - 1 do begin
      // execute a new page if we exceed the max line count
      if LineCount > MaxLines then begin
         MyPrinter.NewPage;
         YPos      := VerticalMargin;
         LineCount := 0;
      end;
      //------------------------------------------------------------------------

      // output the line and advance to a new line
      MyPrinter.Canvas.TextOut(LEFTMARGIN, YPos, SynTab123Editor.Lines.Strings[i]);
      YPos += LineHeight;
      INC(LineCount);
      //------------------------------------------------------------------------

   end;
   //---------------------------------------------------------------------------
   MyPrinter.EndDoc;
//==============================================================================
end;


Put aside the possible fact that there may be other ways to code this .....
I get a message:  'Paper "" not supported' on the code that lurks behind the property MyPrinter.PageHeight.

if I add the line
Code: [Select]
MyPrinter.papersize.papername := 'A4 210x297mm';
then it all works fine, but that of course only works because the current default printer happens to have this paper available.

Trying to be smart I tried a:
Code: [Select]
MyPrinter.papersize.papername := MyPrinter.papersize.defaultpapername;
But that gives the same 'Paper "" not supported' on the property defaultpapername.

Am I overlooking something?

1.0/2.6.0  XP SP3 & OS X 10.6.8

 

TinyPortal © 2005-2018