Dynamically generating an image then printing

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I am trying to create a "print preview" window for a web site using asp.net.
I have got a long way down the road to the solution but the problem I have
now is that the text and lines on the printed page are fuzzy.

The following code sample will illustrate the point:

Start of page load code sample
'=========================
Dim objBitmap As New Bitmap(648, 978)
objBitmap.SetResolution(600, 600)

'Declare Graphics objects for painting graphics onto bitmap.
Dim objGraphics As Graphics = Graphics.FromImage(objBitmap)

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

objGraphics.PageUnit = GraphicsUnit.Millimeter
objGraphics.TextRenderingHint =
Text.TextRenderingHint.AntiAliasGridFit
objGraphics.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
objGraphics.InterpolationMode =
Drawing2D.InterpolationMode.HighQualityBicubic
objGraphics.CompositingQuality =
Drawing2D.CompositingQuality.HighQuality

Dim mFont As New Font("Arial", 0.5, FontStyle.Regular,
GraphicsUnit.Millimeter)

Dim sf As StringFormat = New StringFormat
sf.FormatFlags = StringFormatFlags.LineLimit +
StringFormatFlags.FitBlackBox + StringFormatFlags.NoWrap

objGraphics.DrawString("This is some test text. When you print the
bitmap, the text will be distorted.", mFont, Brushes.Black, 5, 5, sf)

objBitmap.Save("c:\MDPageImages\test.bmp", ImageFormat.Bmp)

objGraphics.Dispose()
objBitmap.Dispose()
'====================================
'End of page load sample

Note I have imported:

Imports System.Threading
Imports System.Globalization
Imports System.Drawing
Imports System.drawing.Imaging
Imports System.IO
Imports System.Text

This code sample will create an image to a folder on your local disk (you
may need to grant everyone permission to the folder to get it to work). If
you open the image, it looks fine. When you print the image the text is not
sharp and clear. The font also looks a bit strange.

Can anyone help? this has been driving me mad!!

Mark
 
Mark said:
Hi,

I am trying to create a "print preview" window for a web site using asp.net.
I have got a long way down the road to the solution but the problem I have
now is that the text and lines on the printed page are fuzzy.

The following code sample will illustrate the point:
Have you tried just sending the information to a memory stream an output it
directly in the browser. For example for a jpeg file you would use the
following:

Response.ClearContent
Response.ContentType = "image/jpeg"
yournewdrawingimage.Save(Response.OutputStream, ImageFormat.Jpeg)
 
Mark said:
Hi,

Whatever I set it to, the results are the same - blurry text!

Ok, so forget about the program for a minute.

At this point, you have a bitmap, and the problem is the fonts look blurry
when printed...but they look sharp crisp and clear when you look at them
through MS-Paint, right ?

And the size of the image that you are printing, is the same size that you
are viewing on screen, right?

When you look at it in MS-Paint, and resize it, do the fonts break up?

Have you thought of resizing your fonts to be the right quality for the size
of image you want to print?
 
Hi,

Thanks for trying to help with this. I am creating the images into a folder
then I am loading them all into a page. It is this page that is getting
printed. As you guessed, when viewing on screen everything looks perfect.

When you say resize the fonts, do you just mean make them bigger i.e. 14pt
instead of 10 or something?

Mark
 
Hi,

That is basically what I am doing. The problem is something abut the image
itself. It displays on-screen fine, but when printed is not clear and crisp.

Mark
 
Back
Top