Delphi-PRAXiS
Seite 2 von 3     12 3      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi PDF Creator innerhalb Delphi nutzen (https://www.delphipraxis.net/152330-pdf-creator-innerhalb-delphi-nutzen.html)

freak4fun 18. Jun 2010 14:59

AW: PDF Creator innerhalb Delphi nutzen
 
Die unterstützen im Moment wohl kein Delphi.
Zitat:

Die API existiert aktuell für die Programmiersprachen Javascript und PHP: ...

Cogito 18. Jun 2010 15:00

AW: PDF Creator innerhalb Delphi nutzen
 
Zitat:

Zitat von HeikoAdams (Beitrag 1029935)
Zitat:

Zitat von Cogito (Beitrag 1029933)
Vielen Dank, aber der PDF Creator leistet genau das was ich benötige und kostet nix. Das Problem ist nur das ich nicht weiß wie ich das Ding von Delphi aus steuern kann... :cry:

PDF Creator hat doch eine COM-Schnittstelle und die müsste auch via Delphi ansprechbar sein

Ja stimmt, aber genau die funzt bei mir nicht...:cry:

mkinzler 21. Jun 2010 09:15

AW: PDF Creator innerhalb Delphi nutzen
 
Vielleicht wäre QuickPDF lite oder die Synopsis PDF engine eine Alternative

DeddyH 21. Jun 2010 09:20

AW: PDF Creator innerhalb Delphi nutzen
 
Oder Synopse. Hab ich zwar noch nie benutzt, liest sich aber nicht schlecht.

squetk 1. Jul 2010 18:39

AW: PDF Creator innerhalb Delphi nutzen
 
Folgender im Netz gefundener Sourcecode als Beispiel für eine späte Bindung funktioniert:
Delphi-Quellcode:
unit uPDFCreator;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ActiveX, ComObj, Mask, JvExMask, JvToolEdit;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    ButtonExecute : TButton;
    procedure ButtonExecuteClick(Sender: TObject);
  private
    PDFCreator, MSWord: OleVariant;
    optUseAutosave, optUseAutoSaveDirectory, optAutosaveFormat,
    optPDFColorsColorModel: Integer;
    optAutosaveDirectory, optAutosaveFilename: String;
    // Security Options
    optPDFUseSecurity, optPDFHighEncryption, optPDFOwnerPass: Integer;
    optPDFDisallowCopy, optPDFDisallowModifyAnnotations,
    optPDFDisallowModifyContents, optPDFDisallowPrinting: Integer;
    optPDFAllowAssembly, optPDFAllowDegradedPrinting, optPDFAllowFillIn,
    optPDFAllowScreenReaders: Integer;
    optPDFOwnerPasswordString: String;
    procedure StorePDFOptions;
    procedure SetPDFOptions(const filename, ownerpass: String);
    procedure RestorePDFOptions;
  public

  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.ButtonExecuteClick(Sender: TObject);
const
   output_filename: String = 'D:\test.pdf';
   owner_password: String = '';
var
   c, printJobCount: Integer;
   optPrintBackground: Boolean;
begin
   PDFCreator := CreateOLEObject('PDFCreator.clsPDFCreator');

   PDFCreator.cStart('/NoProcessingAtStartup');

   StorePDFOptions;
   SetPDFOptions(output_filename, owner_password);

   MSWord := CreateOleObject('Word.Application');
   try
      MSWord.DisplayAlerts := 0;

      MSword.Documents.Open(Edit1.Text);

      MSWord.ActiveDocument.TrackRevisions := false;
      optPrintBackground := MSWord.Options.PrintBackground;
      if not optPrintBackground then
         MSWord.Options.PrintBackground := True;
      MSWord.ActiveWindow.View.ShowRevisionsAndComments := False;
      MSWord.Options.WarnBeforeSavingPrintingSendingMarkup := false;

      printJobCount := PDFCreator.cCountOfPrintJobs;
      /// ------------------------------------------
      ///   Have PDFCreator wait for pages
      PDFCreator.cPrinterStop := true;

      MSWord.ActiveDocument.PrintoutOld;

      ///   we don't want to continue on right after telling word to print, because it can cause problems
      while MSWord.BackgroundPrintingStatus <> 0 do
      begin
        Sleep(10);
        Application.ProcessMessages;
      end;

      /// Tell PDFCreator we're done printing pages.
      PDFCreator.cPrinterStop := false;
      /// ------------------------------------------

      ///   now wait for PDFCreator to finish
      c := PDFCreator.cCountOfPrintJobs;
      while c > printJobCount do
      begin
         Sleep(10);
         Application.ProcessMessages;
         c := PDFCreator.cCountOfPrintJobs;
      end;

      MSword.ActiveDocument.Close(SaveChanges := 0);
   finally
      VarClear(MSWord);
   end;

   RestorePDFOptions;

   PDFCreator.cClose;

   VarClear(PDFCreator);

end;

procedure TForm1.RestorePDFOptions;
begin
   PDFCreator.cOption('UseAutosave') := optUseAutosave;
   PDFCreator.cOption('UseAutosaveDirectory') := optUseAutosaveDirectory;
   PDFCreator.cOption('AutosaveDirectory') := optAutosaveDirectory;
   PDFCreator.cOption('AutosaveFilename') := optAutosaveFilename;
   PDFCreator.cOption('AutosaveFormat') := optAutosaveFormat;
   PDFCreator.cOption('PDFColorsColorModel') := optPDFColorsColorModel;

   // security options
   PDFCreator.cOption('PDFUseSecurity') := optPDFUseSecurity;
   PDFCreator.cOption('PDFHighEncryption') := optPDFHighEncryption;
   PDFCreator.cOption('PDFOwnerPass') := optPDFOwnerPass;
   PDFCreator.cOption('PDFOwnerPasswordString') := optPDFOwnerPasswordString;
   PDFCreator.cOption('PDFDisallowCopy') := optPDFDisallowCopy;
   PDFCreator.cOption('PDFDisallowModifyAnnotations') := optPDFDisallowModifyAnnotations;
   PDFCreator.cOption('PDFDisallowModifyContents') := optPDFDisallowModifyContents;
   PDFCreator.cOption('PDFDisallowPrinting') := optPDFDisallowPrinting;
   PDFCreator.cOption('PDFAllowAssembly') := optPDFAllowAssembly;
   PDFCreator.cOption('PDFAllowDegradedPrinting') := optPDFAllowDegradedPrinting;
   PDFCreator.cOption('PDFAllowFillIn') := optPDFAllowFillIn;
   PDFCreator.cOption('PDFAllowScreenReaders') := optPDFAllowScreenReaders;

   PDFCreator.cSaveOptions;

   Sleep(100);
end;

procedure TForm1.SetPDFOptions(const filename, ownerpass: String);
begin
   // set the options we want, auto-save PDF with specific filename
   PDFCreator.cOption('UseAutosave') := 1;
   PDFCreator.cOption('UseAutosaveDirectory') := 1;
   PDFCreator.cOption('AutosaveDirectory') := ExtractFilePath(filename);
   PDFCreator.cOption('AutosaveFilename') := ExtractFileName(filename);
   PDFCreator.cOption('AutosaveFormat') := 0; // PDF format
   PDFCreator.cOption('PDFColorsColorModel') := 0; // RGB format

   if Trim(ownerpass) <> '' then
   begin
      PDFCreator.cOption('PDFUseSecurity') := 1;
      PDFCreator.cOption('PDFHighEncryption') := 1;
      PDFCreator.cOption('PDFOwnerPass') := 1;
      PDFCreator.cOption('PDFOwnerPasswordString') := ownerpass;
      PDFCreator.cOption('PDFDisallowCopy') := 0;
      PDFCreator.cOption('PDFDisallowModifyAnnotations') := 1;
      PDFCreator.cOption('PDFDisallowModifyContents') := 1;
      PDFCreator.cOption('PDFDisallowPrinting') := 0;
      PDFCreator.cOption('PDFAllowAssembly') := 0;
      PDFCreator.cOption('PDFAllowDegradedPrinting') := 0;
      PDFCreator.cOption('PDFAllowFillIn') := 0;
      PDFCreator.cOption('PDFAllowScreenReaders') := 0;
   end;
   PDFCreator.cSaveOptions;
end;

procedure TForm1.StorePDFOptions;
begin
   // save the current options to put back when we're finished.
   optUseAutosave := PDFCreator.cOption['UseAutosave'];
   optUseAutosaveDirectory := PDFCreator.cOption['UseAutosaveDirectory'];
   optAutosaveDirectory := PDFCreator.cOption['AutosaveDirectory'];
   optAutosaveFilename := PDFCreator.cOption['AutosaveFilename'];
   optAutosaveFormat := PDFCreator.cOption['AutosaveFormat'];
   optPDFColorsColorModel := PDFCreator.cOption['PDFColorsColorModel'];

   // security options
   optPDFUseSecurity := PDFCreator.cOption['PDFUseSecurity'];
   optPDFHighEncryption := PDFCreator.cOption['PDFHighEncryption'];
   optPDFOwnerPass := PDFCreator.cOption['PDFOwnerPass'];
   optPDFOwnerPasswordString := PDFCreator.cOption['PDFOwnerPasswordString'];
   optPDFDisallowCopy := PDFCreator.cOption['PDFDisallowCopy'];
   optPDFDisallowModifyAnnotations := PDFCreator.cOption['PDFDisallowModifyAnnotations'];
   optPDFDisallowModifyContents := PDFCreator.cOption['PDFDisallowModifyContents'];
   optPDFDisallowPrinting := PDFCreator.cOption['PDFDisallowPrinting'];
   optPDFAllowAssembly := PDFCreator.cOption['PDFAllowAssembly'];
   optPDFAllowDegradedPrinting := PDFCreator.cOption['PDFAllowDegradedPrinting'];
   optPDFAllowFillIn := PDFCreator.cOption['PDFAllowFillIn'];
   optPDFAllowScreenReaders := PDFCreator.cOption['PDFAllowScreenReaders'];
end;

end.
Ich hätte aber gern die frühe Bindung eingesetzt (wie z.B. im PDFCreator COM Sample für C# gezeigt), leider funktioniert dieses nicht, wenn ich es in Delphi umsetze. Der Vorteil wäre, dass man dann auf Ereignisse wie OnError und OnReady reagieren könnte.

Eins noch: Der o.a. Quellcode funktionierte bei mir erst dann, als ich den PDFCreator-Druckertreiber auf Direktdruck gestellt habe. Kenn jemand eine Möglichkeit, dies vom Programmcode aus einzustellen?

inca 27. Jul 2011 18:27

AW: PDF Creator innerhalb Delphi nutzen
 
Hm, bei mir funktioniert es nicht. Ich kann noch nicht einmal programmseitig, also von Delphi aus, den Namen der pdf-Datei festlegen.... :shock:

omata 28. Jul 2011 00:30

AW: PDF Creator innerhalb Delphi nutzen
 
Vielleicht hilft etwas von hier weiter.

inca 28. Jul 2011 08:39

AW: PDF Creator innerhalb Delphi nutzen
 
Danke erstmal für die Antwort. Ich weiß nicht, ob ich dich richtig verstanden habe, aber ich habe nur beim Arbeiten mit dem pdfCreator das Problem, dass der filename nicht vergeben werden kann. Der Codeschnipsel hat bei mir keine Auswirkungen. Der pdfcreator arbeitet an sich einwandfrei, ich kann pdfs drucken, habe auch einen ähnlichen Code wie in dem von dir beschriebenen link laufen, alles korrekt. Aber der pdfcreator hört nicht auf meine filename-Zuweisung. Ausgegeben werden immer pdf-Dateien, deren Format etwa so ausschaut. 20110728093845.pdf. Also Datum zuerst und dann ein Rest. Hat jemand vielleicht noch einen Rat?!?

Jumpy 28. Jul 2011 09:09

AW: PDF Creator innerhalb Delphi nutzen
 
Ich hab das mal in Excel nach der folgenden Anleitung gemacht:

http://www.excelguru.ca/node/21

Da stand auch was zu den Settings:

http://www.excelguru.ca/node/37

OK. Ist VBA aber die Idee dahinter sollte dieselbe sein.


Was den Filename angeht, kann man (wenn ich mich recht erinnere) irgendwo in den Programmeinstellungen einstellen, das der einen automatischen Namen vergeben soll und dann ist es egal, was man bei filename angibt, das wird ignoriert. Keine Ahnung, wie man das per Programmierung ausstellt, doch kann man das ja testweise auch manuell im PDFCreator selbst machen. Einmal geändert, müsste die Einstellung erhalten bleiben.

rweinzierl 28. Jul 2011 09:16

AW: PDF Creator innerhalb Delphi nutzen
 
Hallo

Vielleicht hilft dir das weiter , im pdfCreator auf Autospeichern stellen und dann von Delphi aus die Pfade in die registry schreiben ==> Dann druckt er in die gewünschte Datei

mfg

Reinhold


var
reg: TRegistry;
begin
result := false;

reg := TRegistry.create;
reg.RootKey := HKEY_CURRENT_USER;
if reg.OpenKey('\Software\PDFCreator\Program',false) then
begin
reg.LazyWrite := false;
reg.WriteString('AutoSaveDirectory',extractfilepat h(Pdf_Dateiname));
reg.WriteString('AutoSaveFilename',extractfilename (Pdf_Dateiname));
reg.WriteString('UseAutosave','1');
result := true;
reg.CloseKey;
sleep(10);
end;
reg.Free;


Alle Zeitangaben in WEZ +1. Es ist jetzt 21:36 Uhr.
Seite 2 von 3     12 3      

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz