Page 1 of 1
Manupulate PDF via Acrobat PRO DC
Posted: Tue Dec 21, 2021 3:18 pm
by Marc Vanzegbroeck
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
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.
Re: Manupulate PDF via Acrobat PRO DC
Posted: Tue Dec 21, 2021 3:40 pm
by Antonio Linares
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
Re: Manupulate PDF via Acrobat PRO DC
Posted: Thu Dec 23, 2021 8:47 am
by Marc Vanzegbroeck
Hi Antonio,
Did you manage to contact Manuel Alvarez?
Re: Manupulate PDF via Acrobat PRO DC
Posted: Thu Dec 23, 2021 9:27 am
by mastintin
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.pdfIf 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.
Re: Manupulate PDF via Acrobat PRO DC
Posted: Thu Dec 23, 2021 10:20 am
by Marc Vanzegbroeck
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.
Re: Manupulate PDF via Acrobat PRO DC
Posted: Thu Dec 23, 2021 3:47 pm
by Marc Vanzegbroeck
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
Re: Manupulate PDF via Acrobat PRO DC
Posted: Thu Dec 23, 2021 10:20 pm
by mastintin
Mark ...
to split pages ...
Code: Select all | Expand
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
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.
Re: Manupulate PDF via Acrobat PRO DC
Posted: Fri Dec 24, 2021 9:12 am
by Marc Vanzegbroeck
Thank you !!
I will try it, and will you know you the result.
Re: Manupulate PDF via Acrobat PRO DC
Posted: Fri Dec 24, 2021 11:46 am
by Marc Vanzegbroeck
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
Re: Manupulate PDF via Acrobat PRO DC
Posted: Fri Dec 24, 2021 12:43 pm
by mastintin
Mark if you change last parameter to 1 ?
if last parameter is 0 no copy bookmarks , if is positive number it should insert bookmarks.
and in merge ...
Code: Select all | Expand
lOk := opDDoc1:InsertPages( x, OPDDoc2, 0, oPDDoc2:GetNumPages(), 1 )
Report me the result please .
Re: Manupulate PDF via Acrobat PRO DC
Posted: Fri Dec 24, 2021 1:06 pm
by Marc Vanzegbroeck
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.
Re: Manupulate PDF via Acrobat PRO DC
Posted: Fri Dec 24, 2021 2:24 pm
by mastintin
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 ?
Re: Manupulate PDF via Acrobat PRO DC
Posted: Fri Dec 24, 2021 2:29 pm
by Marc Vanzegbroeck
Sorry, same result..
Re: Manupulate PDF via Acrobat PRO DC
Posted: Fri Dec 24, 2021 7:30 pm
by mastintin
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.
Re: Manupulate PDF via Acrobat PRO DC
Posted: Fri Dec 24, 2021 8:13 pm
by Marc Vanzegbroeck
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.