sadhu Posted January 9, 2015 Posted January 9, 2015 I have several A4 pages in pdf format printed from autocad. Since these pages are printed via lisp I have their local addresses in lisp variables. (setq page1 "\\pdf\page1.pdf" etc.) I then use "PDF Merge Tool" to combine these pages manually to create a single pdf file - instruction manual. Is it possible to combine pdf file via Lisp ? All help is appreciated. Quote
Spaj Posted January 9, 2015 Posted January 9, 2015 I assume you have the AutoCAD source .DWG. Why not publish to a single multipage .PDF file directly from AutoCAD? Quote
sadhu Posted January 9, 2015 Author Posted January 9, 2015 Spaj : These pdf files are printed within a lisp routine that changes certain values, freezes /unfreezes layers, adds lines etc according to user input. The dwg is only in model space. So I don't think I can use publish. Quote
BIGAL Posted January 10, 2015 Posted January 10, 2015 I take it your Pdf merge tool is a external program if so you can use "Shell" which opens a operating system window that you can send commands to. Something like ("shell" "notepad") Quote
sadhu Posted October 10, 2016 Author Posted October 10, 2016 (edited) Hi, This might be of help to someone. Mearging pdf files can done quite easily with Ghostscript. read here Roy_043 posted this : (defun KGA_String_Join (strLst delim) (if strLst (apply 'strcat (cons (car strLst) (mapcar '(lambda (a) (strcat delim a)) (cdr strLst)))) "" ) ) ; (CombinePdf ; "C:\\Program Files\\gs\\gs8.61\\bin\\gswin32c.exe" ; '("D:\\Tmp\\A.pdf" "D:\\Tmp\\B.pdf") ; "D:\\Tmp\\Total.pdf" ; ) ; Note: Existing trgFile will be overwritten. (defun CombinePdf (gsExe srcFileLst trgFile) (startapp (strcat gsExe " " "-dBATCH -dNOPAUSE -dQUIET -sDEVICE=pdfwrite " "-sOutputFile=\"" trgFile "\" " "\"" (KGA_String_Join srcFileLst "\" \"") "\"" ) ) ) You need to install Ghostcript - it's a freeware. Edited October 11, 2016 by sadhu Quote
BIGAL Posted October 11, 2016 Posted October 11, 2016 A further version thanks to roy_043 ;Plots layouts by range ; By Alan H Feb 2014 (defun AH:pltlays ( / pdfname lay numlay numend) (SETVAR "PDMODE" 0) (setvar "fillmode" 1) (setvar "textfill" 1) (setq plotnames '()) (if (not AH:getval2) (load "getvals")) (ah:getval2 "Enter start tab number" 6 4 "Enter end tab number" 6 4) (setq numlay (ATOI val1)) (setq numend (ATOI val2)) (setq len (+ (- numend numlay) 1)) (setq dwgname (GETVAR "dwgname")) (setq lendwg (strlen dwgname)) (setq dwgname (substr dwgname 1 (- lendwg 4))) (repeat len (vlax-for lay (vla-get-Layouts (vla-get-activedocument (vlax-get-acad-object))) (if (= numlay (vla-get-taborder lay)) (setvar "ctab" (vla-get-name lay)) ) ; if (setq pdfname (strcat (getvar "dwgprefix") "pdf\\" dwgname "-" (getvar "ctab") ".pdf" )) ) ; for (setq lay nil) (setvar "textfill" 1) (setvar "fillmode" 1) (COMMAND "-PLOT" "Y" "" "dwg to Pdf" "Iso full bleed A3 (420.00 x 297.00 MM)" "m" "LANDSCAPE" "N" "W" "-6,-6" "807,560" "1=2" "C" "y" "Designlasercolour.ctb" "Y" "n" "n" "n" pdfName "N" "y" ) (setq numlay (+ numlay 1)) (setq plotnames (cons pdfname plotnames)) ) ; end repeat (setq trgfile (strcat (getvar "dwgprefix") "pdf\\" dwgname "-D" val1 "-D" val2 ".pdf")) ) ; defun (AH:pltlays) (if (not combinepdf)(load "mergepdfs")) (combinepdf gsExe plotnames trgFile ) (setq plotnames nil val1 nil val2 nil) (princ) ;MergePdfs ;Merges multiple pdf (or eps) files into one ; ; make a batch file ? ;gs -sDEVICE=pdfwrite \ ; -dNOPAUSE -dBATCH -dSAFER \ ; -sOutputFile=combined.pdf \ ; first.pdf \ ; second.pdf \ ; third.pdf [...] ;Ghostscript ([url]http://www.ghostscript.com/[/url]) can be used to combine PDFs. ; Something like this should work: by Roy_043 (defun KGA_String_Join (strLst delim) (if strLst (apply 'strcat (cons (car strLst) (mapcar '(lambda (a) (strcat delim a)) (cdr strLst)) ) ) "" ) ) (setq gsexe "C:\\Program Files\\gs\\gs9.19\\bin\\gswin64c.exe") ; Note: Existing trgFile will be overwritten. (defun CombinePdf (gsExe srcFileLst trgFile) (startapp (strcat gsExe " " "-sDEVICE=pdfwrite -dBATCH -dNOPAUSE -dQUIET " "-sOutputFile=\"" trgFile "\" " "\"" (KGA_String_Join srcFileLst "\" \"") "\"" ) ) ) GETVALS.lsp 1 Quote
Mostafa hisham Posted March 26, 2022 Posted March 26, 2022 Hello sir i have merged the code of plot (ah:pltlays) with the lisp of merge pdf but it don't merge the pdfs can you help me about that ?? i have uploaded the lisp that i have made and i which you help me about that thanks in advance plot lisp & GETVALS lisp inside it .lsp Quote
BIGAL Posted March 27, 2022 Posted March 27, 2022 Its a 5 year old post, you need to mention that you need to download Ghostscript and check where you save it to eg (setq gsexe "D:\\gs\\gs9.55.0\\bin\\gswin64c.exe") Quote
Mostafa hisham Posted March 30, 2022 Posted March 30, 2022 thanks about that I need to delete the other separate pdfs can I make that ?? Quote
Tbiddle Posted October 19, 2022 Posted October 19, 2022 Did you get anywhere on the deleting of the single separate pdfs? I also need this. My only thought is to have it dump the single pages in a tmp folder. Quote
rlx Posted October 19, 2022 Posted October 19, 2022 just a thought (in case you don't have ghostscript or unable to install it) first attach each separate pdf to a dwg (script / lisp) and then publish all dwgs to a single pdf. Quote
BIGAL Posted October 20, 2022 Posted October 20, 2022 If you look at my code the list of file names is made here (setq plotnames (cons pdfname plotnames)) and the files are in a directory \PDF under the current dwg location, there is VL-delete-file . So could do a Foreach loop and delete files. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.