Manupulate PDF via Acrobat PRO DC

Manupulate PDF via Acrobat PRO DC

Postby Marc Vanzegbroeck » Tue Dec 21, 2021 3:18 pm

Hi,

I saw in the forum that it is possible to open PDF's with Acrobat PRO DC via FWH and do some stuff.

I found that I can open it with
Code: Select all  Expand view  RUN
LOCAL numPagPDFObj := CreateObject( "acroexch.pddoc" )


Is there an example how I can add bookmarks (first search a field in the page).
So each page have a unique bookmark.

And at the end I want to order the PDF according the bookmarks

Thank you.
Last edited by Marc Vanzegbroeck on Tue Dec 21, 2021 3:56 pm, edited 1 time in total.
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 Antonio Linares » Tue Dec 21, 2021 3:40 pm

Dear Marc,

I have emailed Manuel Alvarez (Mastintin in these forums) as he is our PDFs Master amongst many other areas that he superb control :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42118
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Manupulate PDF via Acrobat PRO DC

Postby Marc Vanzegbroeck » Thu Dec 23, 2021 8:47 am

Hi Antonio,

Did you manage to contact Manuel Alvarez?
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 » Thu Dec 23, 2021 9:27 am

Marc .
From Acrobat sdk guide ( pag.95) :

AcroExch.PDBookmark

A bookmark for a page in a PDF file. This is a creatable interface. Each bookmark has a title that appears on
screen, and an action that specifies what happens when a user clicks on the bookmark.
Bookmarks can either be created interactively by the user through the Acrobat DC application’s user
interface or programmatically generated. The typical action for a user-created bookmark is to move to
another location in the current document, although any action can be specified. It is not possible to create
a bookmark with OLE—only to destroy one.

https://opensource.adobe.com/dc-acrobat ... cguide.pdf

If not posible add bookmarks using OLE .
Other approach....
Use an hash table . search a field in the page , add element to Hash ... Key is your "bookmark" ( i suppose filed search ) and value is page number .
Sort your Hash by key and move pages in pdf ( PDDoc.MovePage ) .
Other option is create new pdf doc an insert pages from source doc in order wanted.
User avatar
mastintin
 
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: Manupulate PDF via Acrobat PRO DC

Postby Marc Vanzegbroeck » Thu Dec 23, 2021 10:20 am

Thank you for the info.

I see that acrobat automatically add bookmarks when you combine different PDF's.
So maybe I can extract each page, and renamed them, sort them, and combine to one PDF. :D
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 Dec 23, 2021 3:47 pm

Hi,

Is there an example to save all the pages to separate files.
I can extract the number op pages.
Now I want to add a loop , and save the pages one by one, but I can't find it.

Also an example how to add a PDF to the current would be nice
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 » Thu Dec 23, 2021 10:20 pm

Mark ...
to split pages ...
Code: Select all  Expand view  RUN


Function SplitPdf( cFilePdf )

   LOCAL newPdf
   LOCAL newFileName
   LOCAL numPaginas
   LOCAL gPDDoc := CreateObject("AcroExch.PDDoc")
   LOCAL i
   local rutaFicheroPDF := IF( hb_IsNil(cFilePdf) , cGetFile( "*.Pdf" ) , cFilePdf )

   LOCAL cpathFile := cFilePath( rutaFicheroPDF )
   local lResultadoApertura := gPDDoc:Open( RutaFicheroPDF )


   // pausa( RutaFicheroPDF  )

   // intentamos abrir el fichero pdf de acrobat

   cpathFile += "\salida\"

   If !HB_DIREXISTS( cpathFile )
      MakeDir( cpathFile )
   ENDIF


  If !lResultadoApertura
    gPDDoc := nil
    gApp :=nil
    MsgInfo( "
Error al intentar abrir el fichero pdf indicado. " + ;
        "
Puede que no sea un PDF de adobe o que el " + ;
        "
fichero esté corrupto." )
    Return .f.
  EndIf

  numPaginas = gPDDoc:GetNumPages()

  For i = 0 To numPaginas - 1
       newPDF = CreateObject("
AcroExch.pdDoc")
       newPDF:Create()
       newFileName := cPathFile+ cFileNoExt( cFilenoPath( rutaFicheroPdf ) ) +"
_"+AllTrim(Str(i))+".pdf"
       newPDF:InsertPages(-1, gPDDoc, i, 1, 0 )
       newPDF:Save( 1, NewFileName )
       newPDF:Close()
       newPDF = nil
  next

  gPDDoc := nil

  MsgInfo( "
Extracción completada")

RETURN .t.



to merge 2 pdf

Code: Select all  Expand view  RUN

Function MergePdf(cEntra1, cEntra2, cSalida ,lShow )

local app := CreateObject("AcroExch.App")

local oAVDoc1 := CreateObject("AcroExch.AVDoc")
local oAVDoc2 := CreateObject("AcroExch.AVDoc")

LOCAL  lOk

local oPDDoc1 := CreateObject("AcroExch.PDDoc")
local oPDDoc2 := CreateObject("AcroExch.PDDoc")
local x

DEFAULT lShow := .F.

 lOk = oAVDoc1:Open(cEntra1, "")

 IF !lOk
     MsgInfo("error al abrir "+ cEntra1 +" pdf" )
     RETURN .f.
 ENDIF


 lOk := oAVDoc2:Open(cEntra2, "")
 IF !lOk
     MsgInfo("error al abrir "+ cEntra2 +" pdf" )
     RETURN .f.
 ENDIF

 // app:hide()

 oPDDoc1 = oAVDoc1:GetPDDoc()
 oPDDoc2 = oAVDoc2:GetPDDoc()

 X = oPDDoc1:GetNumPages() - 1

lOk := opDDoc1:InsertPages( x, OPDDoc2, 0, oPDDoc2:GetNumPages(), 0 )

 IF !lOk
     MsgInfo("Se no pudo insertar el documento "+ cEntra2 +"en " +cEntra1 )
     RETURN .f.
 ENDIF

 lOk := opDDoc1:Save( 1, cSalida )

 IF !lOk
     MsgInfo("Se no pudo Grabar "+ cSalida )
     RETURN .f.
 ENDIF

opDDoc1:Close()
opDDoc2:Close()

opddoc1:= nil
opddoc2:= nil

oAVDoc1:Close(1)
oAVDoc2:Close(1)

app:CloseAllDocs()

app:Exit()

IF lshow
   IF File(cSalida)
      Shellexecute(nil,"open",cSalida )
   endif
endif

Return nil

Adapt this functions for your work.

Regards.


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

Re: Manupulate PDF via Acrobat PRO DC

Postby Marc Vanzegbroeck » Fri Dec 24, 2021 9:12 am

Thank you !!

I will try it, and will you know you the result.
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 » Fri Dec 24, 2021 11:46 am

mastintin,

It's working very nice.

The only difference is that when you combine PDF's via Acrobat DC via the program, each PAGE have a boormark with the PDF-name, with the program there are no bookmarks
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 » Fri Dec 24, 2021 12:43 pm

Mark if you change last parameter to 1 ?
if last parameter is 0 no copy bookmarks , if is positive number it should insert bookmarks.

Code: Select all  Expand view  RUN

 newPDF:InsertPages(-1, gPDDoc, i, 1, 1 )
 

and in merge ...
Code: Select all  Expand view  RUN

lOk := opDDoc1:InsertPages( x, OPDDoc2, 0, oPDDoc2:GetNumPages(), 1 )
 

Report me the result please .
User avatar
mastintin
 
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: Manupulate PDF via Acrobat PRO DC

Postby Marc Vanzegbroeck » Fri Dec 24, 2021 1:06 pm

Unfortunately it doesn't work. It add the existing bookmarks from the separate PDF's, but it doesn't create new ones for each page/pdf.
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 » Fri Dec 24, 2021 2:24 pm

Marc Vanzegbroeck wrote:Unfortunately it doesn't work. It add the existing bookmarks from the separate PDF's, but it doesn't create new ones for each page/pdf.

if use .t. instead 1 ?
User avatar
mastintin
 
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: Manupulate PDF via Acrobat PRO DC

Postby Marc Vanzegbroeck » Fri Dec 24, 2021 2:29 pm

Sorry, same result..
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 » Fri Dec 24, 2021 7:30 pm

Ok. Focus shift ...
Does your bookmark link to the pages?
I have managed to put the bookmarks a posteriori, passing the name in an array ...
{ "page_1", "name in pag 2", "pag. order3" }

I think it would also be possible to read the names of the bookmarks of the individual pdfs to generate the array.
Feliz Natal.
Regards.
User avatar
mastintin
 
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: Manupulate PDF via Acrobat PRO DC

Postby Marc Vanzegbroeck » Fri Dec 24, 2021 8:13 pm

Yes,

Each page has his own bookmark.

After I generate the seperate pages (TEST_0.pdf,TEST_1.pdf,...), I rename the file to its correct name, then I read the directory with the files, sort them, and merge the files.

So, I have an array with the file-names, that are also the bookmarks.


mastintin wrote:Ok. Focus shift ...
Does your bookmark link to the pages?
I have managed to put the bookmarks a posteriori, passing the name in an array ...
{ "page_1", "name in pag 2", "pag. order3" }

I think it would also be possible to read the names of the bookmarks of the individual pdfs to generate the array.
Feliz Natal.
Regards.
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

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: PabloHarbour and 75 guests