本帖最后由 foxtable 于 2016-3-23 08:05 编辑
我重新描述一下问题。
客户需要打印票据,自定义纸张,宽度大于高度,例如150*80mm,正常打印结果很正常,代码如下:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim doc As New C1.C1Preview.C1PrintDocument
doc.DefaultUnit = C1.C1Preview.UnitTypeEnum.Mm
doc.PageLayout.PageSettings.Width = 150
doc.PageLayout.PageSettings.Height = 80
doc.PageLayout.PageSettings.TopMargin = 10
doc.PageLayout.PageSettings.LeftMargin = 10
doc.PageLayout.PageSettings.RightMargin = 10
doc.PageLayout.PageSettings.BottomMargin = 10
Dim ra As New C1.C1Preview.RenderArea()
ra.Width = "130"
ra.Height = "60"
ra.Style.Borders.All = New C1.C1Preview.LineDef(1, Color.Red)
doc.Body.Children.Add(ra)
Dim pm As New C1.C1Preview.C1PrintManager
pm.PrintOptions.AutoRotate = False '禁止自动旋转
pm.PrintOptions.CenterPage = False
pm.PrintOptions.PageScaling = C1.C1Preview.PageScalingEnum.None
pm.Document = doc
doc.Generate()
Dim ps As System.Drawing.Printing.PrinterSettings = doc.PageLayout.PageSettings.ToPageSettings.PrinterSettings
pm.Print(ps)
End Sub
得到了预期的打印结果:
客户习惯是先预览一下结果,然后再打印,所以我做了一个预览按钮,页面设置和内容都一样,只是最后输出到预览窗口而不是输出到打印机,预览按钮的代码如下:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim doc As New C1.C1Preview.C1PrintDocument
doc.DefaultUnit = C1.C1Preview.UnitTypeEnum.Mm
doc.PageLayout.PageSettings.Width = 150
doc.PageLayout.PageSettings.Height = 80
doc.PageLayout.PageSettings.TopMargin = 10
doc.PageLayout.PageSettings.LeftMargin = 10
doc.PageLayout.PageSettings.RightMargin = 10
doc.PageLayout.PageSettings.BottomMargin = 10
Dim ra As New C1.C1Preview.RenderArea()
ra.Width = "130"
ra.Height = "60"
ra.Style.Borders.All = New C1.C1Preview.LineDef(1, Color.Red)
doc.Body.Children.Add(ra)
Dim dlg As New C1.Win.C1Preview.C1PrintPreviewDialog
dlg.PreviewPane.PageSettings = doc.PageLayout.PageSettings.ToPageSettings
With dlg.PreviewPane.PrintOptions
.AutoRotate = False '静止自动旋转
.CenterPage = False
.PageScaling = C1.C1Preview.PageScalingEnum.None
End With
dlg.Document = doc
dlg.ShowDialog()
End Sub
单击这个按钮,预览窗口显示的结果也正常,符合客户的预期:
看到结果符合预期后,用户单击预览窗口的打印按钮,打印出来的内容旋转了90度:
就是说,目前直接打印和打印预览都能得到正确的结果,只是在预览窗口中单击打印按钮得到的结果是错误的。
所有设置都相同,直接打印正常,预览也也正常,为什么在预览窗口中单击打印按钮得到的结果却和前两者不同,内容会旋转90度?
千言万语一句话: 在使用同样的纸张定义下(150*80),我希望在预览窗口单击打印按钮,也能得到下图的打印结果,四边形是横向的,距离页面的边距也和直接打印相同:
|