Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a lot of PDF files with 1 to 4 pages each. I need a solution which automatically generates a new file for each of these files. The new files should contain the content of the original files twice (i.e. pages 1 through to the end, followed by the same pages in the same order again).

How do I accomplish this?

share|improve this question
3  
Please clarify, we cannot read your mind. What bill? You want to generate a new pdf file that contains every page of the original twice? In what order? Do you want page 1a followed by page 1b or do you want all 4 pages first and then all four pages again? What Operating system are you using? What tool do you use to create the pdfs? –  terdon May 28 '13 at 15:52
add comment

2 Answers

up vote 4 down vote accepted

Solution for Windows using PDFtk (which you seem to be using as per your tags):

This will result in a PDF with pages 1-end followed by 1-end again:

pdftk in.pdf cat 1-end 1-end output out.pdf

If you want each page to be duplicated together (as in 1,1,2,2,...), use the following batch file:

@echo off
set pages=
setlocal enabledelayedexpansion
for /f "tokens=2" %%a in ('pdftk in.pdf dump_data ^| find /i "NumberOfPages"') do for /l %%b in (1,1,%%a) do set pages=!pages! %%b %%b
pdftk in.pdf cat!pages! output out.pdf
share|improve this answer
    
Thanks a lot: "pdftk in.pdf cat 1-end 1-end output out.pdf" exactly does what I need. The only thing missing is a loop that takes all pdf files from a directory and creates all the new files.Thanx a lot for helping me again. I'll be grateful and invite my wife for a dinner with the time saved ;-))) –  Marc May 29 '13 at 19:58
    
@Marc: The loop is easily achieved. Just go to the directory with the PDFs and at the command prompt type for %a in (*.pdf) do @pdftk "%~a" cat 1-end 1-end output "%~na (Duplicated)%~xa". For each in.pdf (name can be anything), this will result in a corresponding in (Duplicated).pdf. Enjoy your dinner and don't forget to accept the answer (click the green check mark to the left) if it helped you! –  Karan May 30 '13 at 14:06
    
infinete thanks to you - you have saved my life! I am very very grateful for your help! –  Marc May 30 '13 at 19:19
add comment

I might give you a better solution if you answer the questions in my comment but for the sake of your wife, here are couple of suggestions.

ImageMagick is a cross-platform command line tool for image manipulation. Once you install it, you should be able to use its convert tool to do what you want. The details depend on your operating system. I am assuming you want two copies of the entire file, not each page doubled.

  1. Linux/OSX/Unix etc

    for n in *pdf; do convert -density 150 "$n" "$n" "$n"; done
    

    This will overwrite the existing files, you may want to backup first.

  2. Windows. This may well be slightly wrong, I don't use Windows so I cannot test it but the general idea should be something like this

    for %f in (*.pdf) do (convert.exe %f %f %f)
    
share|improve this answer
    
Your for loop is missing the done and $n should probably be quoted. Maybe I'm missing how convert works, but what does convert do when you pass three times the same file? I can't test it right now. –  slhck May 28 '13 at 20:51
    
Thanks @slhck, you're right on both counts as usual. The general convert format is convert infile1 infile2 ... infileN outfile. So, if you pass it the same file three times it will take it twice as input and then write to the same file as output. That one I did test :). –  terdon May 28 '13 at 21:29
    
Oh, cool, then I learned something as well :) –  slhck May 28 '13 at 21:30
    
Sounds good to me. Thanks a lot. The comment above: I gave that one the first try and it worked perfectly, only the right loop I am still seraching for.... could you help me again? Many thanks in advance! –  Marc May 30 '13 at 5:50
    
@Marc sorry, I'm not sure what you mean. Which comment? Which loop? The windows or the bash one? –  terdon May 30 '13 at 14:16
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.