Question

I am working on an application in which I need to print labels ranging from 1"x3" up to 8"x10". The text and images that will be printed on the labels is defined in a xml file that contains all needed info including its location on the label as defined by the top-left xy coordinate. I do not want to preview the print job, just send it to the printer on command. My question is, what is the preferred method for doing this?

I have toyed around with 2 different methods.

Method one: Reading the xml and locating the items on a form, creating an image of the form and then printing it. This works but it just seems a bit hokey?? I have to display the form for a second to create the image and I really do not want to do that.

Method two: I have looked into using MigraDoc to create a label document and then sending it to the printer. This approach will create the form and send it to the printer without being displayed however, I do not see how I can locate the items within the document based on xy coordinates?? Maybe I have missed something here but everything seems to be section and paragraph driven.

What would be the best/easiest way to accomplish this?

Was it helpful?

Solution 2

Re Method two:
With MigraDoc you can use TextFrames to position items using XY co-ordinates. Textframes can overlap and if you use this method it will be your responsibility to make sure that everything fits into the designated area.

The better way of using MigraDoc would be using tables and/or paragraphs with exact heigths or spacings. This however cannot be used easily with your approach of using XML files with co-ordinates as spacings would have to be relative to the previous item.

You can use PDFsharp to create a PDF file that draws everything at the right places. But printing could then be a problem - you can call Adobe Reader passing command-line arguments to print automatically, but you cannot set sophisticated printer options. If you create only few print jobs and manual intervention is not a problem, this could be an option (and the PDF files allow a visual check of the document before you print it).

OTHER TIPS

You could use the functionality in the System.Drawing namespace to draw your text and images directly to a bitmap, so you don't have to display a form.

Dim bm As Bitmap = New Bitmap(200, 200)
Dim gr As Graphics = Graphics.FromImage(bm)

Dim img As Image = Image.FromFile("image.jpg")
gr.DrawImage(img, x, y)

Dim fn As Font = New Font("Comic Sans MS",72)
Dim solidBlack As SolidBrush = New SolidBrush(Color.Black)
gr.DrawString("My Picture", fn, solidBlack, x, y)

Then do what you want with the bitmap bm, save, print, whatever.

Some more examples, http://www.websupergoo.com/helppdf9net/source/4-examples/20-systemdrawing.htm

Edit: I don't remeber exactly how I overcame the text quality problem when I last used this, but I did have this stuff set in my code.

gr.SmoothingMode = Drawing.Drawing2D.SmoothingMode.HighQuality
gr.TextRenderingHint = Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit
gr.CompositingQuality = Drawing.Drawing2D.CompositingQuality.HighQuality
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top