[fpc-pascal] Text Only printing on Windows.

Alexander Grotewohl alex at dcclost.com
Wed Feb 9 19:51:03 CET 2022


Is this for a Dymo style printer?

The easiest way you might do this nowadays is using the Windows API.. I'm sorry for the sort of pseudo-code but I'm stuck with examples my previous work owns so I have to paraphrase a bit:

GetDefaultPrinter (so you don't have to enumerate and then find the right one, set the label printer to default)
CreateDC (we want something to draw our text to)

StartDoc(dc, @di); (our initial 'print')
StartPage(dc); (this in our case would be each label)

Some sample stuff to create a font you can use:

fillchar(lf, sizeof(lf), 0);
lf.lfWeight:=FW_NORMAL;
lf.lfHeight:=-MulDiv(12, GetDeviceCaps(dc, LOGPIXELSY), 72);
newfont:=CreateFontIndirect(@lf);
oldfont:=GetCurrentObject(dc, OBJ_FONT);
SelectObject(dc, newfont);

A little helper function.. not amazing but gets text mostly where you'd want it at column/row
procedure printxy(dc: HDC; x, y: byte; s: string);
begin
TextOut(dc, x*50, y*110, @s[1], length(s));
end;

EndPage(dc); (in our case end this label)
EndDoc(dc); (end the print job)

SelectObject(dc, oldfont); (cleanup)
DeleteObject(newfont);
DeleteDC(dc);

It'll take a bit of effort to read up on those functions and get them working right, but afterward you should have printing sorted for yourself as long as the windows api is supported.

--
Alexander Grotewohl
https://dcclost.com
________________________________
From: fpc-pascal <fpc-pascal-bounces at lists.freepascal.org> on behalf of James Richters via fpc-pascal <fpc-pascal at lists.freepascal.org>
Sent: Wednesday, February 9, 2022 1:17 PM
To: 'FPC-Pascal users discussions' <fpc-pascal at lists.freepascal.org>
Cc: James Richters <james.richters at productionautomation.net>
Subject: [fpc-pascal] Text Only printing on Windows.


Way back in the old Turbo Pascal days, it was super simple to send text to a printer…   I had written a program that printed text on labels in the

order the labels were needed.. the whole thing took me less than an hour to write and labels were spewing out of the printer.

I haven’t had a need to print anything since then, but now, I want to do the exact same thing.. print sequential text only labels from my FPC console program…

I can display the labels to the console window, or write them to a file… but I’m just staring at my code at a total loss on how to send these simple labels to my

USB label printer connected to a windows 10 64bit PC.  Is there no way to just send text to printers anymore?

I don’t want to go through the windows print dialog for every label, and I don’t want to create one huge document of all the labels and print them all at once..

I want my FPC console application to spit out the next in sequence single label each time I push the space bar, without dealing with any the print dialog or doing anything else.

This used to be so easy to do, but now it seems either very complicated or impossible.  Does anyone know of a way to just send pain text

to a USB printer with FPC ,preferably without Lazarus?



James
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20220209/5c5d26c1/attachment.htm>


More information about the fpc-pascal mailing list