Click here to Skip to main content
15,885,693 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi folks

I have a problem which has me totally stumped.
I'm collecting information from a form and a database and then creating a printed report using the print preview.

VB
Friend WithEvents dlgPrintPreview As System.Windows.Forms.PrintPreviewDialog
.
.
.

dlgPrintPreview = New System.Windows.Forms.PrintPreviewDialog
Dim print_document As New PrintDocument
AddHandler print_document.PrintPage, AddressOf PrintSheet
dlgPrintPreview.Document = print_document

dlgPrintPreview.WindowState = FormWindowState.Maximized
dlgPrintPreview.ShowDialog()


This work fine - at least I see what I am expecting on screen and I can print but the print quality is terrible.
A little debug in PrintSheet routine shows that the whole page is 627 pixels wide and 969 high - despite setting the printer resolution to 600x600.

Can someone please tell me what I've missed or how to print at the actual printer resolution?


Thanks in advance
Posted
Comments
Sergey Alexandrovich Kryukov 18-May-12 11:50am    
How about just thinking a bit? What do you think the word "resolution" might mean? What is supposed to "resolve" what?
--SA

1 solution

The printer resolution has nothing to do with the page size or a size of any area in pixels. The resolution you quote means 600 dots per pixel, dpi:
http://en.wikipedia.org/wiki/Dots_per_inch[^].

—SA
 
Share this answer
 
Comments
Member 4004713 18-May-12 12:51pm    
The printer resolution does effect the number of points I can plot across or along the page. At the moment I get around 100dpi which is one sixth the capability of the printer. I may be being naive but I expect the page to be over 4000 pixels across.
So how do I get a PrintDocument that will print on an A4 page at 600dpi?
Dave Kreskowiak 18-May-12 13:25pm    
It looks like pixelated garbage because the printer resolution is so much higher than the screen resolution. If you printed the screen image at the printers native resolution, the screen image would be the size of a postage stamp on the printer.

You don't have much choice here. The screen image only has so much information. If you scale it up to the printers resolution, you also scale up the limiations of the image.

For example, a single pixel on the monitor may be 1mm x 1mm in size. If you print that same pixel on printer, it might be 0.01mm x 0.01mm is size.

Now, to print the screen pixel on the printer and maintain the same scale, the single on the monitor has to be scaled up 100 times, so on the printer that pixel becomes a block with the width being 100 printer pixels wide x 100 printer pixel tall.

Because of that, any screen image you printer is going to be pixelated.
Sergey Alexandrovich Kryukov 28-May-12 16:53pm    
Wrong approach. You should use all the resolution the printer offers. Using more or less makes no sense at all.
--SA
Member 4004713 18-May-12 13:49pm    
I'm obviously not explaining myself. In the Printsheet sub I build each page using e.MarginBounds.Width (where e in a System.Drawing.Printing.PrintPageEventArgs passed in by the printpreview I think). My problem is that this is ALWAYS giving the page (width in inches less the 1 inch margin at each side time 100) aroud 625.
This is fine for the preview but when I'm building the document to go to the printer I would expect the width to be calculated using the printers resolution of 600dpi (ie width around 4000).
It makes no difference if I use System.Windows.Forms.PrintDialog or System.Windows.Forms.PrintPreviewDialog I appear to be only able to print at 100dpi.

What I need is an "idiots guide" on how I force the resolution of the System.Windows.Forms.PrintPreviewDialog to be that of the printer when a print is requested.

If this isn't possible is there any way other way to print at the printer resolution! I've already reworked my output so it's now an image when I call the printpreview rather than building the page image in my PrintSheet routine.
ledtech3 18-May-12 21:26pm    
Have you read my article yet ?
This May or May not Explain a few thing.

http://www.codeproject.com/Articles/344099/Windows-form-screenshot-and-print-preview-in-VB-NE

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900