Reputation: 21
I have the following postscript code snippet. What it does is read a PDF filename from an array ConvertItem get the page information for this through getfirstpagesize and store the values that are coming out of this back in the array ConvertItem (8 - 9). This used to work perfectly until ghostscript 9.27. In this version the pdfdict is deprecated.
/ConvertItems
[
[ (...) (...) <...> (...) (...) () 0 0 0 0 0 0 ]
] def
/getfirstpagesize
{
1 1 1
{
pdfgetpage /MediaBox pget dup pop
{
/MediaBox exch def
/PageWidth MediaBox 2 get def
/PageHeight MediaBox 3 get def
} if
(First page - width [) print PageWidth 10 string cvs print
(], height [) print PageHeight 10 string cvs print
(]\n) print
} for
} bind def
------- snip -------
ConvertItem 0 get (r) file"
pdfdict begin"
pdfopen begin"
getfirstpagesize"
ConvertItem 8 PageWidth put"
ConvertItem 9 PageHeight put"
currentdict pdfclose"
end % temporary dict"
end % pdfdict"
------- snip -------
I tried to solve it by using pdfrunbegin and pdfrunend like this
------- snip -------
ConvertItem 0 get (r) file
runpdfbegin
getfirstpagesize
ConvertItem 8 PageWidth put
ConvertItem 9 PageHeight put
runpdfend
(*First page - width [) print ConvertItem 8 get 10 string cvs print
(], height [) print ConvertItem 9 get 10 string cvs print
(]\n) print
------- snip -------
But when I try to print the ConvertItem 8 and 9 value then these are always 0 so it seems like runpdfend is clearing the memory that is shared with these values. So my question is if there is some way around this?
Upvotes: 1
Views: 174
Reputation: 21
Well it seems that runpdfbegin does a save of the interpreter memory and restores that after runpdfend is executed. This is the reason why the value gets "reset" to it's devault value. To work around this problem the PageWidth and PageHeight variables have to be stored in the globaldict, this doesn't get reset when the memory of the interpreter is restored.
/getfirstpagesize
{
1 1 1
{
pdfgetpage dup
/MediaBox pget
{
/MediaBox exch def
true setglobal
globaldict begin
/PageWidth MediaBox 2 get def
/PageHeight MediaBox 3 get def
false setglobal
end
} if
pop
(First page - width [) print PageWidth 10 string cvs print
(], height [) print PageHeight 10 string cvs print
(]\n) print
} for
} bind def
Upvotes: 1