IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Composants VCL Delphi Discussion :

[D7] Composant pour création de PDF


Sujet :

Composants VCL Delphi

  1. #1
    Membre chevronné
    Avatar de Droïde Système7
    Homme Profil pro
    Inscrit en
    Septembre 2003
    Messages
    2 262
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Septembre 2003
    Messages : 2 262
    Points : 1 928
    Points
    1 928
    Par défaut [D7] Composant pour création de PDF
    Bonjour

    Je suis depuis des heures, à la recherche d'un compo effectuant simplement la conversion du contenu d'un RichEdit en PDF, ou texte en PDF.

    J'en ai déjà testé trois ou quatre, et à chaque fois, bien que le compo soit disant freeware, en fin de compte il fallait payer pour le débrider ou bien il manquait un ou plusieurs fichiers.

    Ce dernier cas de figure est illustré par le compo freeware PDF Viewer for Delphi :
    http://www.synactis.com/

    Il manquait un fichier lors de l'installation, je l'ai trouvé et j'ai réussi l'install.

    Ensuite lors de la compil sur un essai, il me manque un autre fichier : SHDocVw.dcu

    Introuvable nulle part !

    Je connais la méthode d'exporter un ActiveX de telle ou telle appli et de l'installer en palette. Mais question licence, je ne souhaite pas tomber dans une licence contagieuse !!!

    Si quelqu'un sait ou se procurer un bon compo fiable, même payant, mais pas plus des 50 €, je vais regarder ça de plus près, merci.


  2. #2
    Membre actif Avatar de petitprince
    Homme Profil pro
    Développeur en systèmes embarqués
    Inscrit en
    Juillet 2006
    Messages
    322
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Finistère (Bretagne)

    Informations professionnelles :
    Activité : Développeur en systèmes embarqués

    Informations forums :
    Inscription : Juillet 2006
    Messages : 322
    Points : 267
    Points
    267
    Par défaut
    Regarde du côté de la la librairie gratuite PowerPDF et ses exemples....
    Et si tu patiente un peu, vers la rentrée je pense la rééditer, en la mettant enfin à jour ....

  3. #3
    Membre chevronné
    Avatar de Droïde Système7
    Homme Profil pro
    Inscrit en
    Septembre 2003
    Messages
    2 262
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Septembre 2003
    Messages : 2 262
    Points : 1 928
    Points
    1 928
    Par défaut
    petitprince merci

    J'ai installé le compo et j'ai une belle palette.
    http://www.est.hi-ho.ne.jp/takeshi_kanno/powerpdf/

    Je ne sais pas encore créer un PFD via un texte ou un RichEdit.

    Mais PowerPdf is free software based on LGPL. You can use or modify it under the GNU Library general Public License.

    N'est-ce pas une licence contagieuse ?

    Autrement dit, tout soft utilisant une ressource de ce type sera de plein droit transformé sous licence GPL.

    Bref, si le logiciel auquel l'on apporte cette ressource, que ce soit un freeware ou shareware, hé bien tout est changé

    Qui peut me contredire ?

    @+

  4. #4
    Expert éminent sénior
    Avatar de ShaiLeTroll
    Homme Profil pro
    Développeur C++\Delphi
    Inscrit en
    Juillet 2006
    Messages
    13 455
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Développeur C++\Delphi
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2006
    Messages : 13 455
    Points : 24 867
    Points
    24 867
    Par défaut
    SHDocVw, c'est le "Shell Web Document" dans "C:\Program Files\Borland\Delphi6\Source\Internet", c'est ni plus ni moins le bon Vieux IWebBrowser ...

    Personnellement, pour le PDF, je n'ai utilise que des imprimantes virtuelles comme PDF995 ou alors des composants très cher qui gère le RTF2 (image, tableau avancé que bcp de RichEdit pour Report ne gère pas comme le TRichEdit standard de Windows 95 au lieu de nouveau fourni par WordPad, riched20.dll contre riched32.dll)

    Faut un jour que je regarde si avec la JVCL on peut pas adapter le TJvRichEdit sur un Report (via Canvas) et si il n'ont pas des composants PDF ... je n'ai jamais pris le temps de chercher
    Aide via F1 - FAQ - Guide du développeur Delphi devant un problème - Pensez-y !
    Attention Troll Méchant !
    "Quand un homme a faim, mieux vaut lui apprendre à pêcher que de lui donner un poisson" Confucius
    Mieux vaut se taire et paraître idiot, Que l'ouvrir et de le confirmer !
    L'ignorance n'excuse pas la médiocrité !

    L'expérience, c'est le nom que chacun donne à ses erreurs. (Oscar Wilde)
    Il faut avoir le courage de se tromper et d'apprendre de ses erreurs

  5. #5
    Membre chevronné
    Avatar de Droïde Système7
    Homme Profil pro
    Inscrit en
    Septembre 2003
    Messages
    2 262
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Septembre 2003
    Messages : 2 262
    Points : 1 928
    Points
    1 928
    Par défaut
    Oki merci ShaiLeTroll. Mais sous D7 perso = niet de ce compo là

    Sur la JVCL, j'avais regardé avec attention = no truc pour PDF (version 3.33)

    Il existe une DLL en CardWare ici :
    (dsPdf en freeware, vers bas de page)
    http://delphistep.cis.si/

    Sous Vista ça fonctionne impec (la DLL est limitée à 10 pages = CardWare...)
    Mais j'ai un testeur qui sous son XP = rien ne se passe. Même avec la DLL aux côtés de l'EXE de démo.

    @+

    Edit :

    Pour PowerPDF, si un utilsateur peut me guider pour le code de comment imprimer un fichier texte et un RichEdit, ce serait sympa.

    J'ai fait ça, mais marche pôô :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    procedure TForm1.btnPrintClick(Sender: TObject);
    begin
      if not SaveDialog1.Execute then Exit;
      with PReport1 do
      begin
        FileName := SaveDialog1.FileName;
        BeginDoc;
          Print(test.txt);
        EndDoc;
      end;
    end;

  6. #6
    Expert éminent sénior
    Avatar de ShaiLeTroll
    Homme Profil pro
    Développeur C++\Delphi
    Inscrit en
    Juillet 2006
    Messages
    13 455
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Développeur C++\Delphi
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2006
    Messages : 13 455
    Points : 24 867
    Points
    24 867
    Par défaut
    Verso Perso, il te suffit d'importer TWebBrowser de IE, et tu obtiens une joli TLB, c'est ce que je faisais avec Delphi 3

    Oui, j'ai vite fait regardé dans la JVCL, pas de PDF, une question de licence surement ...

    Utilisant InfoPower, ExtraDevice sur ReportBuilder, je ne peux pas t'aider, c'est juste une solution à 2000$ ...
    Aide via F1 - FAQ - Guide du développeur Delphi devant un problème - Pensez-y !
    Attention Troll Méchant !
    "Quand un homme a faim, mieux vaut lui apprendre à pêcher que de lui donner un poisson" Confucius
    Mieux vaut se taire et paraître idiot, Que l'ouvrir et de le confirmer !
    L'ignorance n'excuse pas la médiocrité !

    L'expérience, c'est le nom que chacun donne à ses erreurs. (Oscar Wilde)
    Il faut avoir le courage de se tromper et d'apprendre de ses erreurs

  7. #7
    Membre chevronné
    Avatar de Droïde Système7
    Homme Profil pro
    Inscrit en
    Septembre 2003
    Messages
    2 262
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Septembre 2003
    Messages : 2 262
    Points : 1 928
    Points
    1 928
    Par défaut
    Hello Shai

    Il me suffit d'importer TWebBrowser de IE, oki je vais regarder ça alors, mais:

    .. Installer des paquets => Ajouter...

    Est-ce bien cela ? si oui, je me dirige vers le folder de ...Windows/System 32, car j'ai vu des .BLP ?

    Oui mais si c'est suivant le principe de cette méthode = the licence...

    Sinon, je vais me résigner à installer le mammouth, afin de voir...

    http://delphi.about.com/library/howto/htusepdf.htm

    Mais suivant les termes de la licence, toute utilisation de code / ressources est interdite, ou soumise à autorisation, alors perdu d'avance
    http://www.adobe.com/devnet/acrobat/...sdk6_eula.html

    @+ et merci.

    Edit :
    J'ajoute ici, deux autres liens trouvés, si ça peut servir à d'autres développeurs.
    http://www.vbgold.com/AdvancedPDFPrinterEditions.shtml (mais du VB )
    http://www.aloaha.com/wi-software-en/pdf-autoprint.php (J'peux pas tester la démo pour l'instant, car en pleine update mur de feu KIS...)

  8. #8
    Rédacteur/Modérateur

    Avatar de SergioMaster
    Homme Profil pro
    Développeur informatique retraité
    Inscrit en
    Janvier 2007
    Messages
    15 041
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 67
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2007
    Messages : 15 041
    Points : 40 950
    Points
    40 950
    Billets dans le blog
    62
    Par défaut
    D7 n'est pas fourni avec RaveReport ? il me semble que oui . Il n'est donc pas très sorcier d'éditer un fichier sous rave qui se fait un plaisir de proposer une sortie PDF .

    Autre solution également dispo : Quickreport et quelques manips que j'ai pu faire (voir dans le forum solutions d'entreprise , business intelligence )
    MVP Embarcadero
    Delphi installés : D3,D7,D2010,XE4,XE7,D10 (Rio, Sidney), D11 (Alexandria), D12 (Athènes)
    SGBD : Firebird 2.5, 3, SQLite
    générateurs États : FastReport, Rave, QuickReport
    OS : Window Vista, Windows 10, Windows 11, Ubuntu, Androïd

  9. #9
    Membre chevronné
    Avatar de Droïde Système7
    Homme Profil pro
    Inscrit en
    Septembre 2003
    Messages
    2 262
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Septembre 2003
    Messages : 2 262
    Points : 1 928
    Points
    1 928
    Par défaut
    SergioMaster,

    D7 n'est pas fourni avec RaveReport ?
    Pas vu sur ma version perso idem pas de WebBrowser.

    Quickreport :

    QuickReport de QuSoft est un générateur d'état livré avec les versions "Profesionnel" et "Entreprise" de Delphi.

    @+ et merci de ces infos.

  10. #10
    Rédacteur/Modérateur
    Avatar de Andnotor
    Inscrit en
    Septembre 2008
    Messages
    5 691
    Détails du profil
    Informations personnelles :
    Localisation : Autre

    Informations forums :
    Inscription : Septembre 2008
    Messages : 5 691
    Points : 13 121
    Points
    13 121
    Par défaut
    J'utilise personnellement libharu.
    Pas de composant, mais une bibliothèque puissante .

  11. #11
    Membre chevronné
    Avatar de Droïde Système7
    Homme Profil pro
    Inscrit en
    Septembre 2003
    Messages
    2 262
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Septembre 2003
    Messages : 2 262
    Points : 1 928
    Points
    1 928
    Par défaut Patinage artistique
    Andnotor merci !

    Je viens de jeter un oeil, une véritable mine d'or ce Sourceforge.

    Mais au niveau install, quel binz... pourquoi tout est de plus en plus alambiqué ?

    J'approfondis pour voir si je peux déjà installer la bête...
    http://libharu.org/wiki/Documentation/Install

    @+

    Edit : boffff, si quelqu'un y arrive, qu'il en fasse profiter les copains
    Car super pas évident cette install à la noix.
    Pourquoi effectuer un dézippage en ligne de commande ?

    Un pas-à-pas ne serait pas du luxe.
    (Après un certain temps, un certain fichier .RC me dit quelque chose )

    Merci d'avance

  12. #12
    Membre du Club
    Profil pro
    Inscrit en
    Février 2007
    Messages
    70
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2007
    Messages : 70
    Points : 57
    Points
    57
    Par défaut
    j'ai pas mal cherché aussi et je me suis rabattu sur l'imprimante virtuelle pdf creator

    avant de lancer l'impression il faut modifier la base de registre pour éviter d'avoir à parametrer le nom et le chemin du fichier dans pdfcreator et demander l'impession automatique

    reg:=tregistry.create;
    reg.rootkey:=HKEY_CURRENT_USER;
    reg.openkey('\Software\PDFCreator\Program',true);
    reg.WriteString('Autosavedirectory',chemin de l'impression);
    reg.WriteString('Autosavefilename',nom du fichier(sans l'extension)) ;
    reg.Writestring('UseAutosave','1');
    ensuite modifier quickreport.PrinterSettings.PrinterIndex vers pdf creator

    @+

  13. #13
    Membre chevronné
    Avatar de Droïde Système7
    Homme Profil pro
    Inscrit en
    Septembre 2003
    Messages
    2 262
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Septembre 2003
    Messages : 2 262
    Points : 1 928
    Points
    1 928
    Par défaut
    Hello Roland,

    ensuite modifier quickreport.PrinterSettings.PrinterIndex vers pdf creator
    Si tu as QuickReport ; tu n'est pas sous une version perso de Delphi, toute la difficulté est là

    Ensuite, j'évite de beurrer la BdR des utilisateurs, question de confiance.

    Pour terminer, faut que les utilisateurs aient d'installé PDF Creator...

  14. #14
    Rédacteur/Modérateur
    Avatar de Andnotor
    Inscrit en
    Septembre 2008
    Messages
    5 691
    Détails du profil
    Informations personnelles :
    Localisation : Autre

    Informations forums :
    Inscription : Septembre 2008
    Messages : 5 691
    Points : 13 121
    Points
    13 121
    Par défaut
    Je n'ai rien construit de particulier pour Libharu .

    Après dézippage:
    Il te faut simplement copier la dll dans le répertoire de ton application. Tu as ensuite le répertoire If\Delphi avec les unités à inclure dans ton projet.

    hpdf.pas sera nécessaire. Pour les autres, ajoute un chemin de recherche sur ce répertoire.

  15. #15
    Membre chevronné
    Avatar de Droïde Système7
    Homme Profil pro
    Inscrit en
    Septembre 2003
    Messages
    2 262
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Septembre 2003
    Messages : 2 262
    Points : 1 928
    Points
    1 928
    Par défaut
    Il te faut simplement copier la dll dans le répertoire de ton application
    Toute mon interrogation réside surtout en ce point précis = il se trouve aucune DLL dans le fichier téléchargé !

    Dans un dossier nommé Win32, se trouve des dossiers, dans lesquels se trouve des .RC et des .RES.

    J'avais pensé à la méthode de compil de DLL, mais il se trouve pleins de .RC

    Quel binzzz !

    A moins que j'ai raté une marche...

    J'avais téléchargé ce fichier précis :
    http://libharu.org/files/libharu-2.1.0.tar.gz
    Celui en Latest Version ici :
    http://libharu.org/wiki/Downloads

    Si ça se trouve, je m'suis gouré de fichier.

  16. #16
    Rédacteur/Modérateur
    Avatar de Andnotor
    Inscrit en
    Septembre 2008
    Messages
    5 691
    Détails du profil
    Informations personnelles :
    Localisation : Autre

    Informations forums :
    Inscription : Septembre 2008
    Messages : 5 691
    Points : 13 121
    Points
    13 121
    Par défaut
    Je ne sais pas se qu'apporte la 2.1.0. J'utilise la 2.0.8 et ce zip inclus l'ensemble.

  17. #17
    Membre chevronné
    Avatar de Droïde Système7
    Homme Profil pro
    Inscrit en
    Septembre 2003
    Messages
    2 262
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Septembre 2003
    Messages : 2 262
    Points : 1 928
    Points
    1 928
    Par défaut
    Citation Envoyé par Andnotor Voir le message
    Je ne sais pas se qu'apporte la 2.1.0. J'utilise la 2.0.8 et ce zip inclus l'ensemble.
    Whaouuuu !!! je ne sais pas non plus, mais j'peux te dire que ton lien ici donne bien la DLL en question, pas l'autre lien.

    Je regarde ça avec attention.

    @+

  18. #18
    Membre chevronné
    Avatar de Droïde Système7
    Homme Profil pro
    Inscrit en
    Septembre 2003
    Messages
    2 262
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Septembre 2003
    Messages : 2 262
    Points : 1 928
    Points
    1 928
    Par défaut
    Citation Envoyé par Andnotor Voir le message
    Je n'ai rien construit de particulier pour Libharu .

    Après dézippage:
    Il te faut simplement copier la dll dans le répertoire de ton application. Tu as ensuite le répertoire If\Delphi avec les unités à inclure dans ton projet.

    hpdf.pas sera nécessaire. Pour les autres, ajoute un chemin de recherche sur ce répertoire.
    Alors ça avance... en plus ça plante pas.

    Mais comment affecter le chemin du fichier .txt ou .rtf, j'ai bidouillé ça :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    procedure TForm1.btnPrintClick(Sender: TObject);
    const
      fname: string = 'Essai.pdf';
    var
      pdf: HPDF_Doc;
      font: HPDF_Font;
      page: HPDF_Page;
      path: String;
    begin
      pdf := HPDF_New(@error_handler, nil);
      if pdf = nil then
      begin
       ShowMessage('Erreur !');
       exit;
      end;
     
      path := 'Test.txt';
     
      try
        HPDF_SetCompressionMode(pdf, HPDF_COMP_ALL);
     
        {* create default-font *}
        font := HPDF_GetFont(pdf, 'Helvetica', nil);
     
        {* add a new page object. *}
        page := HPDF_AddPage(pdf);
     
     
        {* print the lines of the page. *}
        HPDF_Page_SetLineWidth(page, 1);
     
        HPDF_Page_SetFontAndSize (page, font, 10);
     
        HPDF_Page_BeginText (page);
     
     
    //HPDF_Page_ShowText (page, 'CurveTo(x1, y1, x2. y2, x3, y3)');
    HPDF_Page_ShowText(page, pChar(path));
        HPDF_Page_EndText (page);
     
     
     
        {* save the document to a file *}
        HPDF_SaveToFile (pdf, PChar(fname));
      finally  
      end;
     
     
      HPDF_Free (pdf);
    end;

    @+

    Edit : Si j'avais trouvé ça en premier
    http://www.marclebrun.be/doku.php?id...eration_de_pdf

    Encore du super :
    http://www.developpez.net/forums/d54...cents-libharu/

    Andnotor, je te dois au moins un et
    Mais pour l'instant je patine pour affecter un fichier .txt ou .rtf

  19. #19
    Rédacteur/Modérateur
    Avatar de Andnotor
    Inscrit en
    Septembre 2008
    Messages
    5 691
    Détails du profil
    Informations personnelles :
    Localisation : Autre

    Informations forums :
    Inscription : Septembre 2008
    Messages : 5 691
    Points : 13 121
    Points
    13 121
    Par défaut
    Je m'étais fait une petite classe pour simplifer ces appels. A noter que je n'ai implémenté que ce que j'avais vraiment besoin .

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    unit PrintPDF;
     
    interface
     
    uses SysUtils, Graphics, hpdf, hpdf_types, hpdf_consts, Math, StrUtils;
     
    type
      TFonts = record
        Name :string;
        Size :HPDF_REAL;
      end;
     
      TPrintPDF = class
      private
        FCurPos :THPDF_Point;
        FFonts  :array of TFonts;
        Doc  :HPDF_Doc;
        font :HPDF_Font;
        page :HPDF_Page;
        FMargins :THPDF_Rect;
        FTitle: string;
        FAuthor: string;
        FSubject: string;
        FCreator: string;
        FKeywords: string;
        function GetCurPos: THPDF_Point;
        procedure SetCurPos(const Value: THPDF_Point);
        procedure SetMargins(const Value: THPDF_Rect);
        function GetPageSize: THPDF_Point;
        function GetInnerPageSize: THPDF_Point;
        function GetFontSize: HPDF_REAL;
        procedure SetTitle(const Value: string);
        procedure SetAuthor(const Value: string);
        procedure SetCreator(const Value: string);
        procedure SetKeywords(const Value: string);
        procedure SetSubject(const Value: string);
      public
        procedure NewPage;
        procedure AddFont(aName :string; aSize :HPDF_REAL);
        procedure SelectFont(aIndex :integer);
        procedure IncCurPosY(aValue :HPDF_REAL);
        procedure IncCurPosX(aValue :HPDF_REAL);
        procedure SaveToFile(aFileName :TFileName);
        procedure Write(aText :string; aFontIndex :integer = -1);
        procedure WriteLn(aText :string = ''; aFontIndex :integer = -1);
        procedure TextOut(X, Y: HPDF_REAL; aText :string; aFontIndex :integer = -1);
        procedure WriteLink(aText, aURL :string);
        procedure WriteLinkLn(aText, aURL :string);
        procedure DrawImage(aFileName :TFileName; X, Y, W, H :HPDF_REAL);
        function  TextWidth(aText :string) :HPDF_REAL;
        procedure Rectangle(aLeft, aTop, aWidth, aHeight :HPDF_REAL; aLineWidth: HPDF_REAL = 0.3; aLineColor :TColor = $000000; aFillColor :TColor = $FFFFFF);
        constructor Create(aFontName :string = 'Helvetica'; aFontSize :HPDF_REAL = 10);
        destructor Destroy; override;
      published
        property PageSize :THPDF_Point read GetPageSize;
        property FontSize :HPDF_REAL read GetFontSize;
        property InnerPageSize :THPDF_Point read GetInnerPageSize;
        property Margins :THPDF_Rect read FMargins write SetMargins;
        property CurPos :THPDF_Point read GetCurPos write SetCurPos;
        property Title :string read FTitle write SetTitle;
        property Author :string read FAuthor write SetAuthor;
        property Creator :string read FCreator write SetCreator;
        property Subject :string read FSubject write SetSubject;
        property Keywords :string read FKeywords write SetKeywords;
      end;
     
      function Pointmm(X, Y :HPDF_REAL) :THPDF_Point;
      function Rectmm(aLeft, aTop, aRight, aBottom :HPDF_REAL) :THPDF_Rect;
      function Incmm(var aValue :HPDF_REAL; aInc :HPDF_REAL) :HPDF_REAL;
     
    implementation
     
    const
      DefaultFontSize :HPDF_REAL = 10;
     
    function Pointmm(X, Y :HPDF_REAL) :THPDF_Point;
    begin
      Result.X := X;
      Result.Y := Y;
    end;
     
    function Rectmm(aLeft, aTop, aRight, aBottom :HPDF_REAL) :THPDF_Rect;
    begin
      Result.Left   := aLeft;
      Result.Top    := aTop;
      Result.Right  := aRight;
      Result.Bottom := aBottom;
    end;
     
    function Incmm(var aValue :HPDF_REAL; aInc :HPDF_REAL) :HPDF_REAL;
    begin
      aValue := aValue +aInc;
      Result := aValue;
    end;
     
    procedure error_handler (error_no: HPDF_STATUS; detail_no: HPDF_STATUS; user_data: Pointer); stdcall;
    begin
      raise Exception.Create(Format('Error: %d - %d', [Error_No, Detail_No]));
    end;
     
    { TPrintPDF }
     
    procedure TPrintPDF.AddFont(aName: string; aSize: HPDF_REAL);
    var
      i :integer;
    begin
      i := High(FFonts) +1;
      SetLength(FFonts, i +1);
      FFonts[i].Name := aName;
      FFonts[i].Size := aSize;
    end;
     
    constructor TPrintPDF.Create(aFontName :string; aFontSize :HPDF_REAL);
    begin
      Doc := HPDF_New(@error_handler, nil);
      HPDF_SetCompressionMode(Doc, HPDF_COMP_ALL);
      font := HPDF_GetFont(Doc, PChar(aFontName), 'WinAnsiEncoding');
      Margins := Rectmm(5, 5, 5, 5);
     
      NewPage;
      AddFont(aFontName, aFontSize);
      SelectFont(0);
    end;
     
    destructor TPrintPDF.Destroy;
    begin
      HPDF_Free(Doc);
      inherited;
    end;
     
    procedure TPrintPDF.DrawImage(aFileName: TFileName; X, Y, W, H: HPDF_REAL);
    var
      Image :HPDF_Image;
    begin
      case AnsiIndexText(ExtractFileExt(aFileName), ['.png', '.jpg']) of
        0 : image := HPDF_LoadPngImageFromFile(Doc, PAnsiChar(aFileName));
        1 : image := HPDF_LoadJpegImageFromFile(Doc, PAnsiChar(aFileName));
      end;
     
      HPDF_Page_DrawImage (page, image, X, PageSize.Y -Y -H, W, H);
    end;
     
    function TPrintPDF.GetCurPos: THPDF_Point;
    begin
      Result.X  := FCurPos.X;
      Result.Y := HPDF_Page_GetHeight(page) -FCurPos.Y;
    end;
     
    function TPrintPDF.GetFontSize: HPDF_REAL;
    begin
      Result := HPDF_Page_GetCurrentFontSize(page);
    end;
     
    function TPrintPDF.GetInnerPageSize: THPDF_Point;
    begin
      Result.x := PageSize.x -Margins.left -Margins.right;
      Result.y := PageSize.y -Margins.Top -Margins.Bottom;
    end;
     
    function TPrintPDF.GetPageSize: THPDF_Point;
    begin
      Result.x := HPDF_Page_GetWidth(page);
      Result.y := HPDF_Page_GetHeight(page);
    end;
     
    procedure TPrintPDF.IncCurPosX(aValue: HPDF_REAL);
    begin
      FCurPos.X := FCurPos.X +aValue;
    end;
     
    procedure TPrintPDF.IncCurPosY(aValue: HPDF_REAL);
    begin
      FCurPos.Y := FCurPos.Y -aValue;
    end;
     
    procedure TPrintPDF.NewPage;
    var
      Ofs :HPDF_REAL;
    begin
      page := HPDF_AddPage(Doc);
      HPDF_Page_SetSize(Page, HPDF_PAGE_SIZE_A4, HPDF_PAGE_PORTRAIT);
      FCurPos.X := Margins.Left;
     
      if IsZero(HPDF_Page_GetCurrentFontSize(page), 0.01)
      then Ofs := DefaultFontSize
      else Ofs := HPDF_Page_GetCurrentFontSize(page);
     
      FCurPos.Y := HPDF_Page_GetHeight(page) -Margins.Top -Ofs;
    end;
     
    procedure TPrintPDF.Rectangle(aLeft, aTop, aWidth, aHeight :HPDF_REAL;
                                  aLineWidth: HPDF_REAL; aLineColor, aFillColor: TColor);
    var
      R,G,B :byte;
    begin
      HPDF_Page_SetLineWidth (page, aLineWidth);
     
      R := aLineColor and $FF;
      G := (aLineColor shr 8) and $FF;
      B := (aLineColor shr 16) and $FF;
      HPDF_Page_SetRGBStroke (page, R/255, G/255, B/255);
     
      R := aLineColor and $FF;
      G := (aLineColor shr 8) and $FF;
      B := (aLineColor shr 16) and $FF;
      HPDF_Page_SetRGBFill (page, R/255, G/255, B/255);
     
      HPDF_Page_Rectangle(page, aleft, HPDF_Page_GetHeight(page) -aTop +FontSize, aWidth, -aHeight);
    //  HPDF_Page_Rectangle(page, aleft, aTop +FontSize, aWidth, -aHeight);
      HPDF_Page_Stroke(page);
    end;
     
    procedure TPrintPDF.SaveToFile(aFileName: TFileName);
    begin
      HPDF_SaveToFile(Doc, PAnsiChar(aFileName));
    end;
     
    procedure TPrintPDF.SelectFont(aIndex: integer);
    begin
      aIndex := EnsureRange(aIndex, 0, High(aIndex));
      font := HPDF_GetFont(Doc, PChar(FFonts[aIndex].Name), 'WinAnsiEncoding');
      HPDF_Page_SetFontAndSize(page, font, FFonts[aIndex].Size);
    end;
     
    procedure TPrintPDF.SetAuthor(const Value: string);
    begin
      FAuthor := Value;
      HPDF_SetInfoAttr(Doc, HPDF_INFO_AUTHOR, PAnsiChar(FAuthor));
    end;
     
    procedure TPrintPDF.SetCreator(const Value: string);
    begin
      FCreator := Value;
      HPDF_SetInfoAttr(Doc, HPDF_INFO_CREATOR, PAnsiChar(FCreator));
    end;
     
    procedure TPrintPDF.SetCurPos(const Value: THPDF_Point);
    begin
      FCurPos.X := Value.X;
      FCurPos.Y := HPDF_Page_GetHeight(page) -Value.Y;
    end;
     
    procedure TPrintPDF.SetKeywords(const Value: string);
    begin
      FKeywords := Value;
      HPDF_SetInfoAttr(Doc, HPDF_INFO_KEYWORDS, PAnsiChar(FKeywords));
    end;
     
    procedure TPrintPDF.SetMargins(const Value: THPDF_Rect);
    begin
      FMargins := Value;
      CurPos := Pointmm(Max(CurPos.X, FMargins.Left), Max(CurPos.Y, FMargins.Top));
    end;
     
    procedure TPrintPDF.SetSubject(const Value: string);
    begin
      FSubject := Value;
      HPDF_SetInfoAttr(Doc, HPDF_INFO_SUBJECT, PAnsiChar(FSubject));
    end;
     
    procedure TPrintPDF.SetTitle(const Value: string);
    begin
      FTitle := Value;
      HPDF_SetInfoAttr(Doc, HPDF_INFO_TITLE, PAnsiChar(FTitle));
    end;
     
    procedure TPrintPDF.TextOut(X, Y: HPDF_REAL; aText: string; aFontIndex: integer);
    var
      OldCurPos :THPDF_Point;
    begin
      OldCurPos := CurPos;
      CurPos := Pointmm(X, Y);
      Write(aText, aFontIndex);
      CurPos := OldCurPos;
    end;
     
    function TPrintPDF.TextWidth(aText: string): HPDF_REAL;
    begin
      Result := HPDF_Page_TextWidth(page, PAnsiChar(aText));
    end;
     
    procedure TPrintPDF.Write(aText: string; aFontIndex: integer);
    begin
      if aFontIndex > -1 then
        SelectFont(aFontIndex);
     
      HPDF_Page_BeginText(page);
      HPDF_Page_TextOut(page, FCurPos.X, FCurPos.Y, PAnsiChar(aText));
      HPDF_Page_EndText (page);
    end;
     
    procedure TPrintPDF.WriteLn(aText :string; aFontIndex :integer);
    begin
      Write(aText, aFontIndex);
      IncCurPosY(HPDF_Page_GetCurrentFontSize(page));
    end;
     
    procedure TPrintPDF.WriteLink(aText, aURL: string);
    var
      Rect  :THPDF_Rect;
      Annot :HPDF_Annotation;
    begin
      Rect.Left   := FCurPos.X;
      Rect.top    := FCurPos.Y +HPDF_Page_GetCurrentFontSize(page);
      Rect.Right  := Rect.Left +TextWidth(aText); //HPDF_Page_TextWidth(page, PAnsiChar(aText));
      Rect.Bottom := FCurPos.Y -3;
     
      Write(aText);
      Annot := HPDF_Page_CreateURILinkAnnot(page, Rect, PAnsiChar(aURL));
      HPDF_LinkAnnot_SetBorderStyle (annot, 0, 0, 0);
    end;
     
    procedure TPrintPDF.WriteLinkLn(aText, aURL: string);
    begin
      WriteLink(aText, aURL);
      IncCurPosY(HPDF_Page_GetCurrentFontSize(page));
    end;
     
    end.
    Ensuite:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    const
      TextFont  = 0;
      BoldFont  = 1;
      SmallFont = 2;
      TitleFont = 3;
     
    begin
      with TPrintPDF.Create do
      begin
        Title    := ...;
        Author   := ...;
        Subject  := ...;
        Keywords := ...;
     
        //Pour plusieurs police (Voir constantes ci-dessus)
        AddFont('Helvetica-Bold', 10);  //1
        AddFont('Helvetica', 8);        //2
        AddFont('Helvetica-Bold', 18);  //3
     
        //Dessin d'une image
        DrawImage('MonImage.png', PageSize.x -150, 10, 140, 43.10);
     
        //Texte positionné. (La police définie sera utilisée jusqu'à réassignation)
        TextOut(PageSize.x -170, PageSize.Y -90, 'xxxx', SmallFont);
        TextOut(PageSize.x -170, PageSize.Y -80, 'xxxx');
     
        Margins := Rectmm(40, 40, 40, 40);
     
        //Ecrit un texte et saut de ligne. (La police définie sera utilisée jusqu'à réassignation)
        WriteLn('xxxx', TextFont);
        WriteLn('xxxx');
     
        //Ecriture d'un lien (mail ou www)
        WriteLinkLn('info@xxxx.com', 'mailto:info@xxxx.com');
     
        //CurPos contient la position du curseur. X est concervé jusqu'à réassignation (Indentation)
        IncCurPosX(100);
        WriteLn('xxxx', SmallFont);
     
        SaveToFile(FileName);
        end;
     
        Free;
      end;
    end;
    Si ça peux te simplifier la vie .

  20. #20
    Membre chevronné
    Avatar de Droïde Système7
    Homme Profil pro
    Inscrit en
    Septembre 2003
    Messages
    2 262
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Septembre 2003
    Messages : 2 262
    Points : 1 928
    Points
    1 928
    Par défaut
    Si ça peux te simplifier la vie
    Tu m'étonnes !

    Faut que je regarde tout ça à tête reposée, car là c'est l'avalanche

    Bon, j'ai regardé en vitesse et lu en travers, j'ai vu une méthode TPrintPDF.SaveToFile, mais pas une en Load...

    Peut-être est-ce la méthode "TextOut(...)", mais à tête reposée
    Ou plutôt :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     //Ecrit un texte et saut de ligne. (La police définie sera utilisée jusqu'à réassignation)
        WriteLn('xxxx', TextFont);
        WriteLn('xxxx');
    Mais faut que j'me calme et regarde et teste tout ça tranquillement.

    J'espère taguer très vite en "Résolu"

    Encore

    @+

Discussions similaires

  1. Composant pour gérer les fichiers PDF
    Par BXDSPORT dans le forum Delphi
    Réponses: 4
    Dernier message: 27/05/2007, 08h53
  2. Réponses: 6
    Dernier message: 02/04/2007, 16h34
  3. Meilleure solution pour création PDF
    Par chouchou93 dans le forum Documents
    Réponses: 10
    Dernier message: 09/03/2007, 11h38
  4. composant pour PDF
    Par thebeb dans le forum VC++ .NET
    Réponses: 7
    Dernier message: 25/10/2006, 10h31
  5. [delphi 7] composant pour afficher des pdf ?
    Par PhD13 dans le forum Composants VCL
    Réponses: 6
    Dernier message: 06/03/2006, 17h40

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo