Ghostscript: PDF total pages

后端 未结 2 1245
余生分开走
余生分开走 2020-12-14 18:21

I\'m using Ghostscript library API (wrapping from C#) to print PDF documents from my application.
With the \'-dFirstPage\' and \'-dLastPage\' parameter

相关标签:
2条回答
  • 2020-12-14 18:41

    I tried to make this script:

    gswin32c ^
      -q ^
      -c "(input.pdf) (r) file runpdfbegin pdfpagecount =" ^
      -f input.pdf
    

    work in a c# wrapped solution and kept getting error "/undefinedfilename". In this case ensure that your filepath has Slashes "/" as DirectorySeperator and not Backslashes "\". I know Kurt Pfeifle already wrote it, but it happened to me i just overlooked it.

    0 讨论(0)
  • 2020-12-14 18:48

    Ghostscript can count and display the number of pages of a PDF on stdout. The commandline is

    gswin32c ^
      -q ^
      -dNODISPLAY ^
      -c "(input.pdf) (r) file runpdfbegin pdfpagecount = quit" 
    

    Here all the -c "..." stuff is a PostScript commandline snippet (using a few GS internal command extensions). And input.pdf is the PDF filename (could also be a full path like (c:/path/to/my.pdf)).

    However, a better and faster tool for this kind of job would be to use pdfinfo (part of the XPDF-utilities, also available on Windows).


    Update:

    @ebyrob wants to know if one can modify my example command line so that it also displays the PDF in a single operation. Try this:

    gswin32c ^
      -q ^
      -c "(input.pdf) (r) file runpdfbegin pdfpagecount =" ^
      -f input.pdf
    

    Well, it's not a single operation -- it's just two different operations in a single commandline.

    0 讨论(0)
提交回复
热议问题