0

I need the arguments for the ghostscript in order to convert a double-up pdf page to a simple column pdf page

the input
+--------+-------+
|        |        |          
|        |        |          
|        |        |         
| 1      |    2   |             
|        |        |           
|        |        |           
+--------+--------+   

the output
 +-------+
|        |        
|   1    |   
|        |        
|        |        
|        |       
|        |     
+--------+
 +-------+
|        |        
|   2    |   
|        |        
|        |        
|        |       
|        |     
+--------+

So depending on these two posts post1 and post2 I created this code

import sys
import locale
import ghostscript

args = [

    "-ooutput.pdf",
    "-sDEVICE=pdfwrite",
    "-g2807x5950"
    "-fpdfFile.pdf"
    ]

# arguments have to be bytes, encode them
encoding = locale.getpreferredencoding()
args = [a.encode(encoding) for a in args]

ghostscript.Ghostscript(*args)

I expeced a 2 page pdf file but a fatal error was raised

Edit: this is the error message enter image description here

  • Firstly, you have a problem with the specification of the output file, you have put "-ooutput.pdf" when it should be "-o output.pdf". You haven't said what the error actually is, so I can't tell if that's the problem. Seems likely though. Your approach isn't going to turn one page into 2, its just going to produce a PDF file where the original pages are cropped down. You could also look at this question: https://stackoverflow.com/questions/14487656/splitting-single-page-into-two-pages-with-ghostscript/14497102#14497102 – KenS Aug 08 '19 at 11:41
  • @KenS Thank you for your reply. it's not the problem, I made it "-o output.pdf" as you said but it's the same error, the error is in this line `ghostscript.Ghostscript(*args)` I added the error message in the post, please read it. –  Aug 08 '19 at 12:43

1 Answers1

0

If you read the text its says "Device pdfwrite requires an output file but no file was specified". So that tells you that -o was ignored, or there was some other problem with it.

I suspect you are using the Ghostscript DLL, rather than forking a process, in which case you have to set argv[0] to a dummy value. The reason is that, when running a C program, argv[0] is the name of the executable. So the args processing skips over the 0th element of the args array.

This is covered in the Ghostscript documentation here

NB there also looks like a missing '.' in your argument list, but I don't speak Python so I could be wrong.

You probably need to change your args to something like:

args = [
    "MyApp",
    "-o output.pdf",
    "-sDEVICE=pdfwrite",
    "-g2807x5950",
    "-fpdfFile.pdf"
    ]
KenS
  • 30,202
  • 3
  • 34
  • 51