Ver Mensaje Individual
  #18  
Antiguo 07-03-2012
Avatar de roman
roman roman is offline
Moderador
 
Registrado: may 2003
Ubicación: Ciudad de México
Posts: 20.269
Reputación: 10
roman Es un diamante en brutoroman Es un diamante en brutoroman Es un diamante en bruto
Hola,

Observando con más detalle, veo que me he equivocado. Veamos, no hay que quitar la línea que comento sino sólo su parámetro. Si no se llama al método cStart, el PdfCreator no hace nada de nada.

Aquí un ejemplo de código que me ha funcionado:

Código Delphi [-]
var
  PrinterIndex: Integer;
  OldPrinterIndex: Integer;
  PdfCreator: OleVariant;

begin
  PrinterIndex := Printer.Printers.IndexOf('PdfCreator');
  if PrinterIndex <> -1 then
  begin
    OldPrinterIndex := Printer.PrinterIndex;
    Printer.PrinterIndex := PrinterIndex;

    PdfCreator := CreateOLEOBject('PDFCreator.clsPDFCreator');
    try
      PdfCreator.cStart();
      PdfCreator.cOption('UseAutosave') := 1;
      PdfCreator.cOption('UseAutosaveDirectory') := 1;
      PdfCreator.cOption('AutosaveDirectory') := 'c:\ruta\al\archivo';
      PdfCreator.cOption('AutosaveFilename') := 'test'; // la extensión es opcional
      PdfCreator.cOption('AutosaveFormat') := 0; // PDF format

      Self.Print; // A modo de ejemplo, imprimimos el formulario
    finally
      Printer.PrinterIndex := OldPrinterIndex;

      // método rudimentario para saber cuando terminó de crearse el archivo
      while not FileExists('c:\ruta\al\archivo\test.pdf') do
        Application.ProcessMessages;

      // Cerramos el monitor
      PdfCreator.cClose;
    end;
  end;
end;

Observa que no es necesario guardar las opciones anteriores y restablecerlas después ya que no uso el método cSaveOptions.

// Saludos
Responder Con Cita