Click here to Skip to main content
16,016,501 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I created some software to print barcoded labels on Avery 5160 column templates. They print centered and aligned properly on the HP4015, HP4100, and HP4250 laser jet printers in my office. I deployed the code and am seeing that in different locations across the company the same model printer may not print the labels properly. For example - in one location the HP4100 prints the label perfectly but the HP4250 in that location chops off the right hand column by 1/8 inch. In another site the HP4250 is fine but the HP4100 prints the labels with the verticle positioning just a tad off causing an overlap with the label above it. I am not sure how to fix this issue. Has anyone else had this kind of issue before?
Posted
Comments
[no name] 23-Sep-12 20:50pm    
Do each of the computers that you are printing from have exactly the same printer settings?
Sergey Alexandrovich Kryukov 23-Sep-12 21:00pm    
Those settings are not really important; all one need is some installed printer(s) with sufficient page size and resolution. I basically answered -- please see.
--SA
Sergey Alexandrovich Kryukov 23-Sep-12 20:58pm    
It looks like you did it wrong. :-) Why do you think anyone needs to have this issue to give you a right advice. Issues should not be "had", they can be avoided...
--SA

1 solution

The right approach is to let the platform dealing with all the different printers; your task is to provide rendering which is not dependent from the printer. For example, you cannot deny that if you output some data in a vector format like XPS (http://en.wikipedia.org/wiki/Open_XML_Paper_Specification[^]), the OS with the installed printer will print it correctly despite the printer detail.

Of course, you can always print to XPS, because there is a printer which prints to a file of this type, but more generally, you need to render your graphics on the fly. You can do it using the class System.Drawing.Printing.PrintDocument:
http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.aspx[^].

Look at the code sample to see how this is done. It's important to note that the main thing is such code is adding the event handler to the even PrintPage. Event arguments passed as a parameters of the handler method provides you with the information on the page metrics; and you also are given the instance of the class System.Drawing.Graphics to be used for rendering:
http://msdn.microsoft.com/en-us/library/system.drawing.graphics.aspx[^].

In you rendering method, you have to scale your graphics according to the size and orientation of the page, that's it. For any printer with sufficient page size and resolution, you can arrange your Avery-formatted data with sufficient accuracy.

Good luck,
—SA
 
Share this answer
 

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