Problème interaction avec Acrobat Pro

Chers amis,

Je suis nouveau sur le forum et je fais face à un gros casse-tête.

Avec le code VBA (rédigé ci-dessous), je désire simplement ouvrir des fichiers PDFs et inscrire les dimensions des pages dans une feuille Excel. Pour information, j'ai Excel 2019 et Acrobat Pro 2017, mais j'ai également essayé avec d'autres versions.

Malheureusement, bien qu'ayant les librairies Acrobat activées dans les références, tous les objets Acrobat de classe AcroPDPage ne fonctionnent pas. Je ne parviens pas à invoquer les membres de AcroPDPage (exemple : GetSize etc.) et j'ai des erreurs à répétition lors de l'exécution de mon code. Bizarrement, tout ce qui relève de la classe AcroPDDoc fonctionne.

Est-ce que l'un d'entre vous aurait une idée concernant cette problématique ?

Sub GetPDFSize()

Dim AcroApp As Object
Dim AcroAVDoc As Object
Dim AcroPDDoc As Object
Dim AcroPage As Object
Dim PageCount As Integer
Dim i As Integer

'Create an instance of Adobe Acrobat
Set AcroApp = CreateObject("AcroExch.App")

'Open the PDF file
Set AcroAVDoc = CreateObject("AcroExch.AVDoc")
If AcroAVDoc.Open("C:\SCAN\test3.pdf", "") Then
    Set AcroPDDoc = AcroAVDoc.GetPDDoc
End If

'Get the number of pages in the PDF
PageCount = AcroPDDoc.GetNumPages

'Loop through each page
For i = 0 To PageCount - 1
    'Get the page object
    Set AcroPage = AcroPDDoc.AcquirePage(i)

    'Get the size of the page
    Dim PageWidth As Double
    Dim PageHeight As Double
    PageWidth = AcroPage.GetSize.Width
    PageHeight = AcroPage.GetSize.Height

    'Write the page size to the Excel sheet
    Range("A" & i + 1) = PageWidth
    Range("B" & i + 1) = PageHeight

    'Release the page object
    Set AcroPage = Nothing
Next i

'Close the PDF file
AcroAVDoc.Close True

'Release the objects
Set AcroPDDoc = Nothing
Set AcroAVDoc = Nothing
Set AcroApp = Nothing

End Sub

Merci beaucoup d'avance pour votre aide !

Bonjour,

J'essaierai ce code (non testé) :

    'Open the PDF file
    Set AcroAVDoc = CreateObject("AcroExch.AVDoc")
    If AcroAVDoc.Open("C:\SCAN\test3.pdf", "") Then
        Set AcroPDDoc = AcroAVDoc.GetPDDoc
        Set AcroAVPageView = AcroAVDoc.GetAVPageView
    End If

    'Get the number of pages in the PDF
    PageCount = AcroPDDoc.GetNumPages

    'Loop through each page
    For i = 0 To PageCount - 1
        'Get the page object
        AcroAVPageView.Goto i
        Set AcroPage = AcroAVPageView.GetPage

Merci beaucoup pour votre réponse.

Malheureusement, cela fait toujours une erreur sur cette ligne

  PageWidth = AcroPage.GetSize.Width

Il semble que ce soit vraiment cet objet (GetSize), ainsi que tous ceux associés à AcroPDPage, qui ne s'ouvrent pas.

Pourtant, la Library Acrobat est bien cochée dans les références. C'est vraiment difficile à comprendre.

Cette propriété n'existe pas :

PageWidth = AcroPage.GetSize.Width

Ce serait plutôt :

        'Get the size of the page
        Dim PageX As Single
        Dim PageY As Single
        Set AcroPoint = AcroPage.GetSize

        PageX = AcroPoint.X
        PageY = AcroPoint.Y

        'Write the page size to the Excel sheet
        Range("A" & i + 1).Left = PageX
        Range("B" & i + 1).Top = PageY

Cela fonctionne parfaitement.
Un très grand merci pour votre aide .

Rechercher des sujets similaires à "probleme interaction acrobat pro"