以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  打印机指定问题  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=185172)

--  作者:可乐七号
--  发布时间:2023/2/8 16:13:00
--  打印机指定问题
设置打印机: Doc.PrinterName = printname
设置了打印,还是从默认打印机上打出信息。这是什么原因?


--  作者:有点蓝
--  发布时间:2023/2/8 16:16:00
--  
我测试没有问题。是不是预览后,在预览窗口打印的?
--  作者:可乐七号
--  发布时间:2023/2/8 16:25:00
--  
不是,是直接打印的。
--  作者:有点蓝
--  发布时间:2023/2/8 16:33:00
--  
完整代码发上来看看
--  作者:可乐七号
--  发布时间:2023/2/8 17:18:00
--  
函数调用代码:
Dim comprintset As String =  Forms("商品条码打印").Controls("comprintset").text \' 打印机
Dim num As Integer = e.Form.Controls("num").text \'打印份数
Vars("CODEid") = e.Form.Controls("id").text
Dim dr As DataRow
dr = DataTables("CommodityBarcode").Find("ID = " & Vars("CODEid"))
Functions.Execute("PrintCodeing",dr,num,comprintset )



以下是 PrintCodeing 函数代码
Dim dr As DataRow = Args(0)\'打印内容
Dim t As String = "打印" \'操作类型 打印 / 预览
Dim num As Integer = args(1)\'打印份数
Dim printname As String  = args(2) \'打印名

Dim doc As New PrintDoc \'定义一个报表
doc.Stacking = prt.StackingRulesEnum.InlineLeftToRight \'设置排列方式

doc.PageSetting.Width = 50 \'纸张宽度为60毫米
doc.PageSetting.Height = 30 \'纸张高度为40毫米
Doc.PageSetting.LeftMargin = 0 \'设置左边距
Doc.PageSetting.RightMargin = 0 \'设置右边距
Doc.PageSetting.TopMargin = 0 \'设置上边距
Doc.PageSetting.BottomMargin = 0 \'设置下边距
doc.AutoRotate = False \'禁止自动旋转打印内容
Dim fntx As New Font("微软雅黑",12,FontStyle.Bold )

Dim ra As New prt.RenderArea
Dim rt As prt.RenderText

ra.Width = 50 \'宽度60毫米
ra.Height = 30 \'高度40毫米
ra.Style.Spacing.All = 1
\'ra.Style.Borders.All = New prt.Linedef(0.3, Color.Red) \'设置边框
ra.SplitHorzBehavior = prt.SplitBehaviorEnum.Never \'禁止水平分割
ra.SplitVertBehavior = prt.SplitBehaviorEnum.Never \'禁止垂直分割
Doc.Body.ChildRen.Add(ra) \'将容器加入到报表中


Dim fnt As New Font("微软雅黑",14)
Dim fnt1 As New Font("微软雅黑",12)

\'rt = New prt.RenderText
\'rt.Text = "款号:"
\'rt.Width = "Auto" \'自动设置宽度
\'rt.X = 2
\'rt.Y = 1
\'rt.Style.Font = fnt
\'ra.Children.Add(rt) \'添加到容器中
\'品牌内容
\'rt = New prt.RenderText
\'rt.Text = dr("itemNo")
\'rt.Width = "Auto" \'自动设置宽度
\'rt.X = "Prev.Right"
\'rt.Y = "Prev.top"
\'rt.Style.Font = fnt
\'ra.Children.Add(rt)

rt = New prt.RenderText
rt.Text = "规格:"
rt.Width = "Auto" \'自动设置宽度
rt.X = 2
rt.Y = 1 \'"Prev.Bottom"
rt.Style.Font = fnt
ra.Children.Add(rt) \'添加到容器中

rt = New prt.RenderText
rt.Text = dr("colour").TRIM() & dr("size").TRIM()
rt.Width = "Auto" \'自动设置宽度
rt.X = "Prev.right"
rt.Y = "Prev.top"
rt.Style.Font = fnt
ra.Children.Add(rt)

Dim Bar As New BarCodeBuilder
Dim rg As New prt.RenderGraphics
rg = new prt.RenderGraphics
Bar.Symbology = Barpro.Symbology.Code128
bar.Code = dr("barcode")
Bar.BarRatio = 0.2648
Bar.QuietZoneWidth = 0
Bar.DisplayCode = False
Bar.AddCheckSum = False
Bar.DisplayStartStopChar = False
Bar.BarHeight = 16
rg.width = 50
rg.height = 16
bar.DrawOnCanvas(rg.Graphics,0,0,1)
rg.X = 0
rg.y =  "Prev.Bottom"
rg.Style.ImageAlign.AlignHorz=prt.ImageAlignHorzEnum.Center
ra.Children.Add(rg)

rt = New prt.RenderText
rt.Text = dr("barcode")
rt.Width = 50
rt.X = 1
rt.Y = "Prev.Bottom"
rt.Style.TextAlignHorz = prt.AlignHorzEnum.Center \'水平居中
rt.Style.Font = fnt1 
ra.Children.Add(rt)


Dim ps As new System.Drawing.Printing.PrinterSettings
If t = "打印"
    Doc.PrinterName = printname
    ps.Copies = num    \'设置份数
    doc.Print(ps)
Else
    Doc.PrinterName = printname
    Doc.Preview
End If

--  作者:有点蓝
--  发布时间:2023/2/8 17:25:00
--  
用了PrinterSettings,会覆盖专业报表的设置的。试试

Dim ps As new System.Drawing.Printing.PrinterSettings
ps.PrinterName = printname
If t = "打印"
    ps.Copies = num    \'设置份数
    doc.Print(ps)


--  作者:可乐七号
--  发布时间:2023/2/10 9:18:00
--  
可以了,图片点击可在新窗口打开查看