今天在做窗口模式的合同时,用的是A4纸,横向打印的,直接打印会变成纵向,用预览中的打印又正常了,在直接打印的代码中,我用了这二种代码的各种组合,如:Doc.PageSetting.Landscape = True及doc.AutoRotate = False,但均告失败,打出来的死活是给向的。
_PrintForm.Page.LeftMargin = CDbl(e.Form.Controls("NumericComboBox1").text) '设置左边距
_PrintForm.Page.RightMargin = CDbl(e.Form.Controls("NumericComboBox2").text) '设置右边距
_PrintForm.Page.TopMargin = CDbl(e.Form.Controls("NumericComboBox3").text) '设置上边距
_PrintForm.Page.BottomMargin = CDbl(e.Form.Controls("NumericComboBox4").text) '设置下边距
_PrintForm.Page.Landscape = True '横向打印
Dim doc As PrintDoc = _PrintForm.GernatePrintDoc()
For Each c As object In Doc.Body.Children '自动合并合计行的单元格
If c.Gettype.Name Like "*Table*" Then
Dim t As prt.RenderTable = c
For i As Integer = 0 To t.Rows.Count - 1
If t.Cells(i, 2).Text = Nothing AndAlso t.Cells(i, 1).Text <> Nothing Then
For n As Integer =1 To t.Cols.Count - 1 '表的目录树占用了最左列导致实际列数从1开始,而不是0
If t.Cells(i,n).Text = Nothing AndAlso t.Cells(i,n+1).Text <> Nothing Then
t.Cells(i, 1).SpanCols = n
Exit For
End If
Next
End If
Next
End If
Next
Dim rx As New prt.RenderTable
rx.Cells(0,0).Text = _CompanyName '调用在全局代码中设置的全局变量
rx.Cells(1,0).Text = _DocumentType '调用打开本窗口时赋值的全局变量
rx.Cols(0).Style.TextAlignHorz = prt.AlignHorzEnum.Center '设置居中
rx.CellStyle.Spacing.Bottom = 0.5 '底端内容缩进0.5毫米
rx.Cells(0,0).Style.FontSize = 16 '设置字体大小
rx.Cells(1,0).Style.FontSize = 14 '设置字体大小
Doc.PageHeader = rx '作为页眉使用
doc.PageSetting.Width = CDbl(e.Form.Controls("NumericComboBox5").text) '纸张宽度为XX毫米
doc.PageSetting.Height = CDbl(e.Form.Controls("NumericComboBox6").text) '纸张高度为XX毫米
doc.AutoRotate = False '禁止自动旋转打印内容
If e.Form.Controls("ComboBox_打印机").value = "" Then
Else
Doc.PrinterName =e.Form.Controls("ComboBox_打印机").value
End If
'doc.Print
doc.Preview() '预览