Skip to main content
GameDev.net gamedev.net
🔒 Locked

[.net] 'No printer installed' print preview problem

Started by orbano Jul 2, 2007 at 3:12 PM 18 replies 13.8k views
Original Post
orbano
orbano
Hi! I have a printpreviewcontrol attached to a print document. If the computer has any printers installed, it displays correctly. As soon as i run it on a computer with no printers i get a 'no printer isntalled' exception (don't know the exact exception message as my framework displays it in Hungarian). Any suggestions? Thanks
"Knowledge is no more expensive than ignorance, and at least as satisfying." -Barrin
Mykre
Mykre

That is normal, the print preview needs to read information from the printer so that it can display it correctly in a Print preview.

You might be able to use the office document viewer to simulate a printer, but in essance you are going to need to have a printer attached so the print preview can work.
Michalson
Michalson
Print preview requires some information from the printer driver (it's much worse in some WYSIWYG print applications like Access, where entire parts of the program don't work because they can't start without a printer). At best you can install a file printer (like the Microsoft Document Imaging printer) to work around the problem, otherwise you're stuck making your own approximation of a print preview if you want to preview the results for a printer that doesn't exist.
orbano
orbano
is there any way to provide this data without a printer? i guess it can be told the preview that i want a preview for a 600dpi A4 size paper somehow... it looks silly for me.
lets say it cant be done: how can i check for the existence of a printer? (using office doc. writer is not good. i cant tell every user to buy and install ms office just for this)
"Knowledge is no more expensive than ignorance, and at least as satisfying." -Barrin
orbano
orbano
Quote:
Original post by Michalson
... otherwise you're stuck making your own approximation of a print preview if you want to preview the results for a printer that doesn't exist.


how? :)
"Knowledge is no more expensive than ignorance, and at least as satisfying." -Barrin
orbano
orbano
anybody?
"Knowledge is no more expensive than ignorance, and at least as satisfying." -Barrin
knowyourrole
knowyourrole
You could try starting the print spooler service, if it's not already running, regardless if you have a printer installed or not. This used to work for me for things like MS word before I installed my printer.

Turn it on by right clicking My Computer and going to Manage->Services and Applications->Services, then right clicking on "Print Spooler" and clicking Start. You could also just type [net start "Print Spooler"] without the brackets into the run menu to do the same.
benryves
benryves
Anyone with .NET 3.0 or higher installed will have a printer driver - it installs an XPS document file printer driver. Vista comes with .NET 3.0.

Probably not the greatest solution, but if you already have instructions for installing .NET 2.0 you might as well ask them to install .NET 3.0. [smile]
[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]
orbano
orbano
Quote:
Original post by knowyourrole
You could try starting the print spooler service, if it's not already running, regardless if you have a printer installed or not. This used to work for me for things like MS word before I installed my printer.

Turn it on by right clicking My Computer and going to Manage->Services and Applications->Services, then right clicking on "Print Spooler" and clicking Start. You could also just type [net start "Print Spooler"] without the brackets into the run menu to do the same.


As i create programmes not only for myself but for about a few hundred people without any knowledge of their operating system, this way is not preferred :)
"Knowledge is no more expensive than ignorance, and at least as satisfying." -Barrin
orbano
orbano
Quote:
Original post by benryves
Anyone with .NET 3.0 or higher installed will have a printer driver - it installs an XPS document file printer driver. Vista comes with .NET 3.0.

Probably not the greatest solution, but if you already have instructions for installing .NET 2.0 you might as well ask them to install .NET 3.0. [smile]


I think hat will do as a "patch". But i still wonder if there is any way for detecting the existence of those damned printers :)
"Knowledge is no more expensive than ignorance, and at least as satisfying." -Barrin
TheTroll
TheTroll
Actually there should be a way to show a print preview with no printer drivers. Can you show me the code you are using for calling the print preview so I can modify it to work without print drivers?

theTroll
orbano
orbano
Quote:
Original post by TheTroll
Actually there should be a way to show a print preview with no printer drivers. Can you show me the code you are using for calling the print preview so I can modify it to work without print drivers?

theTroll


PrintPreviewDialog win = new PrintPreviewDialog();
win.Document = printDocument1;
win.ShowDialog(this);

Lets say.

Thank you in advance!
"Knowledge is no more expensive than ignorance, and at least as satisfying." -Barrin
TheTroll
TheTroll
Nope, you can't do it. I tried every trick I could think of except for adding a new printer and then deleting it when you are done.

The best thing to do in this case, is the either catch the exception or to test if System.Drawing.Printing.PrinterSettings.InstalledPrinters.Count > 0 ( 0 means no printers are installed)

Sorry I couldn't get you a better answer.
theTroll
mutex
mutex
Quote:
Original post by benryves
Anyone with .NET 3.0 or higher installed will have a printer driver - it installs an XPS document file printer driver. Vista comes with .NET 3.0.

Probably not the greatest solution, but if you already have instructions for installing .NET 2.0 you might as well ask them to install .NET 3.0. [smile]
Someone can still delete the XPS printer, and I believe it's possible for computer manufacturers to remove the XPS printer from machines they sell.

Nik02
Nik02
Why would you want a print preview if you don't have an actual printer (or equivalent document writer) installed?

Real-world printers have a surprisingly wide variety of attributes, such as paper sizes, margin sizes, resolution and color output settings. It is next to impossible to create a "generic A4" preview without knowing the capabilities that the printer drivers report. At the very least, margin and resolution variability dictate that there is no such thing as a generic print size.
Niko Suni
orbano
orbano
Quote:
Original post by Nik02
Why would you want a print preview if you don't have an actual printer (or equivalent document writer) installed?

Real-world printers have a surprisingly wide variety of attributes, such as paper sizes, margin sizes, resolution and color output settings. It is next to impossible to create a "generic A4" preview without knowing the capabilities that the printer drivers report. At the very least, margin and resolution variability dictate that there is no such thing as a generic print size.


Just to display the content. The content is important, not the specific look. And the most important: stability. At the moment my program craches if there is no printer installed. And the other thing: i can print the document to PDF or XLS or HTML (internally). That does not require a single priner driver to be installed, but i need the preview for a default printer setting i set.
"Knowledge is no more expensive than ignorance, and at least as satisfying." -Barrin
orbano
orbano
Quote:
Original post by ranakor
why not display it in a bitmap instead of a printpreview if you don't care about the printpreviewing part itself?


because in other cases i do care. in a default case, the user has a printer, maybe more. he/she can then check the preview, print it to one of the printers, "print" it to a pdf/xml/html file. all this from ONE SINGLE preview window, with the same functionality for EVERY cases. as i want my program simple, im looking for the workaround to display a printpreview without a damned printer. :)
"Knowledge is no more expensive than ignorance, and at least as satisfying." -Barrin
ranakor
ranakor
yea but if that's not possible you could always have the same button present a printpreview or a bitmap depending on wether there is a printer (or maybe add code to check wethere there is a printer installed at install time & else install a virtual printer like those used to print to pdf?)
orbano
orbano
Quote:
Original post by ranakor
yea but if that's not possible you could always have the same button present a printpreview or a bitmap depending on wether there is a printer (or maybe add code to check wethere there is a printer installed at install time & else install a virtual printer like those used to print to pdf?)


the driver can be removed at any time by anybody. i will have to create a new preview control, that is able to host a printpreview or my preview control if needed. unfortunately thats a lot of work :(
"Knowledge is no more expensive than ignorance, and at least as satisfying." -Barrin

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.