PDF aus HTML ansprechen

Fragen & Antworten zur Steuerung von 3D Inhalten in PDFs über JavaScript
Rob
Beiträge: 8
Registriert: 04.09.2007, 09:38

PDF aus HTML ansprechen

Beitrag von Rob » 05.09.2007, 14:48

An die 3D-Sachen kommt man auch teilweise dran.
Es funktioniert so wie in dem folgenden Beispiel. An den vielen auskommentierten Zeilen kannst du erkennen was ich so alles ausprobiert habe. Die Stellen markiert mit XXX sind interessant, weil sie eindeutig mit dem 3D-Kram funktionieren. Es hat auch mal geklappt irgendwas and dem "Scene"-Objekt zu ändern. Ich kann den Code aber nichtmehr finden. Es war was wie Gitter einblenden und Gitter ausblenden oder so.

Code: Alles auswählen

Private Sub testJsButton_Click()
    Dim pdfOk As Boolean
    pdfOk = pdfIsLoaded()
    If pdfOk Then
        Dim pdfDoc As Acrobat.CAcroPDDoc
        Set pdfDoc = acroExchAVDoc.GetPDDoc()
        Dim jso As Object
        Set jso = pdfDoc.GetJSObject
        If Not jso Is Nothing Then
        
            ' Alles sieht soweit gut aus
            
            ' Zeige die Console
            jso.console.Show
            'jso.console.Clear
            'jso.console.Println ("Hallo Blah!")
            
            ' hole die erste Seite und finde die Anzahl der Annotations heraus
            Dim pdfPage As Acrobat.CAcroPDPage
            Dim pageNum As Long
            pageNum = 0
            Set pdfPage = pdfDoc.AcquirePage(pageNum)
            Dim annotsNum As Integer
            annotsNum = pdfPage.GetNumAnnots
            Dim annotsNumStr As String
            annotsNumStr = annotsNum
            jso.console.Println (annotsNumStr + " annotations on first page")
            
            ' gebe alle Annotaions der ersten Seite aus
            jso.console.Println ("All Annotations on first page:")
            Dim curAnnotIndex As Integer
            For curAnnotIndex = 0 To annotsNum - 1
                Dim curAnnotIndexStr As String
                curAnnotIndexStr = curAnnotIndex
                Dim pdfAnnot As Acrobat.CAcroPDAnnot
                Set pdfAnnot = pdfPage.GetAnnot(curAnnotIndex)
                jso.console.Println ("i:" + curAnnotIndexStr + " title:" + pdfAnnot.GetTitle)
            Next curAnnotIndex
            jso.console.Println ("")
            
            ' die Annotations aller Seiten mal über das jso ansprechen (funktioniert so nicht hmm...)
            'Dim annots As Variant
            'annots = jso.getAnnots()
            'If IsArray(annots) Then
            '    jso.console.Println ("array with annotations ok")
            'Else
            '    MsgBox ("Konnte keine Annotations finden")
            'End If
            
            ' hole alle 3d Annotation der ersten Seite
            Dim annots3d As Variant
            annots3d = jso.GetAnnots3D(0) ' alle 3d Annotations auf der ersten Seite
            ' überpfüfe ob Rückgabe ein Array ist
            If IsArray(annots3d) Then
                jso.console.Println ("array with 3d-annotations ok")
                Dim annots3dArray() As Variant
                annots3dArray = annots3d
                Dim size As Integer
                Dim uVal As Integer
                Dim lVal As Integer
                uVal = UBound(annots3dArray)
                lVal = LBound(annots3dArray)
                size = uVal - lVal + 1
                Dim sizeStr As String
                sizeStr = size
                jso.console.Println ("found " + sizeStr + " 3d-annotation(s)")
                
                ' wenn eine 3d-annotation gefunden wurde dann...
                If size >= 1 Then
                    Dim annot3d As Object
                    Set annot3d = annots3dArray(lVal)
                    Dim context3d As Object
                    Set context3d = annot3d.context3d ' XXX
                    Dim scene As Object
                    Set scene = context3d.scene ' XXX
                    
                    Dim annot3dName As String
                    annot3dName = annot3d.Name ' XXX
                    jso.console.Println ("name of 3d-annotation " + annot3dName)
                    
                    Dim sceneObjectListNodes As Object
                    Set sceneObjectListNodes = scene.nodes ' XXX
                    
                    If sceneObjectListNodes Is Nothing Then
                        MsgBox ("Konnte keine Nodes in der 3D-Annotation finden")
                    Else
                        Dim nodesNum As Variant
'                        nodesNum = sceneObjectListNodes.Count ' XXX
                        
                    End If
                    
                    Dim commandText As Object
                    Set commandText = jso.getField("commandText")
                    commandText.Value = "test3"
                    
                    Set btn = jso.getField(buttonname)
                    ' Button aktivieren und damit den JavaScript-Code des Buttons ausführen
                    jso.getField(buttonname).SetFocus
                    
                    'Call context3d.setRenderMode("illustration")
                    'Dim srm As PropertyBag
                    'Set srm = context3d.setRenderMode
                    'Call srm("illustration")
                    'srm ("illustration")
                    'Dim truth As Variant
                    
                    'scene.showGrid (truth)
                    
                    
                    'Dim sceneObjectListMeshes As Object
                    'Set sceneObjectListMeshes = scene.meshes
                    
                    'Dim meshCount As Object
                    'Dim meshCount2 As Variant
                    'Dim meshCount3 As Integer
                    
                    'Set meshCount = sceneObjectListMeshes.getCount
                    'meshCount2 = sceneObjectListMeshes.getCount
                    'meshCount3 = sceneObjectListMeshes.getCount
                    
                    'Set meshCount = sceneObjectListMeshes.Count
                    'meshCount2 = sceneObjectListMeshes.Count
                    'meshCount3 = sceneObjectListMeshes.Count
                    
                    
                    'Dim meshCount As Object
                    'Set meshCount =
                    'Dim props As Object
                    'props = sceneObjectListMeshes.getProps
                    
                    'Dim sceneObjectListMaterials As Object
                    'Set sceneObjectListMaterials = scene.materials
                    
                    'Dim meshListProps As Object
                    'Set meshListProps = sceneObjectListMeshes.getProps
                    'Dim meshListSize As Variant
                    'meshListSize = sceneObjectListMeshes.Count
                    
                    'Dim renderOptions As Object
                    'Set renderOptions = scene.defaultRenderOptions
                    'Dim irmfc As Object
                    'Set irmfc = renderOptions.illustrationRenderModeFaceColor
                    'Dim blah As Variant
                    'blah = irmfc.Set(0, 0, 1)
                    
                End If
            Else
                MsgBox ("Konnte keine 3D-Annotations finden")
            End If
            
            ' alter Code von Thomas würde hier auch funktionieren
            ' find button with name and set focus
            #If Comment Then
            Dim buttonname As String
            buttonname = "button4"
            Dim btn As Object
            Set btn = jso.getField(buttonname)
            If Not (btn Is Nothing) Then
                ' Button aktivieren und damit den JavaScript-Code des Buttons ausführen
                jso.getField(buttonname).SetFocus
            End If
            #End If
        Else
            MsgBox ("Konnte kein JSObject erhalten")
        End If
    Else
        MsgBox ("Es ist keine PDF-Datei geladen")
    End If
End Sub
 
Wenn man eine Anwendung auf dem jeweiligen Rechner installieren kann lohnt es sich auch zu überlegen ob man vieleicht ein Plugin schreiben möchte. Die sind um einiges mächtiger. Mit der Materie habe ich mich aber leider noch nicht auseinandergesetzt.

Antworten