pdfeof.ps 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. % Copyright (C) 2000 Aladdin Enterprises. All rights reserved.
  2. %
  3. % This file is part of Aladdin Ghostscript.
  4. %
  5. % Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND. No author
  6. % or distributor accepts any responsibility for the consequences of using it,
  7. % or for whether it serves any particular purpose or works at all, unless he
  8. % or she says so in writing. Refer to the Aladdin Ghostscript Free Public
  9. % License (the "License") for full details.
  10. %
  11. % Every copy of Aladdin Ghostscript must include a copy of the License,
  12. % normally in a plain ASCII text file named PUBLIC. The License grants you
  13. % the right to copy, modify and redistribute Aladdin Ghostscript, but only
  14. % under certain conditions described in the License. Among other things, the
  15. % License requires that the copyright notice and this notice be preserved on
  16. % all copies.
  17. % $Id: pdfeof.ps,v 1.1 2000/03/09 08:40:40 lpd Exp $
  18. % Patch to allow garbage on the end of PDF files.
  19. .currentglobal true .setglobal
  20. pdfdict begin
  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. end % pdfdict
  55. .setglobal