Click here to Skip to main content
15,033,303 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I'm trying to expand an inhouse printing-component that we use as reference in our projects to handle printing.
One of the projects I'm working on needs to determine the type of output format (ticket, nametag, A4,...) based on the default printer's type (A4 officejet, ticketprinter, A5 printer,...) in order to properly arrange the layout etc. The idea being that you send a command to this program and that it'll generate the appropriate print-job in the right format.

I'm mainly having issues with determining if a printer is a ticket-printer. Tickets tend to have a variable length, so I was sort of looking for PaperSetting-properties that I could query in order to find out if we're using a ticket printer, but to no avail so far. Not sure if there'd be another way to find out what type of printer we're using.

Over the last couple of days, I haven't been able to find any way to determine what type of default format the printer prints in.
Any help would be appreciated, though I'm starting to think there's no easy way to just ask any printer what type of printer they have.

Thanks in advance for any help!


What I have tried:

I've tried playing around with some properties.
The PaperKind property returns "custom", but as we have a few other industrial printers with other formats that also return this... it's not very useful.
Creating a named custom paper style that we'd have to set up on all ticket printers isn't really an option, as we're talking about hundreds of printers.
I've used the PaperSize to sort of try and guess what type of paper we're using, but I'm not sure that's reliable considering we have tags that are sort of the same width as tickets too. It does kind of do the job I suppose, but as I said I don't really find it a "clean" way to determine it.
Updated 26-Nov-18 2:48am

1 solution

Not sure there is anything which will do it automatically - a ticket printer is just a specific format printer after all - but there is the PrinterSettings.PaperSizes Property (System.Drawing.Printing) | Microsoft Docs[^] which returns a collection of supported paper sizes. Presumably, the ticket printer will support specific sizes rather than A4, A3, etc.
PrinterSettings ps = new PrinterSettings();         // Gets default printer
foreach (PaperSize paperSize in ps.PaperSizes)
    Console.WriteLine("{0}: ({1}, {2})", paperSize.PaperName, paperSize.Width, paperSize.Height);
Gives me these for my Epson BX305:
EPSON4782F5 (Epson Stylus Office BX305)
A4 210 x 297 mm: (827, 1169)
10 x 15 cm (4 x 6 in): (400, 600)
13 x 18 cm (5 x 7 in): (500, 700)
A6 105 x 148 mm: (413, 583)
A5 148 x 210 mm: (583, 827)
B5 182 x 257 mm: (717, 1012)
9 x 13 cm (3.5 x 5 in): (350, 500)
13 x 20 cm (5 x 8 in): (500, 800)
20 x 25 cm (8 x 10 in): (800, 1000)
16:9 wide size (102 x 181 mm): (400, 711)
100 x 148 mm: (394, 583)
Envelope #10 4 1/8 x 9 1/2 in: (413, 950)
Envelope DL  110 x 220 mm: (433, 866)
Envelope C6  114 x 162 mm: (449, 638)
Letter 8 1/2 x 11 in: (850, 1100)
Legal 8 1/2 x 14 in: (850, 1400)
A3 297 x 420 mm: (1169, 1654)
A3+ 329 x 483 mm: (1295, 1902)
A2 420 x 594 mm: (1654, 2339)
B4 257 x 364 mm: (1012, 1433)
B3 364 x 515 mm: (1433, 2028)
User Defined: (827, 1169)
DavidMorf 26-Nov-18 9:13am
Thanks for the reply.
I was afraid that'd be the only way to figure it out.

This is what I get from the ticketprinter:
TEC B-SV4USER : (410, 292)
2 x 4 : (210, 400)
4 x 4 : (410, 400)
4 x 6 : (410, 600)
Form-A : (409, 839)
Form-F : (409, 689)

We have 3 or 4 different type of ticket printers and I don't have them all defined on my machine alas. As some are from a different brand, I hope their PaperSizes are somewhat similarly defined.
OriginalGriff 26-Nov-18 9:22am
So go by the area: multiply the W*H and you'll get a smaller number than a printer that supports even A5!
If all the areas are below a (stored in config file) minimum, it's probably a ticket printer. Ask the user if that's the one, and store the ID in your config file for next time.
DavidMorf 26-Nov-18 9:48am
Hey OriginalGriff,

That's true, but only if the default PaperSize of a ticket printer is always set to its minimum. Not aware of any standards that define that a ticketprinter's default-size should always be it's minimum size atleast, but it could be there is indeed.
My example above would give 410*292=119.720 , but if another ticket printer works with its maximum size as default that could be something like 410*1400=574.000 ... which in turn is a bigger area than A5 i think.

Anyways, I think I'll just have to evaluate the sizes I can read using different margins and "known" papersizes to define the size and kind of guess which type of output format I'm going to have accordingly... and hope the next ticket printers we buy come up with some weird sizes :)

Thanks for the input!
OriginalGriff 26-Nov-18 10:04am
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900