0

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?

4

2 回答 2

1

您可以使用System.Drawing命名空间中的功能将文本和图像直接绘制到位图,因此您不必显示表单。

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)

然后用位图做你想做的事bm,保存,打印等等。

更多示例,http://www.websupergoo.com/helppdf9net/source/4-examples/20-systemdrawing.htm

编辑:我不记得我上次使用它时是如何克服文本质量问题的,但我确实在我的代码中设置了这些东西。

gr.SmoothingMode = Drawing.Drawing2D.SmoothingMode.HighQuality
gr.TextRenderingHint = Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit
gr.CompositingQuality = Drawing.Drawing2D.CompositingQuality.HighQuality
于 2013-05-13T18:06:46.090 回答
0

方法二:
使用 MigraDoc,您可以使用 TextFrames 使用 XY 坐标定位项目。文本框可以重叠,如果您使用此方法,您有责任确保所有内容都适合指定区域。

使用 MigraDoc 的更好方法是使用具有精确高度或间距的表格和/或段落。但是,这不能轻松地与您使用带坐标的 XML 文件的方法一起使用,因为间距必须与前一个项目相关。

您可以使用 PDFsharp 创建一个在正确位置绘制所有内容的 PDF 文件。但是打印可能会成为一个问题 - 您可以调用 Adob​​e Reader 传递命令行参数来自动打印,但您不能设置复杂的打印机选项。如果您只创建少量打印作业并且手动干预不成问题,这可能是一种选择(PDF 文件允许在打印之前对文档进行目视检查)。

于 2013-05-14T08:44:48.443 回答