Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #4724

Re: Assembling PDFs into a PDF document?

From Themis Matsoukas <tmatsoukas@me.com>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Assembling PDFs into a PDF document?
Date 2011-09-03 21:56 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <j3u7q8$a7p$1@smc.vnet.net> (permalink)

Show all headers | View raw


Hi AES, 

This solution cheats because it uses latex to do the  real job. However, it does use mathematica to assemble the latex code. To use it:

1. place your pdf's in a subdirectory of the directory that contains the notebook (avoid file names that confuse latex)
2. supply the name of the subdirectory in the notebook in the variable pdfsubdirectory (in this example the directory is called "pdf_files")
3. Execute the notebook.

This creates a latex file in the current directory that uses the package pdfpages. Typeset it and you will get the assembled pdf. I suppose one should be able to send the typesetting command directly from Mathematica to the shell to fully automate the process, but this job is for another volunteer :-)

Themis

(*specify name of subdirectory that contains the pdf files*)

pdfsubdirectory = "pdf_files";
thisdirectory = SetDirectory@NotebookDirectory[];

(*read in list of pdfs*)

mypdffiles = FileNames["*.pdf", pdfsubdirectory];
numberoffiles = Length[mypdffiles];

(*build latex code*)

latexcode = 
  StringJoin @@ 
   Join[{"\\documentclass[11pt]{article}\n\\usepackage{pdfpages}\n\
\\begin{document}\n"}, 
    Table[StringJoin["\\includepdf[pages=-]{", 
      ToString[mypdffiles[[i]]], "}\n"], {i, 1, 
      numberoffiles}], {"\\end{document}"}];
Export["assemblepdf.tex", latexcode, "Text"]

Back to comp.soft-sys.math.mathematica | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Re: Assembling PDFs into a PDF document? Themis Matsoukas <tmatsoukas@me.com> - 2011-09-03 21:56 +0000
  Re: Assembling PDFs into a PDF document? AES <siegman@stanford.edu> - 2011-09-04 08:14 +0000

csiph-web