打印机是Microsoft Office Document Image Writer
Picture1.CurrentX = 1400 '这里不能用厘米
Picture1.CurrentY = 1000 '这里不能用厘米
Picture1.FontSize = 26
Picture1.Print " TEST REPORT"
Printer.Orientation = 2 会报错打印机默认1
Printer.PaintPicture Picture1.Image, 0, 0
Printer.EndDoc
下面代码,我测试过了,可以打印...
Option Explicit
Private Sub Form_Load()
Me.Show
Me.WindowState = 2
Dim i As Integer
i = Me.ScaleMode
Me.ScaleMode = 7 '厘米作为单位
Picture1.ScaleMode = 7 '厘米作为单位 注意注意注意
Picture1.Move 0, 0, 29.7, 21 'A4纸的尺寸
Me.ScaleMode = i
End Sub
Private Sub Command1_Click()
With Picture1
.FontSize = 26
.CurrentX = .ScaleX(1400, 1, 7) '将Twip数值转化为cm数值 注意注意注意
.CurrentY = .ScaleY(1000, 1, 7) '将Twip数值转化为cm数值 注意注意注意
Picture1.Print "TEST REPORT"
End With
End Sub
Private Sub Command2_Click()
With Printer
.PaperSize = vbPRPSA4 '设置打印机纸张类型
.Orientation = vbPRORLandscape '设置打印方向
.PaintPicture Picture1.Image, 0, 0
.EndDoc
End With
End Sub
还是有问题呀(如图),能不能直接调用修改打印机的属性参数?谢谢!
您如果方便的话给我做个,一个form加picturebox仿A4纸,定义它们的坐标范围(以后我可以在这个范围内作图写字),可以横向纵向转换,打印输出后和显示的一致(打印机是Microsoft Office Document Image Writer
) +200分
'设置Pic1的A4纸规格不同方向
'Pic1控件在Pic0控件上,如果是放在Form1里,将Pic0改为Me就行了...
Private Sub SetPaper(Flag As Integer)
With Pic1
'在改变纸张时设置ScaleMode
Pic0.ScaleMode = 7
.Width = IIf(Flag = 0, 21, 29.7) '纵向规格
.Height = IIf(Flag = 0, 29.7, 21) '横向规格
Pic0.ScaleMode = 1
End With
End Sub
'打印
'Prt为选定的打印机
'img为PictureBox的Image属性
'Orientation为打印方向,vbPRORPortrait和vbPRORLandscape
Private Function PrintPic(Prt As Printer, img As IPictureDisp, Optional Orientation = vbPRORPortrait) As Long
On Error Resume Next
Set Printer = Prt
On Error GoTo PErr
With Printer
.PaperSize = vbPRPSA4
.Orientation = Orientation
.PaintPicture img, 0, 0
.EndDoc
End With
PrintPic = 1
Exit Function
PErr:
'PrintPic = 0
'我在使用“Microsoft Office Document Image Writer”打印时跟你一样,
'设置Orientation= vbPRORLandscape时也出现了错误
'我测试过,如果先将“Microsoft Office Document Image Writer”的打印首选项改为横向,
'那么设置Orientation为vbPRORPortrait、或vbPRORLandscape都没问题。
'至于如何用代码去控制,我还没找到方法的
End Function