Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Merge PDFs
Message
From
30/09/2006 11:00:51
 
General information
Forum:
Visual FoxPro
Category:
ActiveX controls in VFP
Title:
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01156192
Message ID:
01158385
Views:
125
This message has been marked as the solution to the initial question of the thread.
>>Since I have the full Acrobat suite installed on my PC, I would like to try it. My email address is in my profile.
>
>Check your mailbox.

In case other people may have the same need, here is the function I ended up with. Thanks to Sergey for helping me overcome some anomalies which we discovered in Adobe Acrobat Professional. This function works perfectly with Acrobat version 7.0, but I guess it will also work with earlier versions.

I mark this as solution, not to get the stars, but to attract the attension. :-)

To use the function, you store the PDFs you want to merge into an array of _screen, like this
_screen.AddProperty('document(3)','') && Replace 3 with the number of documents
_screen.document(1)='mypath\mydoc1.pdf') && Make sure that you specify the whole path
_screen.document(2)='mypath\mydoc2.pdf')
_screen.document(2)='mypath2\mydoc3.pdf')
Do mergepdf with 'outputpath\mergedfiles.pdf' && Complete filename including path
Function Mergepdf
Lparameters pcOutput && Name of PDF to create
#DEFINE PDSaveLinearized        4       && Save the file in a linearized
#define CrLf = CHR(13) + CHR(10)
If !Vartype(_screen.document)='C' or Empty(_screen.document) or Pcount()<1 or !Vartype(pcOutput)='C' or Empty(pcOutput)
  Return
EndIf 
loAcroApp = Null
loAVDoc = Null
* Kill Acrobat if it's loaded into the  memory
KillAcrobat()
loAcroApp = CREATEOBJECT("AcroExch.App")
loAVDoc = CREATEOBJECT("AcroExch.AVDoc")
lcFirstPdfFile = FULLPATH(_screen.document[1])
lcFirstPath=JustPath(lcFirstPdfFile)
lcNewPdfFile  = ForceExt(FULLPATH(pcOutput),'pdf')
lcNewPath=JustPath(lcNewPdfFile)
lcTempPdfFile  = lcNewPdfFile  
COPY FILE (ForcePath(lcFirstPdfFile,JustPath(lcFirstPdfFile))) TO (lcNewPdfFile)
loAVDoc.Open(lcNewPdfFile, "PDF")
loPDDoc = loAVDoc.GetPDDoc()
lnMaxPage1 = loPDDoc.GetNumPages()
lnMaxPage = loPDDoc.GetNumPages()
loPDDoc2 = CREATEOBJECT("AcroExch.PDDoc") 
FOR lnInd=2 TO ALEN(_screen.document)
  llDelete=.f.
  lcFileName = _screen.document(lnInd) &&FULLPATH(_screen.document[lnInd])
  lnMaxPage = loPDDoc.GetNumPages()
  loPDDoc2.Open(lcFileName)
  lnMaxPage2 = loPDDoc2.GetNumPages()
  If llDelete
    Erase (ForcePath(_screen.document(lnInd),lcFirstPath))
  EndIf 
  loPDDoc.InsertPages(lnMaxPage-1, loPDDoc2, 0, lnMaxPage2, .T.)
  loPDDoc2.Close()
ENDFOR
loPDDoc.Save(PDSaveLinearized, lcTempPdfFile)
* Close and release all objects
loPDDoc.Close()
loPDDoc = Null
loAVDoc.Close(.T.)
loAVDoc = Null
loAcroApp.Exit()
* Kill Acrobat if it still been loaded into the memory
KillAcrobat()

RETURN 
*-------------------------------------------------------
FUNCTION KillAcrobat()
loCIMV2         = GetObject("winmgmts://localhost/root/cimv2")
loProcesses     = loCIMV2.ExecQuery("SELECT * FROM Win32_Process WHERE Name = 'Acrobat.exe'")
IF loProcesses.Count > 0
  For Each objProcess in loProcesses
    objProcess.Terminate(0)
  NEXT
ENDIF
RETURN
ENDFUNC
NB! Adobe Acrobat Professional is required to use this function
Previous
Reply
Map
View

Click here to load this message in the networking platform