I'm looking for a solution that will allow me to do the following to PDF documents:
- Insert PDF pages into existing开发者_StackOverflow中文版 PDF documents
- Delete PDF pages from existing PDF documents
- Change the orientation of certain PDF pages
Any solutions I should be looking at? My output needs to be PDF.
Since you found out already...
* ...how to separate multipage PDF documents into singlepage files, and
* ...how to re-combine multiple PDF documents into a single one
using Ghostscript, here is how to rotate pages. However, this does not work reliably, because it depends on Ghostscript's ability to discover the main flow of text orientation on each page:
* -dAutoRotatePages=/None
-- retains orientation of each page;
* -dAutoRotatePages=/All
-- rotates all pages (or none) depending on a kind of "majority decision";
* -dAutoRotatePages=/PageByPage
-- auto-rotates pages individually.
Add one of these to the Ghostscript commandline you're using.
If there is no text on a page (or if there is an automatic page rotation set to /None
), then Ghostscript uses the setpagedevice
settings. You can pass such setpagedevice
parameters on the Ghostscript commandline using the -c
switch like this:
* -c "<</Orientation 3>> setpagedevice"
-- sets landscape orientation;
* -c "<</Orientation 0>> setpagedevice"
-- sets portrait orientation;
* -c "<</Orientation 2>> setpagedevice"
-- sets upside down orientation;
* -c "<</Orientation 1>> setpagedevice"
-- sets seascape orientation.
Probably you need to set the orientation for each page when extracting the pages. I don't think it would work when merging them back to the unified document (I have never tested this).
However, I'd also recommend to you that you have a look at pdftk
(which is also available for Windows). It is a commandline tool that can extract pages from PDFs, merge multiple PDF files, rotate pages, and much more. Easier to use than Ghostscript for your stated purposes, and much faster as well. See here for details: http://www.accesspdf.com/pdftk/ .
If you're looking for a standalone tool, pdftk is capable of all those things
Now that StackOverflowNewbie has clarified he doesn't want a standalone commandline tool, but a library: iText
is the basis of the pdftk
commandline utility he rejected as a suitable solution for his requirements. And its a library.
精彩评论