ok.
Then the initial generation will work, and afterwards we will add a bookmark consecutively with the names that lead to each sheet of pdf file, from array namers.
Function Main()
local aPdf := {}
local cPathFiles
local aBookMarks := { "Master_0", "Master_1" }
local i
local cMaster
cPathFiles := "c:\fwh\samples\salida\"
cMaster := cPathFiles + "Master.pdf"
for i = 1 to len( abookMarks )
aadd( aPdf , cPathFiles+ aBookMarks[i]+".pdf" )
next
MergeMultiPdf( aPdf, cMaster ,.t. )
alert( "creado master")
AddPdfBookMarks( cMaster, aBookmarks, cPathFiles +"MasterSal.pdf" , "Indice", .t. )
Return nil
//------------------------------------------
Function AddPdfBookMarks( cPdfIni, aBookmarks, cPdfEnd ,cRootName, lShow )
local app := CreateObject("AcroExch.App")
local oAVDoc1 := CreateObject("AcroExch.AVDoc")
local oPDDoc1 := CreateObject("AcroExch.PDDoc")
LOCAL lOk
local nLenBookMarks
local nLenPages
local nMinLen
local jso, bmr
local arrParents, bkmChildsParent
local cEntra1
local i
DEFAULT lShow := .F.
cPdfIni := IF( hb_IsNil(cPdfIni) , cGetFile( "*.Pdf" ) , cPdfIni )
lOk := oAVDoc1:Open( cPdfIni, "")
IF !lOk
Alert("error al abrir "+ cPdfIni +" pdf" )
RETURN .f.
ENDIf
if Empty( aBookmarks )
Alert("Error no especifica bookmarks " )
RETURN .f.
endif
nLenBookMarks := len( aBookMarks )
oPDDoc1 = oAVDoc1:GetPDDoc()
nLenPages = oPDDoc1:GetNumPages()
nMinLen := Min( nLenPages, nLenBookMarks )
jso := opDDoc1:GetJSObject() // JavaScript Object
bmr = jso:bookmarkRoot() // BookMark Root Object
if !Empty( cRootName ) // if use Root
bmr:createChild( cRootName, "this.pageNum = 0" , 0)
bkmChildsParent := jso:bookmarkRoot:children()[1]
else
bkmChildsParent := bmr
endif
for i = 1 to nMinLen // add pages bookmarks
bkmChildsParent:createchild( aBookmarks[i], "this.pageNum=" +alltrim(str(i-1)),i-1 )
next
if Empty( cPdfEnd )
cPdfEnd := cPdfIni
endif
lOk := opDDoc1:Save( 1, cPdfEnd )
opDDoc1:Close()
opddoc1:= nil
oAVDoc1:Close(1)
oAVDoc1 := nil
app:CloseAllDocs()
app:Exit()
IF !lOk
Alert("Error. Not Save "+ cPdfEnd )
RETURN .f.
ENDIF
IF lshow
IF File(cPdfEnd )
Shellexecute(nil,"open",cPdfEnd )
endif
endif
Return nil
//---------------------------------------------
Function MergeMultiPdf( aPdfIni, cPdfEnd ,lShow )
local app := CreateObject("AcroExch.App")
local oAVDoc1 := CreateObject("AcroExch.AVDoc")
local oAVDoc2 := CreateObject("AcroExch.AVDoc")
local oPDDoc1 := CreateObject("AcroExch.PDDoc")
local oPDDoc2 := CreateObject("AcroExch.PDDoc")
LOCAL lOk
local x
local jso, bmr
local arrParents, bkmChildsParent
local cEntra1, cEntra2
local i
DEFAULT lShow := .F.
if Empty( aPdfIni ) .or. !hb_IsArray( aPdfIni )
Alert( " Error. in Parameter")
return .f.
endif
if len( aPdfIni ) == 1
Alert( " Error. only 1 file in array")
return .f.
endif
cEntra1 := aPdfIni[1]
lOk = oAVDoc1:Open(cEntra1, "")
IF !lOk
MsgInfo("error al abrir "+ cEntra1 +" pdf" )
oAVDoc1 := nil
RETURN .f.
ENDIF
oPDDoc1 = oAVDoc1:GetPDDoc()
X = oPDDoc1:GetNumPages() - 1
for i=2 to len( aPdfIni )
cEntra2:= aPdfIni[i]
lOk := oAVDoc2:Open(cEntra2, "")
IF !lOk
MsgInfo("error al abrir "+ cEntra2 +" pdf" )
RETURN .f.
ENDIF
oPDDoc2 = oAVDoc2:GetPDDoc()
lOk := opDDoc1:InsertPages( x, OPDDoc2, 0, oPDDoc2:GetNumPages(), 0 )
IF !lOk
MsgInfo("Se no pudo insertar el documento "+ cEntra2 +"en " +cEntra1 )
RETURN .f.
ENDIF
opDDoc2:Close()
opddoc2:= nil
oAVDoc2:Close(1)
next
if Empty( cPdfEnd )
cPdfEnd := cEntra1
Endif
lOk := opDDoc1:Save( 1, cPdfEnd )
opDDoc1:Close()
opddoc1:= nil
oAVDoc1:Close(1)
app:CloseAllDocs()
app:Exit()
IF !lOk
MsgInfo("Se no pudo Grabar "+ cPdfEnd )
RETURN .f.
ENDIF
IF lshow
IF File(cPdfEnd)
Shellexecute(nil,"open",cPdfEnd )
endif
endif
Return nil
//------------------------------------------------------------------------------
resultadoHilitelist = pagHilitelist:Add(0, 9000)
pagActual = pagPDF:CreatePageHilite(pagHilitelist)
For i = 0 To pagActual:GetNumText() - 1
datosPDF = datosPDF + pagActual:GetText(i)
Next
msginfo( datospdf )
Marc Vanzegbroeck wrote:What exectly is pagHilitelist:Add(0, 9000)? Are those the coordinates?
IF !lOk
MsgInfo("error al abrir "+ cEntra1 +" pdf" )
oAVDoc1 := nil
RETURN .f.
ENDIF
oPDDoc1 = oAVDoc1:GetPDDoc()
// X = oPDDoc1:GetNumPages() - 1 //Moved this line from here
for i=2 to len( aPdfIni )
X = oPDDoc1:GetNumPages() - 1 //Moved to here
cEntra2:= aPdfIni[i]
lOk := oAVDoc2:Open(cEntra2, "") //Here Acobat is shown
IF !lOk
MsgInfo("error al abrir "+ cEntra2 +" pdf" )
RETURN .f.
ENDIF
oPDDoc2 = oAVDoc2:GetPDDoc()
lOk := opDDoc1:InsertPages( x, OPDDoc2, 0, oPDDoc2:GetNumPages(), 0 )
IF !lOk
MsgInfo("Se no pudo insertar el documento "+ cEntra2 +"en " +cEntra1 )
RETURN .f.
ENDIF
opDDoc2:Close()
opddoc2:= nil
oAVDoc2:Close(1)
next
if Empty( cPdfEnd )
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 38 guests