http://youtu.be/5qHNQxZGZKU啊,完全不知道这个乐队的存在
最终得到了什么是CAcroPDDoc对象:
- (setq o (vlax-get-or-create-object "AcroExch.PDDoc")) ; returns #
Tho,did#039;t意识到,在VBA代码中,PartDocs是一个数组——如果是这样的话:看起来它无法在LISP中获得
哦,或者你的意思是他为vla对象手动创建了一个安全阵列,并在稍后用CAcroPDDoc对象填充它
我有点明白了(当我在那里看他的第一个代码建议时)…尽管我更喜欢#039;d来处理完整的.pdf文件路径,所以这是关于的ReDim函数
这是很有价值的信息,起初我试图添加单个PDF文档对象-然后我认为这似乎不寻常,在循环中创建相同的对象而不释放它
这就是我的lisp代码不同的原因。但是在看了一堆类似的vba acrobat脚本代码后,我意识到我';我错了
对我来说,这是代码中最令人沮丧的部分。最后,我开始寻找;“最简单的建议”;在web上,只想看看InsertPages是如何工作的
停止这个简单的例子,关于如何合并两个PDF文档,点击子按钮1\u,看起来我明白了
;现在我们有了一个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更舒服。 |