Discussion:
MergePDF
(too old to reply)
P***@adobeforums.com
2008-07-31 21:45:36 UTC
Permalink
You mean acrobat_pdfl_api_reference.pdf?




No, that's only for plug-ins written in C/C++.
A***@adobeforums.com
2008-07-31 21:06:44 UTC
Permalink
I'm all for doing my own homework, but I don't barely know where to start on this one. I only just downloaded the SDK a couple days ago.
L***@adobeforums.com
2008-07-31 20:52:37 UTC
Permalink
How about downloading the Acrobat SDK and reading the documentation?
L***@adobeforums.com
2008-07-31 21:26:22 UTC
Permalink
No, the IAC reference, since that's what you are working with (IAC == COM). Also, there are a bunch of COM samples for various languages (VB, C#, etc.) that will show how to merge PDFs.

Leonard
A***@adobeforums.com
2008-07-31 21:03:43 UTC
Permalink
"So, I'm still working my way through trying to school myself in the acrobat
SDK..."




You mean acrobat_pdfl_api_reference.pdf?

It's 5000+ pages, which doesn't qualify as light reading

I've tried skimming though it, but if you want to want to save me 40 hours of reading, you could tell me what page to start on to narrow it down.
A***@adobeforums.com
2008-08-01 13:17:05 UTC
Permalink
Well, I'm glad to know that I don't have to read that mess.

I also got one called SDK8_v2_Full_win.zip which is where I found the AdobePDFSilentVB project (very helpful).

I think a little bit of my problem is that Adobe put a lot of stuff up there to help developers, but it's almost information overload... Where to start first becomes the problem.
So thanks for helping us noobs get started with this stuff.

Just to make sure that I have the right documentation this time, and for a hint on where to start, let me know if any of these that I found are the right one.

samples_guide.pdf
Acrobat_SDK_developer_faq.pdf
iac_api_reference.pdf
iac_developer_guide.pdf
acrobat_sdk_doc_set.zip
L***@adobeforums.com
2008-08-01 14:00:03 UTC
Permalink
Look over the samples guide to help you find the sample you want - and then the two IAC docs for details.

Leonard
A***@adobeforums.com
2008-08-01 15:01:48 UTC
Permalink
Leonard, you have probably been working with all things Acrobat for a long time, and so someone like me that is asking questions because I have no idea where to start is probably frustrating to you.

I understand that, I've been there. I had to teach my mom how to turn on the computer and use a mouse.

So if you don't want to take the time to try to explain how to do this, then thats fine.
But there are 13106 pages in the acrobat_sdk_doc_set.zip files, and the ones that I've looked at don't seem to have what I'm looking for.

I'm not afraid to do my own research, and I don't want you to hold my hand, otherwise I'll never learn.
But instead of RTFM, how about something like "Read [insert filename], especially section [insert section title]"
Or even better, "Open [insert project name], it will show you how to do it"
A***@adobeforums.com
2008-08-01 14:41:45 UTC
Permalink
I've actually read the Guide to SDK Sample pretty thoroughly, using the classic method:
1. Do a word search for what your looking for

a. Merge: no results found
b. Insertpages: one result found, but it's for plug-ins again, so useless

2. Skim over the projects in the IAC section

a. AcroPDFInHTML: HTML, nothing about insertpages
b. AcrobatActiveXVB: Display pdfs in the application. Maybe useful later,
but not for this project.
c. ActiveViewVB: Similar to b
d. ActiveViewVC: Same as c
e. AdobePDFSilent: Very useful, already got this one working, thanks a lot
PDL.
f. BasicIACVB: Open PDF, getnumpages. no insert.
g. BasicIacCS: Same as f
h. BasicIacJsoVB: Also the same as f
i. BasicIacOCXCS: Um, the same as b, c, and d, but displays two PDFs instead
of one?
j. BasicIacVC: Same as f, g, and h
k. DdeOpenVC: Sounds like it lets you remote control Acrobat...
l. DistillerCtrlVB: use distiller to convert postscript files... sounds
like a more indepth version of e
m. DistillerCtrlVC: Same as l
n. Same as l, m
o. ExecuteScriptIacVB: This one almost sounded useful, since it talks about
doing stuff in a new PDF... but I opened it and looked it over, and its
not useful.
p. FillFormCS: Forms, no insertpages, no merge.
q. FormsAutomationVB: Forms...
r. JSOFindWordVB: Search a pdf using javascript... This might be useful
to search through all the documents in this sdk and return one that mentions
how to actually do something useful with insertpages or merge...
s. JSObjectAccessVB: This one almost tricked me into thinking it was useful
too...
t. RemoteControlAcrobatVC: Sounds like k, but without javascript
u. SearchPdfVB: like r
v. StaticViewVB: like b, with less controls.
w. StaticViewVC: like v
x. WatermarkJsoVB: Add watermarks to a PDF...

And nothing anywhere that I can find about merging or inserting pages into a PDF.

RTFM is great advice an all, but before you say that, the FM should have F useful information in it.
L***@adobeforums.com
2008-08-01 15:59:22 UTC
Permalink
Let me look...

Hmm...You are right - they removed the old "page merging sample" that used to be in the SDK.

The problem is your InsertPages() call - check the parameters again (they are tricky)...

Leonard
A***@adobeforums.com
2008-08-01 16:59:41 UTC
Permalink
Hmm, thinking out loud...
In the Interapplication Communication API Reference, on pages 79-80, it talks about InsertPages.
specifically VARIANT_BOOL InsertPages(long nInsertPageAfter,LPDISPATCH iPDDocSource,long nStartPage,long nNumPages, long bBookmarks); Cool. and I found this example <http://support.adobe.com/devsup/devsup.nsf/docs/51009.htm>

AcroPDDoc.InsertPages(0, PDDoc, 0, 1, False)

which kind of looks like mine...

dPDDocMerge.InsertPages(numPage, dPDDoc, 0, dPDDoc.GetNumPages, 0)

(oh, and I did catch that error where i had .GetNumPages in the wrong place)

so now it looks like:

Dim dPDDocMerge As New Acrobat.AcroPDDoc
Dim dPDDoc As New Acrobat.AcroPDDoc
Dim strFiles() As String
Dim numPage As Integer

Dim objThisFile As FileInfo 'get FileInfo object for file string

Dim b As Boolean
For i As Integer = 0 To strFiles.Length - 1
objThisFile = New FileInfo(strFiles(i))
If objThisFile.Extension = ".pdf" Then
dPDDoc = New Acrobat.AcroPDDoc
b = dPDDoc.Open(strFiles(i))

numPage = dPDDocMerge.GetNumPages
b = dPDDocMerge.InsertPages(0, dPDDoc, 0, dPDDoc.GetNumPages, False)
End If
Next

and b still = false... so is my problem with the LPDISPATCH iPDDocSource part? I don't know how to find out this information in the file, and none of Adobes docs explain it.

Do you still have the page merge sample around?
Or take my code and run it in VS2005... I'm starting to wonder if it's just an incompatibility with VS2008
A***@adobeforums.com
2008-08-01 17:33:37 UTC
Permalink
Well, it didn't work in VS2003 either...
Is there any way to make the Acrobat SDK fail more verbosely?
A***@adobeforums.com
2008-08-01 21:06:36 UTC
Permalink
InsertPages ' Destination document
(long nInsertPageAfter, ' Page to insert after, in this case page 1
LPDISPATCH iPDDocSource, ' Source document
long nStartPage, ' Source document page to insert from
long nNumPages, ' number of pages to insert
long bBookmarks) ' don't insert bookmarks

dPDDocMerge.InsertPages ' Destination document
(0, ' Page to insert after, in this case page 1
dPDDoc, ' Source document
0, ' Source document page to insert from
dPDDoc.GetNumPages, ' number of pages to insert
False) ' don't insert bookmarks

They look the same... Oh well, giving up for the weekend.
L***@adobeforums.com
2008-08-01 19:20:17 UTC
Permalink
If you use standard VB/C#/whatever error handling mechanism, you can get back error codes & strings.

As far as the source, that's the document you want to insert FROM and then the call is made to the destination document.

Leonard
R***@adobeforums.com
2008-08-02 18:57:36 UTC
Permalink
The first file you have to open and to set as object. The other you have only to insert into the first file.

Attached a working example.

HTH, Reinhard

C:\AcInsFL4.vbs
----------------------------------------------------------------

REM: Insert single/multi Pdfs into one PDF, based on a filelist-file (Datei)
REM: The "Settings.." you can change to your needs. Drag&drop for 1 filelist-file accepted.

'*********Settings in File**************************
Datei = "C:\FileList.txt" '//Filename for filelist-file (files that will be inserted)
Ask = 0 '//0=don't ask for Insert;1=ask
Bookmark = 0 '//0=Insert No bookmarks;1=Insert based on Filename
InsWithBM = "false" '//true=Insert bookmarked files with BM; false = no
'****************************************************
set WshShell = CreateObject ("Wscript.Shell")
set fs = CreateObject("Scripting.FileSystemObject")
Set objArgs = WScript.Arguments
if objArgs.Count = 1 then Datei = ObjArgs(0)

Info = "Insert PDF-Files in Acrobat based on File-list-file."&VbCr&_
"File Name: "&Datei &" Start now?"
OK = MsgBox(Info, vbQuestion+vbYesNo,"Insert Files") : if OK = vbNo then WScript.quit

'//Start or switch to Acrobat
WshShell.run "Acrobat.exe"
While not WshShell.AppActivate("Adobe Acrobat") : Wscript.Sleep 1000 : Wend
Set gApp = CreateObject("AcroExch.App")

FLPOS = 1
if not fs.FileExists(datei) then
MsgBox "Ups! " & datei & " doesn't exist? " & "Try new!", vbExclamation
WScript.quit
end if

set dateiinhalt = fs.OpenTextFile(datei)
do until dateiinhalt.atEndOfStream
inhalt = dateiinhalt.ReadLine
if fs.FileExists(inhalt) then

if Ask=1 then if MsgBox(FlPos&": "&inhalt, vbOKCancel + vbInformation) = vbCancel then exit do
'#File->Open first File
if FLPOS = 1 then
Set gApp = CreateObject("AcroExch.App")
Set BASFL = CreateObject("AcroExch.pdDoc")
OK = BASFL.Open(INHALT)
if not OK Then if MsgBox("Error open Basic File") then Wscript.quit
BASFL.OpenAVDoc(mid(INHALT,InstrRev(INHALT,"\")+1))
WScript.Sleep 1000
Set avdoc = gApp.GetActiveDoc
Set pddoc = avdoc.GetPDDoc
Set jso = pddoc.GetJSObject
PageBAS = BASFL.GetNumPages-1
else
PageBAS = BASFL.GetNumPages
jso.pageNum = PageBAS+1
Set INSFL = CreateObject("AcroExch.PDDoc")
OK = INSFL.Open(INHALT)
if not OK Then if MsgBox("Error open InsertFile") then Wscript.quit
PageIns = INSFL.GetNumPages
OK = BASFL.InsertPages(PageBAS - 1,INSFL,0,PageIns,InsWithBM)
INSFL.Close
jso.pageNum = PageBAS+2
end if
if Bookmark = 1 then
BMNameIE = mid(Inhalt, InstrRev(Inhalt, "\")+1)
BMNameEE = left(BMNameIE, InstrRev(BMNameIE, ".")-1)
Set BMR = JSO.BookmarkRoot
BMR.CreateChild BMNameEE, "this.pageNum = " &PageBas, PageBas
end if
FLPOS = FLPOS+1
else '/-> file in Filelist (=inhalt) doesn't exist
Ok = MsgBox(Inhalt &vbCr &"File don't exist! - Continue?", vbQuestion+vbYesNo,"Insert Files")
if OK = vbNo then QUIT
end if
loop
MsgBox " DONE!" &vbCr &"Don't forget to save the File (save as)"
QUIT

Sub QUIT
dateiinhalt.close
Set JSO=Nothing
Set PDDoc=Nothing
Set gApp=Nothing
Wscript.quit
End sub
A***@adobeforums.com
2008-08-04 15:30:42 UTC
Permalink
Thank you! A useful answer at last!

To others that are looking for a solution to this problem in the future, you have to have a page in there to start with before you can add more in. So open the first one, then add to it, and save with a different file name.
Here is the final working piece, working in VS2008:

Sub MergePDF(ByVal Path As String, ByVal outFileName As String)
On Error GoTo serror

Dim dPDDocMerge As New Acrobat.AcroPDDoc
Dim dPDDoc As New Acrobat.AcroPDDoc
Dim strFiles() As String
Dim numPage As Integer
Dim TotalPage As Integer
Dim objThisFile As FileInfo 'get FileInfo object for file string

strFiles = System.IO.Directory.GetFiles(Path) ' Read in the file names

Dim b As Boolean ' mostly for testing purposes... could use it for error checking to make sure that a file is really added before deleleting it...
For i As Integer = 0 To strFiles.Length - 1 ' run through all the files in the directory
objThisFile = New FileInfo(strFiles(i)) ' Get the extension
If objThisFile.Extension = ".pdf" Then ' Only add in PDFs
If dPDDocMerge.GetFileName = "" Then ' check if it's the first file
dPDDocMerge = New Acrobat.AcroPDDoc
b = dPDDocMerge.Open(strFiles(i)) ' open first file
TotalPage = dPDDocMerge.GetNumPages
Else
dPDDoc = New Acrobat.AcroPDDoc
b = dPDDoc.Open(strFiles(i)) ' open other files

numPage = dPDDocMerge.GetNumPages ' get the page count
TotalPage += numPage
b = dPDDocMerge.InsertPages(numPage - 1, dPDDoc, 0, dPDDoc.GetNumPages, False) ' Insert
End If
End If
Next

b = dPDDocMerge.Save(1, Path & "\" & outFileName) ' save file
b = dPDDocMerge.Close()
Exit Sub
serror:
MsgBox(ErrorToString)
End Sub
A***@adobeforums.com
2008-08-04 17:31:58 UTC
Permalink
Hmm, here's a wierd thing... maybe a bug?
I run the program on a directory with 2 files.
The program opens the first file, opens the second, inserts the second into the first, and saves, just like it is supposed to.

So I delete the merged file, and run it again.
The program opens the first file, opens the second, but does not insert the pages. Failure... So I open Task manager, and end process on Acrobat.exe.

Run the program again, and it works just fine.

Ok, lets test this.
I put a third PDF into the directory, end Acrobat.exe, and run the program again.
The program opens the first file, opens the second, inserts the second into the first, opens the third file, but does not insert it... probably because of the acrobat.exe again.

And so added a .Close = dPDDocMerge.InsertPages(numPage - 1, dPDDoc, 0, dPDDoc.GetNumPages, False) ' Insert = dPDDoc.Close

and that seems to fix the problem

Loading...