Ver Mensaje Individual
  #6  
Antiguo 16-12-2025
Garada Garada is offline
Miembro
 
Registrado: jul 2004
Posts: 90
Reputación: 22
Garada Va por buen camino
Ni idea.

El código nunca lo había probado, es de esas cosas que me apunto cuando lo veo por si hace falta algún día. 😅

Lo he probado en Delphi 2010, he hecho las mismas adaptaciones que tú (el widechar) y funciona bien en un equipo con W11 y otro con W10.
Revisa en los otros equipos si la impresora está instalada, se llama igual, etc.
Prueba también con un código más simple, como el ejemplo, por si hay algo que cause el error en otra parte del código de tu aplicación.

El código de mi prueba, un form y un botón:
Código Delphi [-]
uses
  Printers, ShellAPI;

procedure TForm1.btn1Click(Sender: TObject);
var
  PrtIndex: Integer;
  DeviceMode: Cardinal;
  Device,
  Driver,
  Port: array [0..255] of WideChar;
  PdfFileName: string;
begin
  PdfFileName := ExtractFilePath(Application.ExeName) + 'p.pdf';

  PrtIndex := Printer.Printers.IndexOf('Microsoft Print to PDF');
  if PrtIndex < 0 then
      raise Exception.Create('Printer not found');

  Printer.PrinterIndex := PrtIndex;
  Printer.GetPrinter(Device, Driver, Port, DeviceMode);
  Printer.SetPrinter(Device, Driver, PWideChar(PdfFileName), 0);
  Printer.BeginDoc;
  Printer.Canvas.TextOut(100, 100, 'Hello World ' + DateTimeToStr(Now));
  Printer.EndDoc;

  ShellExecute(0, 'open', PWideChar(PdfFileName), nil, nil, 0);
end;
Responder Con Cita