Printer selected is not valid как исправить
Перейти к содержимому

Printer selected is not valid как исправить

  • автор:

Исправил баг 'printer Selected Is Not Valid' при печати на сетевом принтере

Исключение "Printer selected is not valid" вылетает при попытке печати на сетевом принтере. Возникает не у всех и не всегда. Вот код, который (в моем случае) исправил баг:

<!—fonto:Courier New—><span style="font-family:Courier New"><!—/fonto—>procedure TfrxPrinter.UpdateDeviceCaps;
begin

FDPI := Point(GetDeviceCaps(FDC, LOGPIXELSX), GetDeviceCaps(FDC, LOGPIXELSY));

if (FDPI.X = 0) or (FDPI.Y = 0) then
raise Exception.Create(‘Printer selected is not valid’);

FPaperHeight := Round(GetDeviceCaps(FDC, PHYSICALHEIGHT) / FDPI.Y * 25.4);
FPaperWidth := Round(GetDeviceCaps(FDC, PHYSICALWIDTH) / FDPI.X * 25.4);
FLeftMargin := Round(GetDeviceCaps(FDC, PHYSICALOFFSETX) / FDPI.X * 25.4);
FTopMargin := Round(GetDeviceCaps(FDC, PHYSICALOFFSETY) / FDPI.Y * 25.4);
FRightMargin := FPaperWidth — Round(GetDeviceCaps(FDC, HORZRES) / FDPI.X * 25.4) — FLeftMargin;
FBottomMargin := FPaperHeight — Round(GetDeviceCaps(FDC, VERTRES) / FDPI.Y * 25.4) — FTopMargin;

Printer selected is not valid как исправить

Привет всем жителям Королевства!

Решил обойтись без обычного диалога выбора принтера и его установок.
Задаю значение Printer.PrinterIndex, используя TComboBox. Как только доходит до Printer.BeginDoc, выдается сообщение «Printer selected is not valid». Может быть, нужно задать еще какие-то установки? Не знает ли кто-нибудь, как эта проблема решается?

Вот такой код у меня:

Printer.PrinterIndex := frmGraphPrintSettings.cmbPrinters.ItemIndex;
Printer.Orientation := poLandscape;
Printer.BeginDoc; // Ошибка
chrtMax.PrintPartial(GraphPrintArea1);
Printer.EndDoc;

Отслеживать ответы на этот вопрос по RSS

04-11-2006 13:26 | Сообщение от автора вопроса

Выхода за пределы списка принтеров нет. У меня Printer.Printers.Count = 4, только один настоящий, а другие виртуальные (Acrobat Distiller и ему подобные). Пробовал выбирать настоящий принтер frmGraphPrintSettings.cmbPrinters.ItemIndex = 0, Acrobat Distiller (frmGraphPrintSettings.cmbPrinters.ItemIndex = 3). Настоящий пишет «Printer selected is not valid», а Acrobat Distiller отказывается тоже печатать, советуя выключить в установках опцию «Do not send fonts to Distiller».

04-11-2006 12:38
А чему у Вас равен frmGraphPrintSettings.cmbPrinters.ItemIndex и Printer.Printers.Count .

Страница избранных вопросов Круглого стола.

Если вы заметили орфографическую ошибку на этой странице, просто выделите ошибку мышью и нажмите Ctrl+Enter.
Функция может не работать в некоторых версиях броузеров.

© При использовании любых материалов «Королевства Delphi» необходимо указывать источник информации. Перепечатка авторских статей возможна только при согласии всех авторов и администрации сайта.
Все используемые на сайте торговые марки являются собственностью их производителей.

"Operation not supported" and "Printer selected is not valid" errors while printing

Hopefully somebody will be able to help. In my Delphi 7 application small percentage of users report errors when printing and I’m trying to resolve this with last of them. I’m slightly limited when it comes to testing (as user is physically distant and we are working it out via e-mail), but I get some additional information from EurekaLog.

Anyway, first error that he got is «Operation not supported on selected printer», at this line of code:

So, I assumed that his printer doesn’t support Orientation (I never heard of this, but I guess it’s possible) and tried without this line of code. But now he gets «Printer selected is not valid» at this line:

As far as I know, printer is correctly selected (it’s Canon Pixma iP1500, but other users have other models, inkjet or laser), and he already tried to update drivers. OS also varies — from XP to Vista SP1).

I suggested to him to try with another printer, but whatever he responds, I don’t know where to look next. Google search didn’t give any useful results (for me, at least). Does anyone have an idea?

"Operation not supported" and "Printer selected is not valid" errors while printing

Not a solution but a tip for reducing the bug surface: Install (or have the user install) a virtual printer on that system and try to print to that one. A free (both as in beer, and as in freedom) virtual PDF printer comes with the excellent PDFCreator. It definitely supports page orientation. That will give you a known good baseline against which to test.

Solution 2

Not a direct solution, but it may help solve the problem. First thing I do with this sort of problem is get the exact driver version from the customer, and then download the driver and install it on my PC, using LPT1. I can then print against it for testing, and resolve any issues with the driver. Obviously I can’t actually print, but that isn’t usually a problem. Using a virtual machine helps a lot too.

Solution 3

You say that a small percentage of users report the problems. Do you have any idea what is the difference between these and the other users?

  • used printers
  • printer drivers (version)
  • OS used, including patches and updates (don’t forget the IE updates)
  • version of your software
  • other installed software

Do the users have print problems with other applications?

It would be a great help if you could reproduce the problem.

Solution 4

The error you get points in the direction that SetDefaultPrinter or the printer enumeration fails. SetDefaultPrinter looks a bit scary in Delphi 7. For example it tries to read the default printer from the Registry. It got better in newer Delphi versions, but I still patch Printers.pas in every new version.

This is my patch for Delphi 2009. You might have to make some adjustments for Delphi 7, but this should give you an idea. There is not much left from the original function.

If this does not work, then the next step would be checking why printer enumeration fails. Take a look at «Device», «Driver», «Port» of the TPrinterDevice list.

Solution 5

I have had users report this same error but only on Windows Vista. Windows XP and 7 do not appear to have the same issue. I have found that on Windows Vista computers turning off the UAC will eliminate this problem.

Related videos on Youtube

How to Fix cannot Set Default Printer With Error : 0x00000709

Mẹo 8 phút tổng hợp biết rõ các kiểu lỗi không in được hay gặp nhất

Fix Printer Not Accepting Print Command

Fixing an Error Occurred During Port Configuration on Windows 11/10/8/7 [Tutorial]

Is your Input Image size not printing the size you intended it to be??

Windows cannot connect to the printer. Operation failed with error 0x0000011b

Fixing an Error Occurred During Port Configuration on Windows 10

Error printing on canon ip2700 series/Printer Not Responding

Operation Could Not be Completed Error 0×00000709 - Fix

Fix HP Printer Not Printing Error 0x0000007f Operation Could Not Be Completed

How to Fix All Printer Printing Issues In Windows PC (Easy)

HP Printer Error E2

Updated on December 17, 2020

Comments

Hopefully somebody will be able to help. In my Delphi 7 application small percentage of users report errors when printing and I’m trying to resolve this with last of them. I’m slightly limited when it comes to testing (as user is physically distant and we are working it out via e-mail), but I get some additional information from EurekaLog.

Anyway, first error that he got is «Operation not supported on selected printer», at this line of code:

So, I assumed that his printer doesn’t support Orientation (I never heard of this, but I guess it’s possible) and tried without this line of code. But now he gets «Printer selected is not valid» at this line:

As far as I know, printer is correctly selected (it’s Canon Pixma iP1500, but other users have other models, inkjet or laser), and he already tried to update drivers. OS also varies — from XP to Vista SP1).

I suggested to him to try with another printer, but whatever he responds, I don’t know where to look next. Google search didn’t give any useful results (for me, at least). Does anyone have an idea?

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *