Newsgroup: it.comp.appl.access
Titolo: AttachmentToPDF

È la prima volta che metto le mani sopra un XML
e non mi è piaciuto affatto.
Comunque, grazie al contributo sostanziale di BFS e di Internet,
la procedura salva in un file PDF l'eventuale allegato
(dimensione massima 6Mb) alla fattura elettronica.
 
====================================
Public Sub AttachmentToPDF()
' References:
' Microsoft XML, v6.0
' Microsoft ActiveX Data Object Recordset 6.0 Library
' Microsoft Scripting Runtime
 
Dim Base64Byte() As Byte, B64String As String
Dim xmlDoc, nodeXML, i As Long, TargetFile As String
Dim FSO As New FileSystemObject, XMLFile As String
 
'---  Definizioni  --------------------
XMLFile = "D:\IT02221101203_WGS5.xml"
TargetFile = "D:\BCpdf.pdf"
'--------------------------------------
 
Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.SetProperty "SelectionLanguage", "XPath"
xmlDoc.async = False
xmlDoc.Load (XMLFile)
Set nodeXML = xmlDoc.getElementsByTagName("Attachment")
B64String = nodeXML(0).Text
'MsgBox Len(B64String)
'MsgBox B64String
 
If FSO.FileExists(TargetFile) Then
    Kill TargetFile
End If
 
Const adTypeBinary = 1
GoSub Decoding
With CreateObject("ADODB.Stream")
    .Open
    .Type = adTypeBinary
    .Write Base64Byte
    .SaveToFile TargetFile
    .Close
End With
 
Exit_Sub:
    Exit Sub
 
Decoding:
    Dim objXML As MSXML2.DOMDocument60
    Dim objNode As MSXML2.IXMLDOMElement
    Set objXML = New MSXML2.DOMDocument60
    Set objNode = objXML.createElement("b64")
    objNode.DataType = "bin.base64"
    objNode.Text = B64String
    Base64Byte = objNode.nodeTypedValue
Return
 
End Sub
==========================================
 
Bruno


se però manca l'allegato ti da errore o sbaglio
 
io aggiungerei un
 
Set nodeXML = xmlDoc.getElementsByTagName("Attachment")
If nodeXML .Length > 0 Then
 
'allora leggo...
 
 
ciao
BFS
 
 
---
Questa email è stata esaminata alla ricerca di virus da AVG.
http://www.avg.com
 
 

BFS has brought this to us :

Ok, fatto.
 
======================================
Public Sub AttachmentToPDF()
' References:
' Microsoft XML, v6.0
' Microsoft ActiveX Data Object Recordset 6.0 Library
' Microsoft Scripting Runtime
Dim Base64Byte() As Byte, B64String As String
Dim xmlDoc, nodeXML, i As Long, TargetFile As String
Dim FSO As New FileSystemObject, XMLFile As String
 
'---  Definizioni  --------------------
XMLFile = "D:\IT02221101203_WGS5.xml"
TargetFile = "D:\BCpdf.pdf"
'--------------------------------------
 
Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.SetProperty "SelectionLanguage", "XPath"
xmlDoc.async = False
xmlDoc.Load (XMLFile)
Set nodeXML = xmlDoc.getElementsByTagName("Attachment")
If nodeXML.length = 0 Then
    MsgBox "Nessun Allegato"
    Exit Sub
End If
B64String = nodeXML(0).Text
'MsgBox Len(B64String)
'MsgBox B64String
 
If FSO.FileExists(TargetFile) Then
    Kill TargetFile
End If
 
Const adTypeBinary = 1
GoSub Decoding
With CreateObject("ADODB.Stream")
    .Open
    .Type = adTypeBinary
    .Write Base64Byte
    .SaveToFile TargetFile
    .Close
End With
If FSO.FileExists(TargetFile) Then
    MsgBox "Creato  " & TargetFile
Else
    MsgBox "Qualcosa è andato storto..." & vbCrLf & _
           "Il file  " & TargetFile & "  non è stato creato"
End If
 
Exit_Sub:
    Exit Sub
 
Decoding:
    Dim objXML As MSXML2.DOMDocument60
    Dim objNode As MSXML2.IXMLDOMElement
    Set objXML = New MSXML2.DOMDocument60
    Set objNode = objXML.createElement("b64")
    objNode.DataType = "bin.base64"
    objNode.Text = B64String
    Base64Byte = objNode.nodeTypedValue
Return
 
End Sub
========================================
 
Bruno