Let me start off with this disclaimer: This scenario is completely contrived. The scenario proposed is analogous to an actual problem that I am trying to solve.

Problem: I'm going to cheat on a test that uses Scan-tron style cards. I've stolen the test before it was handed out and written a program that solves every question. After writing 100 KLOC, my hands are too tired to fill out the 500 bubbles on the Scan-tron card before I need to sneak back into the class to hand in the Scan-tron card.

Solution: Add a print function to the program that will print to a Scan-tron style sheet and fill in only the bubbles that correspond to the correct answer.

So hopefully it's blatantly obvious that this is not realistic. The more realistic part of this problem is that, although I'm very comfortable writing code and designing programs, I've reached one of those dark corners that every coder fears - I have a problem and absolutely no idea where to start. The gist of the problem is that I have a fixed, non-standard form that needs to be filled out by my program. I know in advance (or can get in advance) all of the paper sizes and locations on the page that need to be printed. The core problem is that I have no idea where to start. This is where I would really appreciate anyone's help with this problem.
Basically, what I'm looking for is a starting point. The background for the real application is that it is a Linux based, terminal application that must print to Scan-tron style cards (I'll be happy to elaborate on "Scan-tron" for those unfamiliar with the term, just tell me). The target language is C because the algorithms and overall design fit a procedural model perfectly.
If anybody has written/designed a custom printing routine for a Linux application, I would really love to hear where you started and how you broke the problem down. I'm still consulting Dr. Google, but so far all of my research has turned up empty hits about how to configure print servers on Linux - nothing yet on how to invoke the printer in a program. Thanks for any input!

Details:
Target OS: Ubuntu Linux Kernel- 2.6.32-22
Target Printer: HP Officejet 6500A Plus
Target Language: C
Target Page Layout: Scan-tron format (n rows by 5 columns of selections)

*If there is a better forum for this question on DaniWeb, let me know. I guessed CS would be the most involved with software design.

Recommended Answers

All 6 Replies

I know that to print graphical stuff (as opposed to pure text) you are generally better off coding to a library like OpenGL or wxWidgets. That way you only have to worry about a memory device context and not the actual driver-level stuff. The library and operating system will handle the hard work, and all you have to do is make library calls regardless whether you are going to screen or printer.

The bad news is, most of the more popular ones are C++ libraries, so you may have to do some more searching if you specifically want C as your coding language.

Whether you do this in Linux or Windows, the logic is about the same.

The page is a perfect representation of a 2D char array. You need to print out a test sheet to discover:

1) What is the top left char that can be printed by the printer

2) What is the bottom right char that the printer can print

top left is obviously, 2d[0][0], and you work down the rows (and over the columns), from that point.

Now you can print out your data into a plain text file, and by all means, print up a temporary row and number counter, to help you know how far to move your output around.

Now pick out the char from your ASCII (or other) character set, that most closely matches the size of the marks you want to make, on your printed page. An ASCII chart downloaded from the net would be quite valuable for this (your own systems character set values may differ in some char's, but most will be the same). You can even print up your own character set values.

And with that, you can start designing your output. Be sure to display the page, with a close representation of it in a console window first, otherwise you'll waste a TON of paper and time.

I've done this in DOS and Windows, with similar requirements, but not in Linux. Since you're using just console text however, it should be very much the same thing.

Once you set up the paper guides to line up the text printing spaces, with the spaces you need printed on your paper, it's essential that you NOT make any further movement of the guides, or adjustments of the paper feed itself, naturally. It's a good idea to mark the exact place for the left guide, "just in case".

Scan-tron sheets were made for text pages, so no graphics should be needed to do what you want.

P.S.
Anywhere that you don't want to print, your program needs to place a space (char ' ', or 32), into that row and column, and you'll need to also add the end of line char's, as needed: '\n'.

The page is a perfect representation of a 2D char array. You need to print out a test sheet to discover:

Adak, thank you for the response. But I think my example convoluted my problem a little. The crux of it is that I don't know where to start attacking the problem of how to even print to a line printer from my application code. I've never had to write to a printer before, so I'm not sure where to even start.

Epiphany: While I was writing this response, I vaguely remembered an example from K&R C that asked the reader to write a line printer program. I think I'll spend some time with that. I would still appreciate any input or clarification, thank you again!

What I'd recommend is DON'T write it up to the line printer, directly.

Instead, print it to the screen, once you know the top left and bottom right of the printable area of your printer.
Enumerate your rows and columns:

XX1234567890123456789012345678901234567890  << row just before the first printable row
X1.......................................X << First printable row
X2.......................................X
X3.......................................X
X4.......................................X << row numbers
X5.......................................X
X6.......................................X
X7.......................................X
X8.......................................X
X9.......................................X
10.......................................X
11.......................................X
12.......................................X
13.......................................X
14.......................................X
15.......................................X << Last printable row
XX12345678901234567890123456789012345678901234567890 << Column enumeration numbers

X or a digit = a position that your printer can't print in.

Naturally, you want to set your printer up for the widest and tallest print area, that you can.

When it looks right, then print it. Probably by writing it to a text file,and then printing it with Linux, for right now. How many of these sheets do you have to print up?

Once you have the pages printed to file, you can easily print them up with Linux, using Ubuntu. I'm not sure how you print directly in Linux, but I'm sure the Ubuntu Forum (which is VERY active and good), can tell us. :)

commented: Very well written and to the point. Extremely helpful! +2

Ah, I see. Thank you so much for the help! I guess I got so caught up in the details that I forgot that there are higher levels that can handle the task of outputting to the printer for me. I'll have to mess around with the page area like you suggested and you're right, from then I can let the OS handle the dirty work of writing to the printer.
As for the number of these, right now I can only say there will be n, where n may be a large number. But, with how little data each file will contain I can easily write them to a known location on disk and write a helper script to dump them to the printer. I'm familiar enough with Linux shells to handle the print request.
Thanks again!

You're welcome.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.