Split multi page PDF file into single pages

10,076

Solution 1

The most recent version of Ghostscript (v9.06) can do this too. Here is the commandline to be used inside a cmd.exe 'DOS-Box' window on a 32-bit Windows system:

 gswin32c.exe                ^
   -o original_page_%03d.pdf ^
   -sDEVICE=pdfwrite         ^
   -sPDFSETTINGS=/prepress   ^
    original-multipage.pdf

-o ...: this indicates the name of the output file(s).
%03d: this part of the filename will be translated into 3-digit numbers, padded by leading 0s, starting from 001 for the first page.
-sPDFSETTINGS=...: is an optional parameter; if used will ensure that all used fonts are embedded and some other settings which in general ensure a high quality output.

Ghostscript is available for Windows. (The link above leads you to the installers: gs906w32.exe and gs906w64.exe. Scroll down to find them...).

Solution 2

You can use Pdftk

exec("pdftk " . $pdflargeFile . " burst output " . $outputPath);
Share:
10,076
Muhammad Qasim
Author by

Muhammad Qasim

Updated on June 26, 2022

Comments

  • Muhammad Qasim
    Muhammad Qasim almost 2 years

    Possible Duplicate:
    Split PDF documents into separate pages using PHP (or possibly perl)

    How can I split a multi-page PDF file into distinct single page PDF files in PHP on Linux server? Are there any PHP libraries or free command line tools available to do this?

  • Muhammad Qasim
    Muhammad Qasim over 11 years
    can this be used on windows also???
  • Baba
    Baba over 11 years
    yes it runs on windows see pdflabs.com/docs/install-pdftk
  • Muhammad Qasim
    Muhammad Qasim over 11 years
    Does this snippet will work on windows with ghostscript v9.05?
  • Muhammad Qasim
    Muhammad Qasim over 11 years
    It didn't work. Are you sure its for splitting pdf file or for joining???
  • Muhammad Qasim
    Muhammad Qasim over 11 years
    Kurt, can you please explain it a bit more. I didn't get it. Thanks
  • Baba
    Baba over 11 years
    See : pdflabs.com/docs/pdftk-cli-examples Split Select Pages from Multiple PDFs into a New Document pdftk A=one.pdf B=two.pdf cat A1-7 B1-5 A8 output combined.pdf
  • Baba
    Baba over 11 years
    Use pdftk largepdfile.pdf burst and tell me that you get
  • Muhammad Qasim
    Muhammad Qasim over 11 years
    Yes thats what I wanted but using "burst" in this way also creates a text file. Anyway to escape this?
  • Muhammad Qasim
    Muhammad Qasim over 11 years
    OK. Will I be able to use it on Linux in the same way? if not what I would need to change?
  • Baba
    Baba over 11 years
    @Muhammad Qasim it something simple and not enough for you to change
  • Muhammad Qasim
    Muhammad Qasim over 11 years
    I think .exe will not run on Linux (don't know much about Linux), how to install it for Linux and how to add it to the PATH?
  • Kurt Pfeifle
    Kurt Pfeifle over 11 years
    @MuhammadQasim: Why, do you think, did I explicitely write 'the most recent version of Ghostscript'? And why did I even quote that version, you think?! -- So no, it doesn't work with v9.05.
  • Kurt Pfeifle
    Kurt Pfeifle over 11 years
    @MuhammadQasim: I updated the answer to add some better explanation of the individual parameters used.
  • Martin Schröder
    Martin Schröder over 11 years
    @MuhammadQasim: Do you need that for Linux (as you say in your question) or Windows or ...?
  • Baba
    Baba over 11 years
    It Supporst Linux FeeBDS , Ubuto or SuSE RMP .... already given you installation link pdflabs.com/docs/install-pdftk
  • MrCalvin
    MrCalvin over 6 years
    if it does require java it should have been specified in the answer