Hi Hiro,
I discussed the case with the developer. As per him, the problem is due to the printer driver. We’ve tried several printers, both local and networked, Sharp printer and a couple of HP LaserJet printers. The HP LaserJet printers, local and network, all behave correctly, but the Sharp printer does not. One the Sharp printer, if any VSPrinter operation is done before DrawPicture of an EMF, the EMF does not appear. For example, if the loop adding text is done first, then NEITHER of the emf images appear in the output. This is related to how the printer driver handles nested emf - each page of VSPrinter output is an emf, so emf images are nested within the page.
Without rewriting VSPrinter (which cannot be done as it is legacy) the only workaround we could find is to use bitmap images instead of emf images. Of course, the emf images scale better, which is probably why you are using them, however, it is possible to create the bitmaps at runtime from the original emf images. Consider the modified Form_Load and new EmfToBitmap function provided below:
Private Sub Form_Load()
Dim i As Integer
Dim pic1 As stdpicture
Dim pic2 As stdpicture
Dim Width As Single
Dim Height As Single
Dim AsBmpOnly As Boolean
Set pic1 = LoadPicture(App.Path & "\imagetest.emf")
AsBmpOnly = True
If AsBmpOnly Then
Width = ScaleX(pic1.Width, vbHimetric, vbTwips)
Height = ScaleY(pic1.Height, vbHimetric, vbTwips)
' Always use the original EMF image and not an image already
' converted to a bitmap.
Set pic2 = EmfToBitmap(pic1, Width * 2, Height * 2)
Set pic1 = EmfToBitmap(pic1, Width, Height)
End If
VSPrinter1.StartDoc
For i = 1000 To 1500 Step 500
VSPrinter1.CurrentX = 1000
VSPrinter1.CurrentY = i
VSPrinter1.FontSize = 20
VSPrinter1.Text = CStr(i) + " Abcdefg1234567890#!"
Next
Call VSPrinter1.DrawPicture(pic1, 500, 5000)
If AsBmpOnly Then
' BMP images can scale, but not as well. Use default BMP size
Call VSPrinter1.DrawPicture(pic2, 500, 8000)
Else
' Emf images can scale directly using VSPrinter
Call VSPrinter1.DrawPicture(pic2, 500, 8000, "200%", "200%", 11)
End If
VSPrinter1.EndDoc
End Sub
Public Function EmfToBitmap(emf As stdpicture, Width As Single, Height As Single) As stdpicture
Dim picbox As PictureBox
Dim pic As stdpicture
Dim tmpSingle As Single
Dim tmpFile As String
tmpFile = Environ("TEMP") + "\tmpBitmapFile.bmp"
Set picbox = Me.Controls.Add("vb.PictureBox", "tmpPicBox")
With picbox
Set .Picture = Nothing
tmpSingle = .Width - .ScaleWidth
.Visible = False
.BackColor = vbWhite
.AutoRedraw = True
.AutoSize = True
.Width = Width + tmpSingle
.Height = Height + tmpSingle
.ScaleLeft = 0
.ScaleTop = 0
.ScaleWidth = Width
.ScaleHeight = Height
.PaintPicture emf, 0, 0, Width, Height
.Picture = .Image
SavePicture .Picture, tmpFile
.Picture = Nothing
Set pic = LoadPicture(tmpFile)
Kill tmpFile
End With
Me.Controls.Remove picbox
Set EmfToBitmap = pic
End Function
I have also attached a modified project for your reference. This version converts the emf image to bitmaps at runtime. This is not as good as using the emf images due to scaling differences between screen and printer, but it provides a workaround for no images at all.
Thanks,
Pragati
vsview_test_modified.zip