Ich habe ein Programm welches mir einen Bestellbon erstellt und dann auf einem Kassenbondrucker ausdruckt.
Das klappt aktuell auch alles soweit wie es soll. Der Text des Bon wird in einem TMemo zusammengestellt und dann wird der Inhalt des Memo ausgedruckt. Nun möchte ich aber am Anfang des Bons ein Logo (liegt als PNG mit 5000x2541 px vor) einfügen und dann erst den Text.
Habe mit der Suche auch ein paar Themen gefunden, (z.B. https://www.delphipraxis.net/172435-png ... ken-2.html ) aber trotzdem will das ganze noch nicht so wie ich will.
Das PNG wird zur Kontrolle in ein TImage geladen. Dann das TImage einem TPortableNetworkGraphic zugewiesen. Und dann soll das gedruckt werden.
Das Logo erscheint im TImage wie geplant, aber es wird einfach nichts gedruckt.
Ist mein PNG einfach zu groß und es wird nicht skaliert? Oder stehe ich einfach auf einem Knoten?
Bitte bringt etwas Licht in meine Dunkelheit.
Code: Alles auswählen
procedure TForm1.panelPrintMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: integer); // Drucken
const
LEFTMARGIN = 0;
var
i, j, YPos, LineHeight, VerticalMargin: integer;
zeile, error: string;
b: TPortableNetworkGraphic;
begin
if config.printed then exit;
if config.main_dish = 0 then exit;
changePanel(panelPrint);
Printer.Copies := 2;
error := 'Kein Fehler';
try
Form1.Image1.Picture.LoadFromFile(ExtractFilePath(ParamStr(0)) + 'logo_ffw.png');
except
on E: EInOutError do
error := 'File handling error occurred. Details: ' + E.ClassName + '/' + E.Message;
end;
//Form1.Image1.Transparent:= false;
try
b := TPortableNetworkGraphic.Create;
// b.Transparent:= false;
b.Canvas.Brush.Color := clBlue;
b.Canvas.Rectangle(0, 0, round(Image1.Picture.Graphic.Width / 33),
round(Image1.Picture.Graphic.Height / 33));
b.Assign(Image1.Picture.Graphic);
except
error := 'Fehler beim Bilderzeugen';
end;
with Printer do
try
BeginDoc;
Printer.Canvas.Draw(10, 5, b);
Canvas.Font.Name := 'Courier New'; // Ab hier ist alles wie es sein soll
Canvas.Font.Size := 10;
Canvas.Font.Bold := True;
Canvas.Font.Color := clBlack;
LineHeight := Round(1.1 * Abs(Canvas.TextHeight('I')));
VerticalMargin := 2 * LineHeight;
// There we go
YPos := VerticalMargin + round(Image1.Picture.Graphic.Height / 33);
j := Memo_Output.Lines.Count - 1;
for i := 0 to j do
begin
zeile := Memo_Output.Lines[i];
if pos('###', zeile) <> 0 then
begin
canvas.Font.Size := 13;
Canvas.TextOut(LEFTMARGIN, YPos, zeile);
YPos := YPos + LineHeight;
canvas.Font.Size := 10;
continue;
end;
if i = Memo_Output.Lines.Count - 1 then
canvas.Font.Size := 25;
zeile := dupestring(' ', 3) + trim(zeile);
Canvas.TextOut(LEFTMARGIN, YPos, zeile);
YPos := YPos + LineHeight;
end;
Canvas.Font.Size := 10;
YPos := YPos + VerticalMargin;
zeile := IntToStr(config.bonCount) + dupestring(' ', 7) + DateTimeToStr(Now);
Canvas.TextOut(LEFTMARGIN, YPos, zeile);
YPos := YPos + VerticalMargin;
Canvas.TextOut(LEFTMARGIN, YPOS, ' ');
YPos := YPos + VerticalMargin;
Canvas.TextOut(LEFTMARGIN, YPOS, IntToStr(round(Image1.Picture.Graphic.Width / 33)) +
'.......' + IntToStr(round(Image1.Picture.Graphic.Height / 33)));
YPos := YPos + VerticalMargin;
Canvas.TextOut(LEFTMARGIN, YPOS, error);
finally
EndDoc;
DBStoreDish();
DBStoreIngredients();
DBWriteBon();
config.printed := True;
config.cash[1] := 0;
config.additionalDish.Clear;
config.main_dish := 0;
resetall();
config.additionalDish.Clear;
PageControl1.ActivePageIndex := 0;
config.bonCount := config.bonCount + 1;
LblCounter.Caption := 'Count ' + IntToStr(config.bonCount);
fillMemo(Memo_Output);
config.printed := False;
end;
end;