Jump to content
BrianTFC

Plot to PDF and Combine into one file

Recommended Posts

BrianTFC

All,

 

I need some help with this PDF plot lisp that was created at work, this lisp was created to take material list sheets PDF them and drop them into the source folder with the sheet name as the file name. I was wondering if someone could help figure out how to combine the pages together to create one file once they are converted to PDF all as one step.

 

;;;This is the lisp routine to Plot the material list to individual PDF files with the job name and the page number
;;;as is does in the Plot Material List button.
;;; plotpdf.lsp
(defun c:PlotPDF (/ ob ss bn mn mx)
     (vl-load-com)
   (setq cnt 0)
   (setq dir(getvar "dwgprefix"))
           (if (and (progn
                (initget "B")
          (setq ob (entsel "\nSelect Block/B for blockname: "))
               (cond 
               ((eq ob "B")
                   (setq bn (getstring "\nEtner Block Name: "))
                   )
               ((and (eq (type ob) 'LIST)
              (vlax-method-applicable-p (vlax-ename->vla-object (car ob)) 'getboundingbox))
                     (setq bn (cdr (assoc 2 (entget (car ob))))))))
 (tblsearch "BLOCK" bn)
               bn     
               (setq ss  (ssget "_X" (list '(0 . "INSERT")'(410 . "Model")(cons 2 bn))))
                     )
                   
               
(progn 
         (vla-zoomextents (vlax-get-acad-object))
       (repeat (setq i (sslength ss))
 (setq ML "Material-List")
 (setq cnt (1+ cnt))
 
 (vla-getboundingbox (vlax-ename->vla-object (ssname ss (setq i (1- i)))) 'mn'mx)
     (command "plot" "yes" "model" "DWG To PDF.pc3" "ANSI A (8.50 x 11.00 Inches)"
         "inches" "LANDSCAPE" "no" "Window"
         (trans (vlax-safearray->list mn) 0 1)
         (trans (vlax-safearray->list mx) 0 1)
         "fit" "center" "yes" "acad.ctb"  "yes" "As Displayed" (strcat dir "ML-" (itoa cnt) "-"(getvar "dwgname")) "no" "yes" "yes" "yes")
               (command ".delay" "750")
   )
             )
              (princ "\nNo Blocks Selected: ")
         )(princ)
     )

 

Thanks,

Brian

Share this post


Link to post
Share on other sites
BIGAL

Adobe acrobat thats what we have access to it has COMBINE as a option. Takes maybe 2 minutes or less to make 1 pdf with all in. 88 sheets = 15Mb.

 

There are posts about PDF's creators Bluebeam etc which appear to have this ability, I am sure others will post

Share this post


Link to post
Share on other sites
BrianTFC

thanks for the reply BIGAL, I guess the big question is..can it be done thru lisp? if AutoCAD isn't capable of combining them that's fine just let me know...8)

Share this post


Link to post
Share on other sites
BIGAL

Theres is posts about using Publish and making 1 pdf pretty sure you have to have the right pdf creator I dont think Dwg to pdf works.

Share this post


Link to post
Share on other sites
Roy_043

Ghostscript can be used to combine PDFs.

 

Something like this should work:

(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 "\" \"") "\""
   )
 )
)

Share this post


Link to post
Share on other sites
BIGAL

Nice idea Roy_043 will have a play the srcfilelst can be made pretty easy as as you plot each pdf you add it to the list. and then run as per your code.

 

in the code above

(setq pdfname (strcat dir "ML-" (itoa cnt) "-"(getvar "dwgname")))
(setq srcfilelst (cons pdfname scrfilelst))

 

Seems to work pretty good may do it for say more than 4 pdf's will have a chat with the guys and gal.

Edited by BIGAL
Tested now

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×