martedì 25 marzo 2014

unisci Fdf a Pdf - vbs

'

'

' vbs - unisce i valori contenuti in un file Fdf

' nel file Pdf editabile contenente i relativi campi.

'

Option explicit

'

Dim objA

Set objA = Wscript.Arguments

if objA.count = 0 Then

Wscript.Echo "Servono almeno due file: uno pdf e uno fdf"

Wscript.Quit

End If

'

Dim objFSO

Set objFSO = CreateObject("Scripting.FileSystemObject")

'

dim quantifile, contali, nomefile, filepdf, suffisso

quantifile = objA.count - 1

' ricerca il file pdf

for contali = 0 to quantifile

nomefile = trim(obja(contali))

suffisso = lcase(objFSO.GetExtensionName(nomefile))

if suffisso = "pdf" then

filepdf = nomefile

end if

next

'

' ricerca i fle fdf

for contali = 0 to quantifile

nomefile = trim(obja(contali))

suffisso = lcase(objFSO.GetExtensionName(nomefile))

if suffisso = "fdf" then

call stampapdf(nomefile) ' stampa i file unisce fdf a pdf

call muovifile(nomefile) ' il file pdf generato assume il nome del file fdf

end if

next

'

' ===

sub muovifile(pnomefile)

Dim objFSO, origine, destinazione

Set objFSO = CreateObject("Scripting.FileSystemObject")

'

origine = "C:\pdf\770ED.pdf" ' file Pdf con i campi da compilare

destinazione = "C:\pdf\" & objFSO.GetBaseName(pnomefile) & ".pdf" ' nome file Fdf senza suffisso

'

objFSO.MoveFile origine, destinazione



end sub

' =====

sub stampapdf(strPDFpath)

'

Dim objPrinter, stampantepredefinita

Set objPrinter = CreateObject("WScript.Network")

objPrinter.SetDefaultPrinter "PDFCreator" ' assegna la stampante pdf come predefinita

'

Dim wsh, esegui, attesa

Set wsh = CreateObject("WScript.Shell")

'

'esegui = "acrord32.exe /p /h """ & strPDFpath

esegui = "acrord32.exe /t /h """ & strPDFpath

'attesa = wsh.Run (esegui, 1, true) ' nel caso si voglia chiudere manualmente il file pdf

wsh.Run esegui

'

WScript.Sleep 15000 ' attende 15 secondi prima di terminare Adobe

'

objPrinter.SetDefaultPrinter "AMMINISTRA" ' ripristina la stampante predefinita

'

dim strComputer, objWMIService, colProcessList, objProcess

strComputer = "."

Set objWMIService = GetObject ("winmgmts:\\" & strComputer & "\root\cimv2")

Set colProcessList = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = 'acrord32.exe'")

For Each objProcess in colProcessList

objProcess.Terminate()

Next

'

end sub

' =================

Nessun commento:

Posta un commento