Ghostscript:PDF总页数 [英] Ghostscript: PDF total pages

查看:160
本文介绍了Ghostscript:PDF总页数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Ghostscript库API(从C#包装)来从我的应用程序中打印PDF文档.
使用' -dFirstPage '和' -dLastPage '参数,我可以选择要打印的页面范围,但是PDF页面的总数如何呢? ?

I'm using Ghostscript library API (wrapping from C#) to print PDF documents from my application.
With the '-dFirstPage' and '-dLastPage' parameters I'm able to select an range of pages to be printed, but how about the total number of a PDF's pages?

当PDF文档只有4页时,允许用户选择2到10的页面间隔不是很好.

It is not very nice to allow a user to select a page interval from 2 to 10 when, let me say, the PDF document has only 4 pages.

考虑通过 gsapi_init_with_args API库调用使用Ghostscript库.

Consider that I'm using Ghostscript library through the gsapi_init_with_args API library call.

推荐答案

Ghostscript可以在stdout上计数并显示PDF的页数.命令行是

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" 

所有-c "..."内容都是PostScript命令行摘要(使用一些GS内部命令扩展名). input.pdf 是PDF文件名(也可以是完整路径,例如(c:/path/to/my.pdf)).

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)).

但是,这种工作的更好,更快的工具是使用pdfinfo(XPDF实用程序的一部分,也可在Windows上使用).

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想知道是否可以修改我的示例命令行,以便它也可以通过一次操作显示 PDF.试试这个:

@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.

这篇关于Ghostscript:PDF总页数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆