home *** CD-ROM | disk | FTP | other *** search
/ Acorn User 10 / AU_CD10.iso / Updates / GhostScript / !GhostScr / 6_01 / lib / pdfeof.ps < prev    next >
Text File  |  2000-03-09  |  2KB  |  60 lines

  1. %    Copyright (C) 2000 Aladdin Enterprises.  All rights reserved.
  2. % This file is part of Aladdin Ghostscript.
  3. % Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  4. % or distributor accepts any responsibility for the consequences of using it,
  5. % or for whether it serves any particular purpose or works at all, unless he
  6. % or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  7. % License (the "License") for full details.
  8. % Every copy of Aladdin Ghostscript must include a copy of the License,
  9. % normally in a plain ASCII text file named PUBLIC.  The License grants you
  10. % the right to copy, modify and redistribute Aladdin Ghostscript, but only
  11. % under certain conditions described in the License.  Among other things, the
  12. % License requires that the copyright notice and this notice be preserved on
  13. % all copies.
  14.  
  15. % $Id: pdfeof.ps,v 1.1 2000/03/09 08:40:40 lpd Exp $
  16. % Patch to allow garbage on the end of PDF files.
  17.  
  18. .currentglobal true .setglobal
  19. pdfdict begin
  20.  
  21. % Skip backward over the %%EOF at the end of the PDF file.
  22. % We put this in a separate procedure so we can easily offer the option
  23. % of accepting garbage after the %%EOF, which the PDF specification
  24. % unambiguously forbids but which some applications (including, apparently,
  25. % Acrobat Distiller on the Macintosh) produce, and of accepting the
  26. % xref position on the same line as startxref.
  27. /findxref {        % - findxref <xrefpos>
  28.   PDFfile dup dup 0 setfileposition bytesavailable
  29.   dup /PDFfilelen exch def
  30.     % Find the last %%EOF string (within 2048 bytes)
  31.   2048 sub PDFoffset .max
  32.   2 copy setfileposition
  33.   PDFfilelen exch sub string 1 index exch readstring pop {
  34.     (\015%%EO) search {        % Adobe can handle truncated key string
  35.       pop pop            % if found, keep searching 'post' string
  36.     } {
  37.       (\012%%EO) search
  38.     { pop pop } { exit } ifelse    % exit if neither string found
  39.     } ifelse
  40.   } loop
  41.   PDFfilelen exch length sub 4 sub PDFoffset .max setfileposition
  42.     % Now read the startxref and xref start position.
  43.   prevline token not { null } if dup type /integertype eq {
  44.     exch pop cvi        % xref start position
  45.     exch PDFfile exch setfileposition
  46.     prevline (startxref) linene { findxreferror } if
  47.     pop
  48.   } {    % else, this file has 'startxref #####' format
  49.     (startxref) ne { findxreferror } if
  50.     cvi        % xref start position
  51.     exch PDFfile exch setfileposition
  52.   } ifelse
  53. } bind def
  54.  
  55. end            % pdfdict
  56. .setglobal
  57.