[gs-code-review] Patch for 689413, running default file from PDF collection

Alex Cherepanov alexcher at quadnet.net
Tue Oct 23 19:49:35 PDT 2007


Display the default file in PDF file by extracting it from the embedded
file stream to a temporary file and re-starting the PDF interpreter.

The patch is quite straightforward but there are a few issues related
to the PDF file collection I'd like to discuss.

1. The patch doesn't delete the temp file. An simple appoach would
    be saving the file and the file name and delete the file
    in runpdfend procedure.

    Alternatively, we can create a file that deletes itself from
    disk when it is closed.

2. Currently, there's no way to select non-default files from the
    collection. The content of the collection is not listed either.
    Suggestions about the user's interface are welcome.

3. The current code location is inconvenient for rendering of
    multiple files from the collection. Do we need this feature?

Regards,
Alex Cherepanov

-------------- next part --------------
Index: gs/lib/pdf_main.ps
===================================================================
--- gs/lib/pdf_main.ps	(revision 8312)
+++ gs/lib/pdf_main.ps	(working copy)
@@ -467,6 +467,40 @@
     }
    if
   pdfopenfile begin
+  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    % strm
+                //null (w+) .tempfile   % strm (name) file
+                3 -1 roll               % (name) file strm
+	        32768 string            % (name) file strm (buf)
+	        { 3 copy readstring     % (name) file strm (buf) file (data) bool
+                  3 1 roll              % (name) file strm (buf) bool file (data)
+                  writestring           % (name) file strm (buf) bool
+ 	    	  not { exit } if
+	        } loop                  
+                pop closefile           % (name) file
+                exch pop                % file   %  can't delete temp file here
+	        dup 0 setfileposition
+                end  % old state
+                pdfopenfile begin
+              } if
+            } if
+          } {
+            pop
+          } ifelse
+        } {
+          pop
+        } ifelse
+      } {
+        pop
+      } ifelse
+    } if
+  } if
   pdfopencache
   writeoutputintents
   .writepdfmarks {


More information about the gs-code-review mailing list