Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.postscript > #131
| From | ken <ken@spamcop.net> |
|---|---|
| Newsgroups | comp.lang.postscript |
| Subject | Re: PDF: multiple slides per page to one slide per page? |
| Date | 2011-04-25 12:03 +0100 |
| Message-ID | <MPG.281f65484753c352989831@usenet.plus.net> (permalink) |
| References | (1 earlier) <MPG.27e30eeb4abd417798981e@usenet.plus.net> <fb141551-05f0-47a3-8ef3-418c2bfc4dce@h9g2000pre.googlegroups.com> <MPG.281cfc403305e78498982f@usenet.plus.net> <3e3f53ca-2bf5-428a-b6ea-12da34cb3aeb@34g2000pru.googlegroups.com> <MPG.281d4705d8cb0a10989830@usenet.plus.net> |
In article <MPG.281d4705d8cb0a10989830@usenet.plus.net>, ken@spamcop.net
says...
> I believe you have the page offsets incorrect, I changed them and was
> able to get decent output. I'm working on a better PostScript program,
> now I have a good idea of what's required.
And below is the PostScript program, I hope UseNet doesn't mess up the
line endings. If cut&paste doesn't work let me know an address I can
mail the file to.
I used the example file you posted a link to, with the following command
line:
c:\gs-scratch\bin>gswin32c -dBATCH -dNOPAUSE -sFile=\temp\BMB170c_2011_
04_21_LECTURE.pdf -dSubPagesX=2 -dSubPagesY=2 -dFIXEDMEDIA -
dDEVICEHEIGHTPOINTS=288.36 -dDEVICEWIDTHPOINTS=378.36 -sDEVICE=pdfwrite
-sOutputFile=\temp\out.pdf \temp\pdf_slice.ps
Now the way this works is that you start by setting the page size to the
size of the individual slides (or sub-pages). You also set the -
dFIXEDMEDIA switch to true which prevents the PDF interpreter from
changing the page size.
The program uses this size, the original page size from the PDF file and
the number of sub-pages in each direction to calculate any margins
surroundnig the sub-page group (your file has a 17 point margin all the
way round).
Then, using the SubPageOrder it draws each of the sub pages in the
required order, shifting the page as it does so. The page size set at
the command line acts like a window, anything which is visible
underneath it is what gets drawn.
For me the command line above produced 64 pages with content. I have to
warn you, however, that the original PDF file seems to use clipping
paths to remove some content from some pages. Unfortunately this is not
working reliably and some pages contain content that I believe should
have been clipped.
This does not happen if I simply pass the original file through
pdfwrite, so its a consequence of the PageOffset being applied. I guess
that there are some comditions where the PDF interpreter is not moving
the clip region in line with the PageOffset. Feel free to open a bug
report on it at
http://bugs.ghostscript.com
But I should probably warn you that it may be some time before it gets
addressed, as the engineers are very busy at the moment.
8<-------------------8<------------------------8<-------------------8<
%!PS
% Copyright (C) 2011 Artifex Software, Inc. All rights reserved.
%
% This software is provided AS-IS with no warranty, either express or
% implied.
%
% This software is distributed under license and may not be copied,
% modified or distributed except as expressly authorized under the terms
% of the license contained in the file LICENSE in this distribution.
%
% For more information about licensing, please refer to
% http://www.ghostscript.com/licensing/. For information on
% commercial licensing, go to http://www.artifex.com/licensing/ or
% contact Artifex Software, Inc., 101 Lucas Valley Road #110,
% San Rafael, CA 94903, U.S.A., +1(415)492-9861.
%
% Slice up a PDF file
%
% usage: gs -sFile=____.pdf -dSubPagesX= -dSubPagesY= [-dSubPageOrder=]
[-dVerbose=]pdf_slice.ps
%
% SubPageOrder is a bit field;
% Default = 0
% Bit 0 - 0 = top to bottom
% 1 = bottom to top
% Bit 1 - 0 = left to right
% 1 = right to left
% Bit 3 - 0 = increase x then y
% - 1 = increase y then x
%
% 0 - page 1 at top left, increasing left to right, top to bottom
% 1 - page 1 at bottom left increasing left to right, bottom to top
% 2 - page 1 at top right, increasing right to left, top to bottom
% 3 - page 1 at bottom right increasing right to left, bottom to top
% 4 - page 1 at top left, increasing top to bottom, left to right
% 5 - page 1 at bottom left increasing bottom to top, left to right
% 6 - page 1 at top right, increasing top to bottom, right to left
% 7 - page 1 at bottom right increasing bottom to top, right to left
%
% Check the parameters to see they are present and of the correct type
%
/Usage {
( usage: gs -dNODISPLAY -q -sFile=____.pdf \n) =
( -dSubPagesX= -dSubPagesY= [-dSubPageOrder=] pdf_slice.ps \n) =
(Please see comments in pdf_slice.ps for more details) =
flush
quit
} bind def
/Verbose where not {
/Verbose false def
}{
pop /Verbose true def
} ifelse
/File where not {
(\n *** Missing source file. \(use -sFile=____.pdf\)\n) =
Usage
} {
pop
}ifelse
/SubPagesX where not {
(\n *** SubPagesX not integer! \(use -dSubPagesX=\)\n) =
Usage
} {
Verbose { (SubPagesX ) print } if
SubPagesX type
Verbose { dup == } if
/integertype eq not {
(\n *** SubPagesX not integer! \(use -dSubPagesX=\)\n) =
Usage
}
pop
}ifelse
/SubPagesY where not {
(\n *** SubPagesY not integer! \(use -dSubPagesY=\)\n) =
Usage
} {
Verbose { (SubPagesY ) print } if
SubPagesY type
Verbose { dup == } if
/integertype eq not {
(\n *** SubPagesY not integer! \(use -dSubPagesY=\)\n) =
Usage
}
pop
}ifelse
/SubPageOrder where not {
/SubPageOrder 0 def
} {
Verbose { (SubPageOrder ) print } if
SubPageOrder type
Verbose { dup == } if
dup ==
/integertype eq not {
(\n *** SubPageOrder not integer! \(use -dSubPageOrder=\)\n) =
Usage
}
pop
}ifelse
%
% Turns off most messages
%
/QUIET true def % in case they forgot
%() =
%
% Open the PDF file and tell the PDF interpreter to start dealing with
it
%
File dup (r) file runpdfbegin pop
/PDFPageCount pdfpagecount def
%
% Set up our bookkeeping
%
% First get the size of the page from page 1 of the PDF file
% We assume that all PDF pages are the same size.
%
1 pdfgetpage currentpagedevice
1 index get_any_box
exch pop dup 2 get exch 3 get
/PDFHeight exch def
/PDFWidth exch def
%
% Now get the page size of the current device. We are assuming that
% this is the size of the individual sub-pages in the original PDF. NB
% This assumes no margins between sub-pages, all sub-pages the same
size.
%
currentpagedevice /PageSize get
dup 0 get /SubPageWidth exch def
1 get /SubPageHeight exch def
%
% Calculate the margins. This is the margin between the page border and
% the enclosed group of sub-pages, we assume there are no borders
% between sub pages.
%
/TopMargin PDFHeight SubPageHeight SubPagesY mul sub 2 div def
/LeftMargin PDFWidth SubPageWidth SubPagesX mul sub 2 div def
Verbose {
(PDFHeight = ) print PDFHeight ==
(PDFWidth = ) print PDFWidth ==
(SubPageHeight = ) print SubPageHeight ==
(SubPageWidth = ) print SubPageWidth ==
(TopMargin = ) print TopMargin ==
(LeftMmargin = ) print LeftMargin ==
} if
%
% This rouitne calculates and sets the PageOffset in the page device
% dictionary for each subpage, so that the PDF page is 'moved' in such
% a way that the required sub page is under the 'window' which is the
current
% page being imaged.
%
/NextPage {
SubPageOrder 2 mod 0 eq {
/H SubPagesY SubPageY sub SubPageHeight mul TopMargin add
def
}{
/H SubPageY 1 sub SubPageHeight mul TopMargin add def
} ifelse
SubPageOrder 2 div floor cvi 2 mod 0 eq {
/W SubPageX 1 sub SubPageWidth mul LeftMargin add def
}{
/W SubPagesX SubPageX sub SubPageWidth mul LeftMargin add
def
} ifelse
<< /PageOffset [W neg H neg]>> setpagedevice
Verbose {
(SubPageX ) print SubPageX ==
(SubPageY ) print SubPageY ==
(X Offset ) print W ==
(Y Offset ) print H == flush
} if
PDFPage
} bind def
%
% The main loop
% For every page in the original PDF file
%
1 1 PDFPageCount
{
/PDFPage exch def
% Do the gross ordering here rather than in
% NextPage. We eiither process rows and then
% columns, or columns then rows, depending on
% Bit 3 of SubPageorder
SubPageOrder 3 le {
1 1 SubPagesY {
/SubPageY exch def
1 1 SubPagesX {
/SubPageX exch def
NextPage
pdfgetpage
pdfshowpage
} for
} for
} {
1 1 SubPagesX {
/SubPageX exch def
1 1 SubPagesY {
/SubPageY exch def
NextPage
pdfgetpage
pdfshowpage
} for
} for
} ifelse
} for
8<-------------------8<------------------------8<-------------------8<
Back to comp.lang.postscript | Previous | Next — Previous in thread | Next in thread | Find similar
Re: PDF: multiple slides per page to one slide per page? David Mathog <dmathog@gmail.com> - 2011-04-22 09:03 -0700
Re: PDF: multiple slides per page to one slide per page? David Mathog <dmathog@gmail.com> - 2011-04-22 10:41 -0700
Re: PDF: multiple slides per page to one slide per page? ken <ken@spamcop.net> - 2011-04-22 19:36 +0100
Re: PDF: multiple slides per page to one slide per page? David Mathog <dmathog@gmail.com> - 2011-04-22 13:01 -0700
Re: PDF: multiple slides per page to one slide per page? ken <ken@spamcop.net> - 2011-04-22 21:50 +0100
Re: PDF: multiple slides per page to one slide per page? ken <ken@spamcop.net> - 2011-04-22 19:33 +0100
Re: PDF: multiple slides per page to one slide per page? ken <ken@spamcop.net> - 2011-04-23 16:10 +0100
Re: PDF: multiple slides per page to one slide per page? David Mathog <dmathog@gmail.com> - 2011-04-23 08:50 -0700
Re: PDF: multiple slides per page to one slide per page? ken <ken@spamcop.net> - 2011-04-23 21:29 +0100
Re: PDF: multiple slides per page to one slide per page? ken <ken@spamcop.net> - 2011-04-25 12:03 +0100
Re: PDF: multiple slides per page to one slide per page? David Mathog <dmathog@gmail.com> - 2011-04-26 08:40 -0700
Re: PDF: multiple slides per page to one slide per page? ken <ken@spamcop.net> - 2011-04-26 17:21 +0100
Re: PDF: multiple slides per page to one slide per page? David Mathog <dmathog@gmail.com> - 2011-04-26 13:23 -0700
Re: PDF: multiple slides per page to one slide per page? ken <ken@spamcop.net> - 2011-04-27 08:31 +0100
csiph-web