[gs-cvs] rev 8325 - trunk/gs/lib
alexcher at ghostscript.com
alexcher at ghostscript.com
Sat Oct 27 11:55:14 PDT 2007
Author: alexcher
Date: 2007-10-27 11:55:14 -0700 (Sat, 27 Oct 2007)
New Revision: 8325
Modified:
trunk/gs/lib/pdf2dsc.ps
trunk/gs/lib/pdf_main.ps
Log:
Extract and process default PDF file from the PDF collection when
it is defined. Otherwise process the container PDF file.
DETAILS:
The procedure pdf_collection_files can be extended to select other
PDF files from the collection and extract them for processing.
DIFFERENCES:
None
Modified: trunk/gs/lib/pdf2dsc.ps
===================================================================
--- trunk/gs/lib/pdf2dsc.ps 2007-10-26 07:41:30 UTC (rev 8324)
+++ trunk/gs/lib/pdf2dsc.ps 2007-10-27 18:55:14 UTC (rev 8325)
@@ -116,6 +116,7 @@
DSCfile PDFname write==only
( \(r\) file { DELAYSAFER { .setsafe } if } stopped pop\n) puts
( pdfopen begin\n) puts
+ ( copy_trailer_attrs\n) puts
(%%EndSetup\n) puts
/.hasPageLabels false def % see "Page Labels" in the PDF Reference
Modified: trunk/gs/lib/pdf_main.ps
===================================================================
--- trunk/gs/lib/pdf_main.ps 2007-10-26 07:41:30 UTC (rev 8324)
+++ trunk/gs/lib/pdf_main.ps 2007-10-27 18:55:14 UTC (rev 8325)
@@ -136,7 +136,7 @@
currentdict /runpdfstring .undef
-/runpdfbegin { % <file> runpdf -
+/runpdfbegin { % <file> runpdfbegin -
userdict begin
% It turns out that the PDF interpreter uses memory more
% effectively if it is run under at least one level of save.
@@ -151,6 +151,9 @@
GS_PDF_ProcSet begin
pdfdict begin
pdfopen begin
+} bind def
+
+/runpdfpagerange { % - runpdfpagerange <firstpage#> <lastpage#>
/FirstPage where
{ pop FirstPage dup pdfpagecount gt
{ (\nRequested FirstPage is greater than the number of pages in the file: ) print
@@ -194,12 +197,68 @@
2 vmreclaim % couldn't hurt
} bind def
+% - pdf_collection_files [temp_files] show_container
+/pdf_collection_files {
+ {} //true
+ Trailer /Root oget /Collection knownoget {
+ /D knownoget { % We have default document in the collection
+ Trailer /Root oget /Names knownoget {
+ /EmbeddedFiles knownoget {
+ exch nameoget dup //null ne {
+ /EF knownoget {
+ /F knownoget {
+ //true resolvestream % {} true strm
+ //null (w) .tempfile % {} true strm (name) file
+ 3 -1 roll % {} true (name) file strm
+ 32768 string % {} true (name) file strm (buf)
+ { 3 copy readstring % {} true (name) file strm (buf) file (data) bool
+ 3 1 roll % {} true (name) file strm (buf) bool file (data)
+ writestring % {} true (name) file strm (buf) bool
+ not { exit } if
+ } loop
+ pop closefile % {} true (name) file
+ closefile % {} true (name)
+ 3 1 roll pop pop % (name)
+ .currentglobal //true .setglobal
+ exch dup length string copy 1 array astore
+ exch .setglobal //false
+ } if
+ } if
+ } {
+ pop
+ } ifelse
+ } {
+ pop
+ } ifelse
+ } {
+ pop
+ } ifelse
+ } if
+ } if
+} bind def
+
/runpdf { % <file> runpdf -
- runpdfbegin
- dopdfpages
- runpdfend
+ //runpdfbegin exec
+ //pdf_collection_files exec {
+ copy_trailer_attrs
+ //runpdfpagerange exec
+ //dopdfpages exec
+ } if
+ //runpdfend exec
+ {
+ dup (r) file
+ //runpdfbegin exec
+ copy_trailer_attrs
+ //runpdfpagerange exec
+ //dopdfpages exec
+ //runpdfend exec
+ deletefile
+ } forall
} bind def
+{/runpdfbegin /runpdfpagerange /dopdfpages /runpdfend /pdf_collection_files}
+{ currentdict exch .undef } forall
+
end % systemdict
% Redefine the procedure that the C code uses for running piped input.
% It is OK to use { (%stdin) run } here, because a startjob cannot occur.
@@ -468,6 +527,10 @@
if
pdfopenfile begin
pdfopencache
+ currentdict end
+} bind def
+
+/copy_trailer_attrs { % - copy_trailer_attrs -
writeoutputintents
.writepdfmarks {
% Copy bookmarks (outline) to the output.
@@ -477,7 +540,6 @@
} if
} if
} if % end .writepdfmarks
- currentdict end
} bind def
% Verify that each entry in the xref table is pointing at an object with
More information about the gs-cvs
mailing list