2

How do I write code using AIC (Acrobat Interapplication Communication) to load a PDF file and output the equivalent Postscript file? Using Acrobat X interactively, I would open the file, then use the menu File > Save As... > More Options... > PostScript.

Ideally, I would like to do this from a Windows Service program without displaying any window on the machine console.

I have installed Acrobat X Pro and I have downloaded the Acrobat SDK.

I'd prefer code samples in C#, but I can convert from VB or C++ if needed.

randomfactor
  • 479
  • 3
  • 11

3 Answers3

1

For the latest version of Ghostscript (which is v9.02), a suitable commandline would be:

gswin32c.exe ^
  -o output.ps ^
  -sDEVICE=ps2write ^
   input.pdf
Kurt Pfeifle
  • 86,724
  • 23
  • 248
  • 345
  • Ghostscript is not a suitable option for my needs. Adobe Acrobat is the requirement. – randomfactor May 16 '11 at 16:12
  • I'm reversing myself now. I am aware of a clever bit of code which enables Enfocus PowerSWITCH to do exactly what I had hoped to accomplish. However, their technique involves subtle magick to get around the javascript sandbox security mechanisms which I was not able to work out satisfactorily. – randomfactor Sep 23 '11 at 19:46
  • It seems that Adobe is Acrobat's worst enemy. Why would they bake something into the UI which is unavailable through their programming API? – randomfactor Sep 23 '11 at 19:48
1

Another alternative for you may be to call Acrobat Reader (or Professional?) with commandline switches to have it convert your PDF to PostScript. On Linux (Ubuntu Natty) at least this is what version 9.4.2 of Acrobat Reader offers (not sure if the Windows version offers exactly the same CLI switches):

kp@s42:~$  acroread -help
Usage: acroread [options] [list of files] 
Run 'acroread -help' to see a full list of available command line options.
------------------------

Options:
    --display=<DISPLAY>                                          This option specifies the host and display to use.
    --screen=<SCREEN>                                            X screen to use. Use this options to override the screen part of the DISPLAY environment variable.
    --sync                                                       Make X calls synchronous. This slows down the program considerably.
    -geometry [<width>x<height>][{+|-}<x offset>{+|-}<y offset>] Set the size and/or location of the document windows.
    -help                                                        Prints the common command-line options.
    -iconic                                                      Launches in an iconic state on the desktop.
    -info                                                        Lists out acroread Installation Root, Version number, Language.
    -tempFile                                                    Indicates files listed on the command line are temporary files and should not be put in the recent file list.  
    -tempFileTitle <title>                                       Same as -tempFile, except the title is specified.
    -toPostScript                                                Converts the given pdf_files to PostScript.
    -openInNewInstance                                           It launches a new instance of acroread process. 
    -openInNewWindow                                             Same as OpenInNewInstance. But it is recommended to use OpenInNewInstance. openInNewWindow will be deprecated.
    -installCertificate <server-ip> <server-port>                Fetches and installs client-side certificates for authentication to access the server while creating secured connections.
    -installCertificate [-PEM|-DER] <PathName>                   Installs the certificate in the specified format from the given path to the Adobe Reader Certificate repository.
    -v, -version                                                 Print version information and quit.
    /a                                                           Switch used to pass the file open parameters.


Forms of using -toPostScript
    -toPostScript [options] pdf_file ... [ps_dir]
    -toPostScript [options] -pairs pdf_file_1 ps_file_1 ...
    -toPostScript [options]
    Note: When using -toPostScript it must be the first argument passed in on the command line.

Valid options for the conversion of PDF to PostScript:

    -binary                                                      emit binary PostScript where possible.
    -start <int>                                                 identify the first page in the document to be converted (default is the first page of the document).
    -end <int>                                                   identify the last page in the document to be converted (default is the last page of the document).
    -optimizeForSpeed                                            emit PostScript such that all fonts are emitted once at the beginning of the document. 
    -landscape                                                   rotate the pages to print landscape.
    -reverse                                                     reverse the page order of the output.
    -odd                                                         emit only odd-numbered pages.
    -even                                                        emit only even-numbered pages.
    -commentsOff                                                 don't print comments.
    -annotsOff                                                   don't print annots.
    -stampsOff                                                   don't print stamps.
    -markupsOn                                                   print document and markups.
    -level2                                                      emit Level 2 PostScript.
    -level3                                                      emit Level 3 PostScript.
    -printerhalftones                                            use the printer default halftones.
    -saveVM                                                      download fonts as needed to preserve printer memory.
    -shrink                                                      shrink the pages to fit the page size.
    -expand                                                      expand the pages to fit the page size.
    -size <pagesize>                                             set the page size.
    -transQuality level                                          set the transparency flattening level. Value from 1-5.
    -printerName <name>                                          this is to print device-dependent PS.
    -rotateAndCenter                                             auto-rotate and center the pages.
    -choosePaperByPDFPageSize                                    use the pdf page size to determine the output tray.
    -nUp <hpage> <vpage> <pageorder> border rotate               print multiple pages on the same sheet of paper.
    -booklet <subset> <binding> rotate <from> <to>               prints multiple pages on the same sheet of paper in the order required to read correctly when folded.


For detailed description on the options please visit the manpage.
Kurt Pfeifle
  • 86,724
  • 23
  • 248
  • 345
  • Neither acrobat, nor acrord32 offer any command line options on windows. – randomfactor May 16 '11 at 22:17
  • @randomfactor: That's not true! I know for a fact that acrord32.exe **does** offer **some** commandline options for printing... I just don't know what's the difference to the Linux version, and I'm too lazy right now to research this. -- So, it is not an option for you to use Linux for this task? – Kurt Pfeifle May 16 '11 at 22:45
  • OK, you are right. I tried /h /help --help /? and the usual suspects. But these are unsupported command line options and there is no built-in "help" message. This info can be found in the Adobe Acrobat SDK Developer [FAQ on page 27:](http://partners.adobe.com/public/developer/en/acrobat/sdk/pdf/intro_to_sdk/DeveloperFAQ.pdf) – randomfactor May 17 '11 at 16:19
0

Maybe it would be a better idea to use Ghostscript instead. In the simplest use case, a simple call to it as an external process with command line parameters will make the conversion for you - but there are several ways of getting better integration - up to creating a Postscript virtual printer.

jsbueno
  • 99,910
  • 10
  • 151
  • 209
  • Ghostscript is not an option for my purpose. My colleague insists that ghostscript has been the source of many printing problems in the past. It may be fine for files that are only intended for viewing on a monitor, but not for commercial print. Therefore, I cannot accept this answer. – randomfactor May 16 '11 at 16:08
  • @randomfactor: Ghostscript has improved a **lot** in the recent 4-5 releases. However, your colleague was right: the commandline switch of olden times `-sDEVICE=pswrite` did output PostScript Level 1 and that was not too good for further processing. You should at least give a try to the `ps2write`-output of the most recent version (9.02) before you deem it not suitable. – Kurt Pfeifle May 16 '11 at 17:00