http://youtu.be/5qHNQxZGZKU
啊,完全不知道这个乐队的存在。
最终得到了什么是CAcroPDDoc对象:
- (setq o (vlax-get-or-create-object "AcroExch.PDDoc")) ; returns #
Tho,没有意识到在那个VBA代码中PartDocs是一个数组 - 如果是这样:看起来它无法在LISP中获得。
哦,或者你的意思是他手动为vla对象创建了一个
safearray
,并在以后用CAcroPDDoc对象填充它?
我有点明白了(当我在那里看他的第一个代码建议时).虽然更喜欢使用完整的.pdf文件路径
,所以这是ReDim函数。
这是有价值的信息,起初我试图添加单个PDF文档对象 - 然后我认为这似乎很不寻常,在循环中创建相同的对象而不释放它。
这就是为什么我的lisp代码不同的原因......但是在看了一堆类似的vba-acrobat-scripting代码之后,我意识到我错了。
对我来说,这是代码中最令人沮丧的部分。
最后,我开始在网上寻找“最简单的建议”,只是为了看看InsertPages是如何工作的。
停止在这个简单的例子,关于如何合并两个PDF文档,Sub Button1_Click,看起来我得到了它!
所以现在伙计们,我们有一个LISP子来合并PDF:
- ;| Examples:
- (MergePDFs
- (strcat (getenv "userprofile") "\\Desktop\\Hale 515\\PDFs") ; in
- (strcat (getenv "userprofile") "\\Desktop\" "MergedPDFS.pdf") ; out
- )
- (MergePDFs
- (list ; in
- (getfiled "Specify PDF file" (strcat (getenv "userprofile") "\\Desktop\") "pdf" 16)
- (strcat (getenv "userprofile") "\\Desktop\\I_Dont_Exist.pdf")
- (getfiled "Specify PDF file" (strcat (getenv "userprofile") "\\Desktop\") "pdf" 16)
- (getfiled "Specify PDF file" (strcat (getenv "userprofile") "\\Desktop\") "pdf" 16) ; You can cancel and provide nil if you want to
- ); list
- (strcat (getenv "userprofile") "\\Desktop\" "MergedPDFS.pdf") ; out
- )
- |;
- ; in - folder that contains .pdf files, or a list of ("\\.pdf" "\\.pdf" ..)
- ; out - path\\filename.pdf - Overwrites the existing (if theres one)
- ; If successful, Returns assoc list of '(( PageCount) ..)
- (defun MergePDFs ( in out / *error* AcroApp L PD r )
- ; http://www.theswamp.org/index.php?topic=53974.msg586248#msg586248
- (defun *error* ( m )
- (and L (foreach x (mapcar 'car L) (vl-catch-all-apply 'vlax-invoke-method (list x 'Close)) (vl-catch-all-apply 'vlax-release-object (list x))))
- (and AcroApp
- (vl-catch-all-apply 'vlax-invoke-method (list AcroApp 'CloseAllDocs))
- (vl-catch-all-apply 'vlax-invoke-method (list AcroApp 'Exit))
- (vl-catch-all-apply 'vlax-release-object (list AcroApp))
- ); and
- (gc) (gc) (and m (princ m)) (princ)
- ); defun *error*
-
- (and in out
- (or (setq AcroApp (vlax-get-or-create-object "AcroExch.App")) (prompt "\nUnable to interfere with Acrobat object.") )
- (cond
- ( (eq 'STR (type in)) ; folder provided
- (setq L ((lambda (pat / tmp) (if (setq tmp (vl-directory-files pat "*.pdf" 1)) (mapcar (function (lambda (x) (list (vlax-get-or-create-object "AcroExch.PDDoc") (strcat pat "\" x)))) tmp))) in))
- )
- ( (vl-consp in) ; list of .pdf filepaths'n'names provided
- (setq L (mapcar (function (lambda (x) (list (vlax-get-or-create-object "AcroExch.PDDoc") x))) in))
- )
- ); cond
- (setq L (apply (function append) (mapcar (function (lambda (x) (if (eq :vlax-true (vlax-invoke-method (car x) 'Open (cond ((cadr x)) ("")))) (list (append x (list (vlax-invoke-method (car x) 'GetNumPages))))))) L)))
- (setq PD (caar L))
- (progn
- (foreach x (cdr L) ; L - assoc list of (# )
- (if (eq :vlax-false (vlax-invoke-method PD 'InsertPages (1- (vlax-invoke PD 'GetNumPages)) (car x) 0 (caddr x) :vlax-true))
- (prompt (strcat "\nCannot insert pages from "" (cadr x) """))
- )
- )
- (or (eq :vlax-true (vlax-invoke-method PD 'Save 1 out)) ; 1 = PDSaveFull
- (prompt "\nCannot save the modified document")
- ); or
- ); progn
- (setq r (mapcar 'cdr L))
- ); and
-
- (*error* nil) r
- ); defun MergePDFs
再次非常感谢你的帮助,我会尝试调整我的眼睛更多的VBA编码,尽管在编写LISP时仍然更舒服。 |