This post is a follow-up of "How do I crop pages 3&4 in a multipage pdf using ghostscript", but it changes the input to an array of data.
The quest: I have a pdf file (a set of drawings) where all pages have the same size and I want to crop some pages in one way and others differently. The following screenshot shows how I generated the data below for cropping:spreadsheet The "left,bottom,right,top" are to be handed over to the postscript /CropBox [934 350 3318 2034] command. Pagenumbers are just consecutive numbers, so they may not rally be needed.
page#,left,bottom,right,top
1 0 0 4252 2384
2 0 0 4252 2384
3 0 0 4252 2384
4 0 0 4252 2384
5 934 350 3318 2034
6 934 350 3318 2034
7 441 0 3811 2384
8 441 0 3811 2384
With the solution in the above mentioned question I was able to crop a specific page in an multipage pdf and it probably is a good starting point for a solution to this question. I just didn't figure it out on my own.
The relevant postscript code which tried to use as a base to solve this problem is (thanks to KenS):
<<
/EndPage {
0 eq {
pop /Page# where {
/Page# get
3 eq {
(page 3) == flush
[/CropBox [0 0 1612 1792] /PAGE pdfmark
true
}
{
(not page 3) == flush
[/CropBox [500 500 612 792] /PAGE pdfmark
true
} ifelse
}{
true
} ifelse
}
{
false
}
ifelse
}
>> setpagedevice
I guess we need some test numbers for "realistic" page sizes for my crazy page size dictionary... just for some fun testing.
/MyCrazyPageSizeDictionary begin
/PageSizeArray [
[0 0 595 842] % original A4 portrait
[87 123 508 719] % cut to A5
[149 210 446 631] % cut to A6
[192 272 403 570] % cut to A7
[223 316 372 526] % cut to A8
] def