A4 Sayfaya Tam Olarak Yazdırmak - Uğur ŞİRİN - 09/06/2017
Merhaba arkadaşlar aşağıdaki örnek uygulama ile mevcut jpeg dosyasını yazıcıya gönderiyorum. Lakin yazıcıda tam sayfa çıkmıyor. Resmi kırpıyor ve bir parçasını çıkartıyor.
Elimdeki JPEG dosyası A4 sayfaya yazılmış bir doc dosyasının resmidir.
Elimdeki JPEG dosyasını A4 sayfaya tam olarak sığdırması için kodun neresini değiştirmem gerekiyor ?
Option Explicit
' Print the PictureBox's picture with upper left
' corner at (1440, 1440). Then draw a box around
' the picture.
Private Sub cmdPrint_Click()
Dim wid As Single
Dim hgt As Single
' Set the PictureBox's ScaleMode to pixels to
' make things interesting.
picCanvas.ScaleMode = vbPixels
' Print the picture.
Printer.PaintPicture picCanvas.Picture, _
1440, 1440
' Get the picture's dimensions in the printer's
' scale mode.
wid = ScaleX(picCanvas.ScaleWidth, picCanvas.ScaleMode, Printer.ScaleMode)
hgt = ScaleY(picCanvas.ScaleHeight, picCanvas.ScaleMode, Printer.ScaleMode)
' Draw the box.
Printer.Line (1440, 1440)-Step(wid, hgt), , B
' Finish printing.
Printer.EndDoc
MsgBox "Done"
End Sub
Private Sub Form_Load()
Const SAMPLE_TEXT As String = "Geodesic Sphere"
' Draw on the picture.
picCanvas.Font.Name = "Times New Roman"
picCanvas.Font.Size = 24
picCanvas.Font.Bold = True
picCanvas.ForeColor = vbBlack
' Center the text horizontally at the top
' of the picture.
picCanvas.CurrentX = (picCanvas.ScaleWidth - picCanvas.TextWidth(SAMPLE_TEXT)) / 2
picCanvas.CurrentY = 0
picCanvas.AutoRedraw = True
picCanvas.Print SAMPLE_TEXT
' Make the text a permanent part of the image.
' This is important if you later need to copy
' the picture to another control or the Printer.
picCanvas.Picture = picCanvas.Image
End Sub
Cvp: A4 Sayfaya Tam Olarak Yazdırmak - Uğur ŞİRİN - 09/06/2017
Çözümü buldum. Başka arkadaşlara lazım olur diye burada paylaşıyorum. Buyrun.
Option Explicit
' Print the PictureBox's picture as large as
' possible and centered. Then draw a box around it.
Private Sub cmdPrint_Click()
Dim picture_aspect As Single
Dim printer_aspect As Single
Dim wid As Single
Dim hgt As Single
Dim X As Single
Dim Y As Single
' Set the PictureBox's ScaleMode to pixels to
' make things interesting.
picCanvas.ScaleMode = vbPixels
' Compare the picture's and Printer's
' aspect ratios.
picture_aspect = picCanvas.ScaleHeight / picCanvas.ScaleWidth
printer_aspect = Printer.ScaleHeight / Printer.ScaleWidth
If picture_aspect > printer_aspect Then
' The picture is too tall and thin.
' Print it as tall as possible.
hgt = Printer.ScaleHeight
wid = hgt / picture_aspect
Else
' The picture is too short and wide.
' Print it as wide as possible.
wid = Printer.ScaleWidth
hgt = wid * picture_aspect
End If
' See where we need to place the picture
' to center it.
X = Printer.ScaleLeft + (Printer.ScaleWidth - wid) / 2
Y = Printer.ScaleTop + (Printer.ScaleHeight - hgt) / 2
' Print the picture.
Printer.PaintPicture picCanvas.Picture, X, Y, wid, hgt
' Draw the box.
Printer.Line (X, Y)-Step(wid, hgt), , B
' Finish printing.
Printer.EndDoc
MsgBox "Done"
End Sub
Private Sub Form_Load()
Const SAMPLE_TEXT As String = "Geodesic Sphere"
' Draw on the picture.
picCanvas.Font.Name = "Times New Roman"
picCanvas.Font.Size = 24
picCanvas.Font.Bold = True
picCanvas.ForeColor = vbBlack
' Center the text horizontally at the top
' of the picture.
picCanvas.CurrentX = (picCanvas.ScaleWidth - picCanvas.TextWidth(SAMPLE_TEXT)) / 2
picCanvas.CurrentY = 0
picCanvas.AutoRedraw = True
picCanvas.Print SAMPLE_TEXT
' Make the text a permanent part of the image.
' This is important if you later need to copy
' the picture to another control or the Printer.
picCanvas.Picture = picCanvas.Image
End Sub
|