latex3 / pdfresources

LaTeX PDF resource management
LaTeX Project Public License v1.3c
22 stars 5 forks source link

`\DocumentMetadata{}` disables stream uncompression for dvips #48

Closed muzimuzhi closed 7 months ago

muzimuzhi commented 1 year ago

l3build's regression-test.tex sets

  \special{%
      ps: /setdistillerparams
      where
        {pop << /CompressPages false /CompressStreams false >> setdistillerparams}
      if
    }%

to uncompress pdf generated by ps2pdf.

But if \DocumentMetadata{} is used, the /Type/Metadata object in pdf is no longer uncompressed and one has to pass -dCompressStreams=false to ps2pdf to re-enable uncompression (https://github.com/latex3/l3build/pull/278#issuecomment-1441325092). See an example diff here

The .tpf files in current repo's directory testfiles-dvips also reflect this difference. Thus I suppose this is a known problem/limitation.

% \DocumentMetadata{}
\input regression-test\relax
\documentclass{article}

\begin{document}
text
\end{document}

From the intermediate ps files, it seems with \DocumentMetadata{} the corresponding special is inserted too late:

 %%Page: 1 1
-TeXDict begin 1 0 bop 515 440 a
+TeXDict begin 1 0 bop -600 -600 a
+ [{ThisPage}<<>> /PUT pdfmark
+ -600 -600 a 515 440
+a
  /setdistillerparams where {pop << /CompressPages false /CompressStreams
 false >> setdistillerparams} if
u-fischer commented 1 year ago

Without \DocumentMetadata you get the xmp-metadata added by Ghostscript; with \DocumentMetadata the one added by the pdfmanagement code. Ghostscript honors then that there are user metadata and doesn't add its own, but it offers no option to add it as an uncompressed stream (I had a discussion about that https://bugs.ghostscript.com/show_bug.cgi?id=705962) and imho it doesn't react to the /setdistillerparams either. The only way to uncompress it is to pass the options (in the few tests I have I normally use \DocumentMetadata{xmp=false} as I didn't want to bother with this).

muzimuzhi commented 1 year ago

It seems https://bugs.ghostscript.com/show_bug.cgi?id=705962 only tells there's no way to uncompress the xmp stream solely, but didn't clearly say the /setdistillerparams setting is not honored (on xmp stream added by the pdfmanagement code). Is it?

u-fischer commented 7 months ago

I retried. Even if I put the special in the background hook (where it is then before the pdfmark) the XMP stays compressed.

\AddToHook{shipout/background}{ \special{%
      ps: /setdistillerparams
      where
        {pop << /CompressPages false /CompressStreams false >> setdistillerparams}
      if
    }}%
\input regression-test\relax
\DocumentMetadata{}
\showoutput
\documentclass{article}

\begin{document}
text
\end{document}

So I think there is nothing one can do unless ghostscript changes something and I'm closing here for now.