Services & ResourcesWolfram ForumsMathGroup Archive

Re: Assembling PDFs into a PDF document?

• To: mathgroup at smc.vnet.net
• Subject: [mg121195] Re: Assembling PDFs into a PDF document?
• From: Themis Matsoukas <tmatsoukas at me.com>
• Date: Sat, 3 Sep 2011 17:55:29 -0400 (EDT)
• Delivered-to: l-mathgroup@mail-archive0.wolfram.com

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[];

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"]



• Prev by Date: Resizing graphics
• Next by Date: Re: Quit versus Clear["Global`*"]
• Previous by thread: Re: Assembling PDFs into a PDF document?
• Next by thread: Re: Assembling PDFs into a PDF document?