Forum > Lazarus Extra Components

Printer4Lazarus, Lazarus 3.4

(1/2) > >>

irawan:
i got error on this

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TfMain.Button1Click(Sender: TObject);const  LEFTMARGIN = 100;  HEADLINE = 'I Printed My Very First Text On ';var  YPos, LineHeight, VerticalMargin: Integer;  SuccessString: String;begin  with Printer do  try    BeginDoc;    Canvas.Font.Name := 'Courier New';    Canvas.Font.Size := 10;    Canvas.Font.Color := clBlack;    LineHeight := Round(1.2 * Abs(Canvas.TextHeight('I')));    VerticalMargin := 4 * LineHeight;    // There we go    YPos := VerticalMargin;    SuccessString := HEADLINE + DateTimeToStr(Now);    Canvas.TextOut(LEFTMARGIN, YPos, SuccessString);  finally    EndDoc;  end;end;                   any clue?

bytebites:
Which error?

wp:
Your code looks correct, and works fine on my system (Win 11, PDF printer). What might be helpful, is to add unit OSPrinters to the uses clause (in addition to unit Printers) in order to get correct access to OS-specific printing routines.

Please note that specifying the LEFTMARGIN as 100 pixels is not a very good idea because the printer resolution usually is much different from the screen resolution, and thus the 100 px may be too small. Better to think in device-independent units, e.g. millimeters, and provide a conversion function to pixels:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---const  INCH = 25.4;   // 1 inch is 25.4 mm function mmToPx(mm: Double; APixelsPerInch: Integer): Integer;begin  Result := round(mm / INCH * APixelsPerInch);end; const  LEFT_MARGIN_MM = 10;  // Left margin should be 10 mmvar  LeftMargin: Integer;   // Left margin in pixels, to be passed to the printerbegin  with Printer do  begin    ...    LeftMargin := mmToPx(LEFT_MARGIN_MM, XDPI);    ... ...

irawan:

--- Quote from: bytebites on June 25, 2024, 09:35:14 am ---Which error?

--- End quote ---
Project PortMap raised exception class 'External: ACCESS VIOLATION' with message:
Access violation reading from address $00000000000058.

in file 'printers.pas' at line 739

irawan:

--- Quote from: wp on June 26, 2024, 05:52:28 pm ---Your code looks correct, and works fine on my system (Win 11, PDF printer). What might be helpful, is to add unit OSPrinters to the uses clause (in addition to unit Printers) in order to get correct access to OS-specific printing routines.

--- End quote ---
i got another problem when adding osprinter.
Cannot find osprinters used by sMain. Check if package Printer4Lazarus is in the dependency of the project inspector.
trying to find printer4lazarus in online package manager and got none.
cause of this i compiled by removing osprinters.
project compiled okay but gave error when executed.

and then following this https://wiki.freepascal.org/Using_the_printer#Adding_the_Printer4Lazarus_package_to_your_project_requirements
and now everything work as it should.

Navigation

[0] Message Index

[#] Next page

Go to full version