Package: pdftk-java
Version: 3.3.2-1
Severity: normal
Tags: upstream
X-Debbugs-Cc: sid.stew...@pdflabs.com, debbug.pdftk-j...@sideload.33mail.com

Some PDFs contain OCG layers, where some content is assigned to a
layer that users can toggle the visibility of. For LaTeX users the
ocgx2 package provides this functionality.

PDFtk loses the layering information. All layers are flattened into
one, even layers with a default visibility is set to false.

Instead of attaching a sample PDF, I will reference a PDF from Debian:

  /usr/share/texmf/doc/context/presentations/examples/present-punk-001.pdf

That file is included with the /context/ package, which texlive-full
depends on. If you open it in evince, layers are detected and evince
gives a layers tab in the sidebar. In that tab you can see these
layers:

  step:1
  step:2
  step:3
  step:4

They are all invisible by default. Clicking next to each step makes a
layer visible. You can see the effect if the 2nd page is in view.

Running this command ruins the presentation:

  $ pdftk 
/usr/share/texmf/doc/context/presentations/examples/present-punk-001.pdf cat 
1-r1 output /tmp/flattened.pdf

Loading /tmp/flattened.pdf shows the layers are gone. A CLI way to verify this:

===8<----------------------------------------
$ gdalinfo 
/usr/share/texmf/doc/context/presentations/examples/present-punk-001.pdf -mdd 
LAYERS | grep -iE "(layer.*name|^Files)"
Files: /usr/share/texmf/doc/context/presentations/examples/present-punk-001.pdf
  LAYER_00_NAME=step:1
  LAYER_01_NAME=step:2
  LAYER_02_NAME=step:3
  LAYER_03_NAME=step:4

$ gdalinfo /tmp/flattened.pdf -mdd LAYERS | grep -iE "(layer.*name|^Files)"
Files: /tmp/flattened.pdf
===8<----------------------------------------

FWIW, if you want to find other files on your system which contain OCG
layers, this command may be useful:

===8<----------------------------------------
  $ find /usr/share -iname \*.pdf -exec sh -c 'for f; do gdalinfo "$f" -mdd 
LAYERS; done | grep -iE "(layer.*name|^Files)"' _ {} +
===8<----------------------------------------

# This is a BUG, not a feature request:

Superficially this bug report might be perceived as a wishlist
proposal to support layers. However, I’m exposing a *bug* here. There
is data loss and it is invisible to users. Users are exposed to the
risk of deleting a source PDF without realising the output PDF was
unwittingly/surreptitiously altered in this way.

Adding seamless support for OCG layers would of course be ideal but
short of that, in the very least, there should be a LIMITATIONS
section added to the man page informing users of the treatment of OCG
layers. And when a PDF with layers is fed to pdftk as input, there
should be a loud warning printed to the screen about the lossy
output. FWIW, the following JavaScript may be useful for detection of
layers (if not gdalinfo):

  
https://web.archive.org/web/20230330010541/https://acrobatusers.com/tutorials/how-do-i-check-layers-comments-and-forms-collection-pdf-files/

-- System Information:
Debian Release: 12.9
  APT prefers stable-updates
  APT policy: (990, 'stable-updates'), (990, 'stable-security'), (990, 
'stable'), (500, 'oldstable')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 5.10.0-28-amd64 (SMP w/2 CPU threads)
Kernel taint flags: TAINT_OOT_MODULE, TAINT_UNSIGNED_MODULE
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8), LANGUAGE not set
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

Versions of packages pdftk-java depends on:
ii  default-jre-headless [java8-runtime-headless]     2:1.17-74
ii  libbcprov-java                                    1.72-2
ii  libcommons-lang3-java                             3.12.0-2
ii  openjdk-11-jre-headless [java8-runtime-headless]  11.0.24+8-2~deb11u1
ii  openjdk-17-jre-headless [java8-runtime-headless]  17.0.13+11-2~deb12u1

pdftk-java recommends no packages.

Versions of packages pdftk-java suggests:
ii  poppler-utils [xpdf-utils]  22.12.0-2+b1

-- no debconf information

Reply via email to