Manupulate PDF via Acrobat PRO DC

Re: Manupulate PDF via Acrobat PRO DC

Postby mastintin » Fri Dec 24, 2021 9:02 pm

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.
User avatar
mastintin
 
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: Manupulate PDF via Acrobat PRO DC

Postby mastintin » Sat Dec 25, 2021 11:55 am

This Sample work for me ....

Code: Select all  Expand view  RUN


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

//------------------------------------------------------------------------------

User avatar
mastintin
 
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: Manupulate PDF via Acrobat PRO DC

Postby Marc Vanzegbroeck » Sat Dec 25, 2021 10:21 pm

Thank you very much!!

Is's working very nice.

Merry Christmas
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: Manupulate PDF via Acrobat PRO DC

Postby Marc Vanzegbroeck » Sun Dec 26, 2021 12:50 pm

Hi,

A little question.

Now I'm using a program 'PDFtoTxt' to extract text from a pdf, but us it also possible with the Acrobat DC.

I see in an example that you made before something like

Code: Select all  Expand view  RUN
resultadoHilitelist = pagHilitelist:Add(0, 9000)

  pagActual = pagPDF:CreatePageHilite(pagHilitelist)

  For i = 0 To pagActual:GetNumText() - 1

      datosPDF = datosPDF + pagActual:GetText(i)

  Next

  msginfo( datospdf )
 


What exectly is pagHilitelist:Add(0, 9000)? Are those the coordinates?

On my pages, the name is always on the same location on the paper.
Is it possible with this?

Image

It's the text 'F2001_3' that I need
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: Manupulate PDF via Acrobat PRO DC

Postby mastintin » Mon Dec 27, 2021 10:32 am

Marc Vanzegbroeck wrote:What exectly is pagHilitelist:Add(0, 9000)? Are those the coordinates?

Is the number of word to collect ...
pagHilitelist:Add(0, 9000) collect the first word to word 9000 . if use Add( 0,10 ) Hilite the first 10 word , if use add( 10,20 ) Hilite the word nomber 11 to 19 , ( first word is 0 ) . if your page has many words change to add( 0, 18000 ).
In the Web are multiple implementations different, some use the js object, but in essence they do the same.
https://www.vbforums.com/showthread.php ... ext-in-pdf in the 4 and 8 comment have complete methods in VB easy to switch to Harbour.
Last edited by mastintin on Mon Dec 27, 2021 10:36 am, edited 1 time in total.
User avatar
mastintin
 
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: Manupulate PDF via Acrobat PRO DC

Postby Marc Vanzegbroeck » Mon Dec 27, 2021 10:36 am

Thank you for the info.
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: Manupulate PDF via Acrobat PRO DC

Postby Marc Vanzegbroeck » Wed Jan 05, 2022 9:41 am

Hi,

It's working very nice.

Just one question. The program is doing everything without showing the PDF while working, except in the 'merge' routine.
Then Acrobat is shown, and you can see the program manipulating it. Is is possible toe hide this also, because sometimes an error occur when the user click the mouse on the PDF.

While debugging, I found the place where it shows Acrobat.
This is the part of the mergemultipdf() function.
It's very strange, because on other places in the program the same function is used, without showing the Acrobat.

I moved 1 line, because the program inserted the files always on the second page, instead adding it at the end.

Code: Select all  Expand view  RUN

 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 )
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: Manupulate PDF via Acrobat PRO DC

Postby Marc Vanzegbroeck » Thu Jan 06, 2022 9:39 am

I found the way to hide it :)

With
Code: Select all  Expand view  RUN
app:Hide()
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: Manupulate PDF via Acrobat PRO DC

Postby goosfancito » Fri Dec 15, 2023 11:05 am

MANUEL

necesito contactarme con vos. podes escribirme? gracias

gusmavf arroba gmail punto com

gracias
FWH 21.02
Harbour 3.2.0dev (r2104281802)
Copyright (c) 1999-2021, https://harbour.github.io/
User avatar
goosfancito
 
Posts: 1954
Joined: Fri Oct 07, 2005 7:08 pm

Previous

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 60 guests