TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: ttechnik on March 04, 2016, 03:22:17 AM

Title: concatenate PDF's
Post by: ttechnik on March 04, 2016, 03:22:17 AM
I would like one pdf file, with some laps.
(vla-put-ConfigName activelayout "DWG To PDF_A3L.pc3")
in repeat cicle:
(vla-PlotToFile acadPlot (strcat filedir text_fix "-" (car (nth i Rajzok))))

I would like not to create separate files

Does anyone have any idea?

Title: Re: concatenate PDF's
Post by: David Bethel on March 04, 2016, 06:13:30 AM

I don't know if it can be done in AutoCAD.

What I do is plot to Postscript files, and have Distiller combine them into a single PDF

It can be automated so that it is a 2 step process

Also ( on my systems at least ) postscript plotting can bypass all prompts and dialog boxes.

-David
Title: Re: concatenate PDF's
Post by: ttechnik on March 04, 2016, 11:24:20 AM
THX
my best cont progr: http://www.pdfsam.org/download-pdfsam-basic/
Title: Re: concatenate PDF's
Post by: Cathy on March 04, 2016, 04:32:07 PM
Publish allows you the option of a multi-sheet file or single sheet files.  I'm not sure that's an answer to your question though. 
Title: Re: concatenate PDF's
Post by: MickD on March 04, 2016, 06:29:48 PM
PDF Creator (http://www.pdfforge.org/pdfcreator) allows you to save each print in a list that can be combined into one file, have been using it for years and works well.
It can also be automated with vba etc.
Might be worth a look.
Title: Re: concatenate PDF's
Post by: ttechnik on March 05, 2016, 01:29:49 PM
Cathy, the publish is not good. I have one layout and print in program after zoom target.

MickD, from lisp send print to PDF creator?
I do'nt want VB programaing
Title: Re: concatenate PDF's
Post by: JohnK on March 05, 2016, 03:12:13 PM
Use Ghostscript, or something like it, and call it from Autolisp.
Code: [Select]
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=merged.pdf file1.pdf file2.pdf
Title: Re: concatenate PDF's
Post by: ttechnik on March 06, 2016, 06:00:32 AM
THX.

I install the gs9.18.
But I recive: not recognized command.
Title: Re: concatenate PDF's
Post by: Grrr1337 on March 06, 2016, 07:41:25 AM
I agree with Cathy, try with PUBLISH.
The only question is can it be automated with lisp? I don't know anyone ever tried that.
EDIT: I did my research and found BlackBox's publish reactor (I added some stuff and info to it):

Code: [Select]
;Reactor for PUBLISHING (author: BlackBox)
;Reactor starts upon "AUTOMATICPUB" variable is set to 1, and Ctrl+S (quicksave) the drawing
;NOTE: to PUBLISH IN .PDF format go to "Options" -> "Plot and Publish" -> "Automatic Publish Settings", in General DWF/PDF options change "File format" to PDF

    (setq PBCOLLATE (getvar 'PUBLISHCOLLATE))
    (setvar "PUBLISHCOLLATE" 1)

    (setq PBHATCH (getvar 'PUBLISHHATCH))
    (setvar "PUBLISHHATCH" 1)

    (setq PBALLSHEETS (getvar 'PUBLISHALLSHEETS))
    (setvar "PUBLISHALLSHEETS" 1)

    (setq FIELD-EVAL (getvar 'FIELDEVAL))
    (setvar "FIELDEVAL" 4)
 
    (setq AUTOPUB (getvar 'AUTOMATICPUB))
    (setvar "AUTOMATICPUB" 1)

    (setq AUTODWFPUB (getvar 'AUTODWFPUBLISH))
    (setvar "AUTODWFPUBLISH" 0)

;AUTOMATICPUB 0 and ctrl+s
;AUTOMATICPUB 1 and ctrl+s to start the reactor

(vl-load-com)

(defun Autopublish:StartReactor ()


  (or *AutopublishReactor*
      (setq preferences (vla-get-Preferences (vlax-get-acad-object)))
      (setq *AutopublishReactor*
     (vlr-docmanager-reactor
       nil
       '(
(:vlr-documentbecamecurrent . Autopublish:DocumentBecameCurrent)
)
     )
      )
  )
  (princ)
)

(defun Autopublish:DocumentBecameCurrent (rea doc)
  (if (and *AutopublishReactor* (= 1 (getvar 'automaticpub)))
    (prompt (strcat "\n[BlackBox] : AUTOMATICPUB = "
    (itoa (setvar 'automaticpub 0))
    )
    )
  )
  (princ)
)

(Autopublish:StartReactor)

And maybe this would be handy addition:
Code: [Select]
;Toggle the AUTOMATICPUB variable:

(defun c:tgAutoPub (/)
  (if (= (getvar "AUTOMATICPUB") 1)
  (setvar "AUTOMATICPUB" 0)
  (setvar "AUTOMATICPUB" 1)
  )
  (princ (strcat "\nAUTOMATICPUB variable is set to \"" (rtos(getvar "AUTOMATICPUB")) "\" "  ))
  (princ)
)
Title: Re: concatenate PDF's
Post by: JohnK on March 06, 2016, 02:53:01 PM
THX.

I install the gs9.18.
But I recive: not recognized command.

That's because Ghostscript needs to be in the "environmental path" for Windows before you can use just "gs ...". Otherwise, you will have to use a fully qualified path like: "c:/Ghostscript/bin/gs.exe ..."
Title: Re: concatenate PDF's
Post by: ttechnik on March 06, 2016, 04:53:18 PM
Yes, John.

I use fully path.

But I have gswin64.exe  and gswin64c, not gs.exe.

Not recognized command....
Title: Re: concatenate PDF's
Post by: roy_043 on March 07, 2016, 03:04:08 AM
The executable is named gswin64c.exe instead of gs.exe in your case.

Quote from: http://ghostscript.com/doc/8.63/Use.htm
The command line to invoke Ghostscript is essentially the same on all systems, although the name of the executable program itself may differ among systems.
Title: Re: concatenate PDF's
Post by: JohnK on March 07, 2016, 09:46:58 AM
ttechnik, roy_043 is right. You need to call "c:\GS\Ghostscript\bin\gswin64.exe" or rename "gswin64.exe" to "gs.exe".
Title: Re: concatenate PDF's
Post by: ttechnik on March 08, 2016, 02:51:52 PM
THX to everyone

Code: [Select]
(command "shell"
    (strcat "d:/gs/gs918/bin/gswin64 \" -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -iDirectories=d:/gs/gs918/bin
                 -sOutputFile=a.pdf b.pdf  \"")
)
gs is run, but:
(http://)
Title: Re: concatenate PDF's
Post by: JohnK on March 08, 2016, 03:01:18 PM
ttechnik, Try the 32 bit version. The 32 bit version should run fine on an x64 machine.
Title: Re: concatenate PDF's
Post by: roy_043 on March 09, 2016, 03:01:22 AM
@ ttechnik: You should supply the path to the PDFs. And to merge files you have to specify more than one source file.
Code - Auto/Visual Lisp: [Select]
  1.   (strcat
  2.     "D:/gs/gs918/bin/gswin64 "
  3.     "-dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile="
  4.     "D:/Test/merged.pdf D:/Test/a.pdf D:/Test/b.pdf"
  5.   )
  6. )
Title: Re: concatenate PDF's
Post by: ttechnik on March 09, 2016, 06:07:26 AM
Not 64 bit problem.
Great difficulty solved problem.
The target must be complete file path.
Otherwise, not will create.

Code: [Select]
(command "shell"
    (strcat "d:/gs32/gs9.18/bin/gswin32 -dSAFER -dBATCH -dNOPAUSE -q -iDirectories=d:/gs32/gs9.18/bin
-sDEVICE=pdfwrite -sOutputFile=d:/gs32/gs9.18/bin/target.pdf a.pdf b.pdf  ")
  )
Title: Re: concatenate PDF's
Post by: ttechnik on March 09, 2016, 07:39:29 AM
What to do in the parameters, file names have spaces?
Title: Re: concatenate PDF's
Post by: JohnK on March 09, 2016, 08:29:36 AM
Will escaping the quote mark work?

Code: [Select]
... -sOutputFile=d:/gs32/gs9.18/bin/target.pdf \"a.pdf\" \"b.pdf\"
Title: Re: concatenate PDF's
Post by: ttechnik on March 09, 2016, 11:08:00 AM
Not what I meant.

Code: [Select]
(command "shell"
    (strcat (findfile "gs/bin/gswin32.exe") " -dSAFER -dBATCH -dNOPAUSE -q "
                      "-iDirectories=" filesdir " -sDEVICE=pdfwrite "
                      "-sOutputFile=" outputfullfilename " " file1 " " file2)
  )
file2 is "H:\\MT GPON 2015\\KM 002 Mezőkövesd dél (II) INS Turn Key\\__ReKód_13-14-15\\15\\dd-temp"

Which replace the space character strings?
Title: Re: concatenate PDF's
Post by: ttechnik on March 17, 2016, 11:22:45 AM
Here is the solution:

Code: [Select]
(command "shell" (strcat (chr 34) "A:\\support_sajat\\prog_samples\\gs\\bin\\gswin32.exe "
"-dSAFER " "-dBATCH " "-dNOPAUSE " "-q " "-sDEVICE=pdfwrite " (chr 34)
"-sOutputFile=C:\\Users\\Tamás\\Dropbox\\F\\ss.pdf" (chr 34) " " (chr 34)
"C:\\Users\\Tamás\\Dropbox\\FTTH minták\\aa.pdf" (chr 34) " " (chr 34)
"C:\\Users\\Tamás\\Dropbox\\FTTH minták\\ss-temp.pdf" (chr 34)))