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

 Delphi Discussion :

Screenshot en .jpg du format .pdf et TWebbrowser


Sujet :

Delphi

  1. #1
    Membre expérimenté
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    2 426
    Détails du profil
    Informations personnelles :
    Âge : 71
    Localisation : Belgique

    Informations forums :
    Inscription : Janvier 2006
    Messages : 2 426
    Points : 1 326
    Points
    1 326
    Par défaut Screenshot en .jpg du format .pdf et TWebbrowser
    Bonjour à toutes et à tous,

    Sous D6, j'utilise le composant TWebBrowser et j'affiche soit une page Web soit un fichier .pdf.

    J'aimerai pouvoir faire un Screenshot de la page .pdf, mais problème de page blanche dans le résultat.

    Par contre, avec ce code et avec une page web cela fonctionne !

    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
     
    procedure WebBrowserScreenShot(const wb: TWebBrowser; const fileName: TFileName) ;
     var
       viewObject : IViewObject;
       r : TRect;
       bitmap : TBitmap;
     begin
       if wb.Document <> nil then
       begin
         wb.Document.QueryInterface(IViewObject, viewObject) ;
         if Assigned(viewObject) then
         try
           bitmap := TBitmap.Create;
           try
             r := Rect(0, 0, wb.Width, wb.Height) ;
     
             bitmap.Height := wb.Height;
             bitmap.Width := wb.Width;
     
             viewObject.Draw(DVASPECT_CONTENT, 1, nil, nil, Application.Handle, bitmap.Canvas.Handle, @r, nil, nil, 0) ;
     
             with TJPEGImage.Create do
             try
               Assign(bitmap) ;
               SaveToFile(fileName) ;
             finally
               Free;
             end;
           finally
             bitmap.Free;
           end;
         finally
           viewObject._Release;
         end;
       end;
     end;

    Usage :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    procedure TForm1.Button4Click(Sender: TObject);
    begin
    WebBrowserScreenShot(WebBrowser1, chappli +'test.jpg') ;
    end;
    Si quelqu'un a une solution, merci d'avance, à mon avis peut être une différence de format entre un fichier .pdf et .html.


    Quant à l'affichage pour le fichier .pdf, la commande "ctrl + L" permet d'obtenir la page entière, je n'ai pas réussi à le faire avec le code de l'event clavier peut être à cause du focus de la page.

    @+,

    cincap

  2. #2
    Membre expérimenté
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    2 426
    Détails du profil
    Informations personnelles :
    Âge : 71
    Localisation : Belgique

    Informations forums :
    Inscription : Janvier 2006
    Messages : 2 426
    Points : 1 326
    Points
    1 326
    Par défaut
    Bonjour à toutes et à tous,

    Apparemment personne n'a d'idée du comment faire !

    Ceci dit voici un exemple de code console pour D7 qui pourra peut être être modifié pour D6 :

    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
     
    ////////////////////////////////////////////////////////////////////////////////////
    // This example was designed to be used in Delphi 7 or higher.
    //
    // 1. Adobe Acrobat version 4.0 or higher should be installed and activated on your PC.
    //    Adobe Acrobat Reader does not have COM interface and cannot be used as COM-server
    //
    // 2. Universal Document Converter version 5.2 or higher should be installed as well
    //
    // 3. Add Universal Document Converter Type Library and
    //    Adobe Acrobat XX.0 Type Library type libraries to the project.
    //    XX is the Adobe Acrobat version installed on your computer.
    //
    //    Delphi 7:
    //      Use the Project | Import Type Library menu.
    //
    //    Delphi 2006 or latter:
    //      Use the Component | Import Component menu.
    //
    //    Clear the Generate Component Wrapper checkbox and click the Create Unit
    //    button (Delphi 7) or select the Create Unit option (Delphi 2006 or latter).
    //
    ////////////////////////////////////////////////////////////////////////////////////
     
    program PDFToJPEG;
     
    {$APPTYPE CONSOLE}
     
    uses
      SysUtils,
      Variants,
      Windows,
      Dialogs,
      ActiveX,
      ComObj,
      UDC_TLB,
      Acrobat_TLB;
     
      procedure PrintPDFtoJPEG(PDFFilePath: string);
      var
        objUDC: IUDC;
        Printer: IUDCPrinter;
        Profile: IProfile;
        AcroApp: Variant;
        AVDoc: Variant;
        PDDoc: Variant;
        nPages: Integer;
        nPSLevel, bBinaryOk, bShrinkToFit, bNoSave: Integer;
      begin
        //Create a UDC object and get its interfaces
        objUDC := CoAPIWrapper.Create;
        Printer := objUDC.get_Printers('Universal Document Converter');
        Profile := Printer.Profile;
     
        //Adobe Acrobat API allow to print only on the default printer
        objUDC.DefaultPrinter := 'Universal Document Converter';
     
        //Use Universal Document Converter API to change settings of converterd document
     
        //Load profile located in folder "%APPDATA%\UDC Profiles".
        //Value of %APPDATA% variable should be received using Windows API's
        // SHGetSpecialFolderPath or JCL's JclSysInfo.GetAppdataFolder function.
        //Or you can move default profiles into a folder you prefer.
        Profile.Load('PDF to JPEG.xml');    
     
        Profile.OutputLocation.Mode := LM_PREDEFINED;
        Profile.OutputLocation.FolderPath := 'c:\UDC Output Files';
     
        Profile.PostProcessing.Mode := PP_OPEN_FOLDER;
     
        AcroApp := CreateOleObject('AcroExch.App');
        AVDoc := AcroApp.GetActiveDoc;
     
        //Open PDF document from file
        AVDoc.Open(PDFFilePath, '');
        PDDoc := AVDoc.GetPDDoc;
     
        nPages := PDDoc.GetNumPages;
     
        //Print all pages of the document
        nPSLevel := 0;
        bBinaryOk := 1; //true
        bShrinkToFit := 1; //true
        AVDoc.PrintPagesSilent(0, nPages - 1, nPSLevel, bBinaryOk, bShrinkToFit);
     
        //Close the document
        bNoSave := 1;
        AVDoc.Close(bNoSave);
     
        //Close Acrobat
        AcroApp.Exit;
      end;
     
    var
      TestFilePath: string;
    begin
      TestFilePath := ExtractFilePath(ParamStr(0)) + 'carrefour-family-day-4140.pdf';
      try
        CoInitialize(nil);
        try
          PrintPDFtoJPEG(TestFilePath);
        finally
          CoUninitialize;
        end;
      except
        on E: Exception do
          MessageDlg(E.ClassName + ' : ' + E.Message, mtError, [mbOK], 0);
      end;
    end.
    @+,

    cincap

Discussions similaires

  1. dll pour Extraire des pages au format jpg d'un pdf
    Par toniob44 dans le forum VB.NET
    Réponses: 0
    Dernier message: 06/06/2012, 20h28
  2. Réponses: 3
    Dernier message: 20/09/2004, 09h00
  3. [Rave5] format PDF ...
    Par Djedjeridoo dans le forum Rave
    Réponses: 2
    Dernier message: 09/06/2004, 09h25
  4. exportation en format pdf
    Par nounou dans le forum Access
    Réponses: 6
    Dernier message: 10/12/2003, 14h22

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