Skip to content

Add Hidden Data Embedding in PDFs #59

Description

@OlegCheban

We need to hide arbitrary data in a PDF in ways that do not affect rendering. We have to add data in a way to be difficult to identify and remove.

For researching:

  1. Metadata embedding
    Use the XMP metadata block (in the /Metadata stream object).
    It can contain arbitrary XML; you can base64 your string and store it in a custom namespace tag, e.g.:
<rdf:Description xmlns:wm="http://yourdomain/watermark">
  <wm:HiddenID>BASE64ENCODED_DATA</wm:HiddenID>
</rdf:Description>

Con: Relatively easy to find if someone looks at metadata.

  1. Unreferenced object injection
    PDFs can contain extra objects that are not referenced from any page, annotation, or catalog.
999 0 obj
<< /HiddenData (SomeBinaryOrBase64) >>
endobj

Readers ignore unreferenced objects, but they remain in the file.

Pro: Invisible in normal viewing, survives many editing operations.
Con: Can be removed by PDF optimizers that discard unreferenced objects.

  1. Inside page content streams as no-op operators
    You can inject data in a page’s content stream in the form of comments or no-op commands:
%Hidden: BASE64_DATA
0 0 m
0 0 l
n
% starts a comment; 

PDF interpreters ignore it during rendering.

Pro: Stays in visible page streams, so optimizers may leave it.
Con: Anyone dumping the stream sees it.

  1. In object stream padding
    PDF object streams often have unused padding between tokens or within binary streams (when compression is off).
    You can inject bytes inside these padding areas.
    Pro: Very stealthy.
    Con: Risky if any PDF editor recompresses streams — could lose data.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions