Creating & Printing Graphics

M

Mark Davison

Hi,

I hope someone can help, this has been driving me mad! I am trying to
generate a graphic on the fly. This is then shown in the browser in a "print
preview" type window. The user can click a "Print" button and all the
graphics are printed. The problem I have is that the text looks distorted.
If you try the example below you will see the problem. This example creates
a graphic, writes some text to it and then saves it to your disk as a full
size image. It is the size it is so that each image becomes a full page when
printed from within IE.

Can anyone help get the text looking ok? Essentially, I need the text to be
printed out prefectly.

Regards,

Mark
Imports System.Drawing
Imports System.Drawing.Printing
Imports System.drawing.Imaging
Imports System.IO

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
DrawPage(1)
End Sub

Private Sub DrawPage(ByVal PageNum As Integer)

Dim intW As Integer
Dim intH As Integer

intW = CInt(648)
intH = CInt(978)

Dim objBitMap As New Bitmap(intW, intH)
objBitMap.SetResolution(600, 600)

Dim objGraphics As Graphics
objGraphics = Graphics.FromImage(objBitMap)

objGraphics.PageUnit = GraphicsUnit.Pixel
objGraphics.TextRenderingHint =
Text.TextRenderingHint.SingleBitPerPixelGridFit
objGraphics.SmoothingMode = Drawing2D.SmoothingMode.Default
objGraphics.CompositingQuality = Drawing2D.CompositingQuality.Default

'Set the background color to white
objGraphics.Clear(Color.White)

Dim Pen As New Pen(Color.Black, 1)
Dim mFont As New Font("Arial", 14, FontStyle.Regular, GraphicsUnit.Pixel)

objGraphics.DrawRectangle(Pen, 1, 1, (intW) - 2, (intH) - 2)

objGraphics.DrawString("Page " & PageNum & " : Line 1", mFont,
Brushes.Black, 5, 5)


Dim fp As New
FileStream("c:\MDPageImages\ACF24E8D5F884E1E8AD359254D95057A\Page" & PageNum
& ".png", FileMode.OpenOrCreate)
objBitMap.Save(fp, ImageFormat.Png)
fp.Close()

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top