Gs to split a pdf into multiple pages


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Gs to split a pdf into multiple pages
# 1  
Old 07-24-2013
Gs to split a pdf into multiple pages

Hello,

Some googling and checking the man pages told me it should be possible to split a pdf (or ps) file into individual pages :

Code:
man gs

You  might  want  to  print each page separately.  To do this, send the
       output to a series of files "foo1.xyz, foo2.xyz, ..." using the "-sOut-
       putFile=" switch with "%d" in a filename template:

            -sOutputFile=foo%d.xyz

So I tried splitting a file containing two pages :
Code:
gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=un_nostop%d.pdf un_nostop.pdf

but only one file (un_nostop1.pdf) containing the two pages is created ...

I tried with other pdf files, and the result is always the same.

What's the problem ? It must be right there, but I can't see it ...

Thanks,
Jos
# 2  
Old 07-24-2013
Hi.

See also utilities like:
Code:
pdftk
Description: useful tool for manipulating PDF documents
 If PDF is electronic paper, then pdftk is an electronic stapler-remover,
 hole-punch, binder, secret-decoder-ring, and X-Ray-glasses. Pdftk is a
 simple tool for doing everyday things with PDF documents. Keep one in the
 top drawer of your desktop and use it to:
  - Merge PDF documents
  - Split PDF pages into a new document
...

Best wishes ... cheers, drl
# 3  
Old 07-25-2013
Yes, of course, there are other ways to do this, like with pdftk :

Code:
pdftk cinq_nostop.pdf burst output cinq_nostop%02d.pdf

Strangely, but luckily, it also works when I ask ghostscript to create ps files :

Code:
gs -dBATCH -dNOPAUSE -sDEVICE=pswrite -sOutputFile=cinq_nostop%03d.ps cinq_nostop.ps

The problem seems to be related to the pdfwrite device : splitting a pdf in ps files works, but not the other way round.

Best,
Jos
# 4  
Old 08-26-2013
How about this code
Code:
namespace RE__Test
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        public static string FolderName = "c:/";

        private void button1_Click(object sender, EventArgs e)
        {
            string fileName = FolderName + "Sample.pdf";

            REDocument doc = REFile.OpenDocumentFile(fileName, new PDFDecoder());//use PDFDecoder open a pdf file

            List<BaseDocument> baseDocs = doc.SplitDocument(1);

            int index = 0;

            foreach (BaseDocument baseDoc in baseDocs)
            {
                // REImage reimage = (REImage)baseDoc.GetPage(0).ToImage();
                index++;

                REFile.SaveDocumentFile((REDocument)baseDoc, "c:/reDoc" + index + ".pdf", new PDFEncoder());
            }


Last edited by Franklin52; 08-26-2013 at 03:15 AM.. Reason: Please use code tags
 
Login or Register to Ask a Question

Previous Thread | Next Thread

5 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Split a text file into multiple pages based on pattern

Hi, I have a text file (attached the sample). I have also, attached the way the way the files need to be split. We get this file, that will either have 24 Jurisdictions, or will miss some and retain some. Like in the attached sample file, there are only Jurisdictions 03,11,14,15, 20 and 30.... (3 Replies)
Discussion started by: ebsus
3 Replies

2. UNIX for Advanced & Expert Users

creating pdf file with four pages

I have some code in fortran90, example stored in scode.f90 and I want to create a pdf containing the code. I would like to have four pages of code put into each page in the pdf. I was thinking of creating a ps file using mpage and then using ps2pdf after. However, I noticed that ps2pdf shift the... (4 Replies)
Discussion started by: kristinu
4 Replies

3. Shell Programming and Scripting

[Example] View man pages as pdf

This is a simple example of a shell script. I made it because it's sometimes convenient to search through a manpage and to have access to the terminal while you're reading (maybe to test code). It also serves as a basic example for anyone learning shell scripting. #!/bin/sh nm="/tmp/$1.pdf"... (0 Replies)
Discussion started by: CRGreathouse
0 Replies

4. Shell Programming and Scripting

how to get number of pages in a PDF file

Hello, Can anyone please help me providing script to get the number of pages in a PDF file? TIA Prvn (8 Replies)
Discussion started by: prvnrk
8 Replies

5. UNIX for Dummies Questions & Answers

Split text file by pages

Hello! Firts of all, I'm sorry for my English. My problem: I have text file with few Form Feed symbols (FF, ASCII code =12) inside (for example - some report, consists of some pages for printing). I want to split this text by pages - each page (until FF symbol) in single file. I... (2 Replies)
Discussion started by: ranri
2 Replies
Login or Register to Ask a Question