Take the 2-minute tour ×

Super noob question: is it possible to show the metadata inserted with hyperref into the generated pdf itself? I don't mean to set them during generation, that would be easy.

I know that is not possible or somewhat hard to search and replace strings of text into a pdf after creation. I've some nice LaTeX invoice template, where normally, only some data changes.

I would like to use C or Objective-C to change those data after the PDF is generated. It seems to me that the metadata are, maybe, more accessible programmatically and I would not like to loose the excellent LaTeX typeset text of the PDF.

I would like to use metadata as some sort of baked in database.

Am I crazy?

For example, the "author" field could be set to a placeholder value like XXX, then I would later set/change it by only accessing PDFs metadata, programmatically (in other words in post-production without LaTeX).

It's like a fillable pdf but with metadata as a mean to update the text.


I know it could be an automation distorted idea but the problem arise from the usage scenario. I would like to produce a simple invoicing app for iOS (iPhone and iPad) and I would like to use the nice typeset pdf I created with LaTeX. I know i can't embed TEX into the app because of various licensing problems. At the same time I don't like to depend on an external, network reachable, TEX engine like scribtex.

share|improve this question
I guess not crazy but definitely cryptic :) Can you please elaborate on your question a little slower? –  percusse Feb 21 '12 at 11:17
@percusse thx, reduced my cryptic level, let me know if you need more explanations –  microspino Feb 21 '12 at 11:26
I think you are trying to use automation on the wrong level. Generate your document, then compile it; not in the reverse order. –  Andrey Vihrov Feb 21 '12 at 12:23
I have to admit that I still don't understand the question. When you create the document, do you want to read the same document's metadata? Or do you load another PDF and want to read the metadata? Or do you want to change metadata of some PDF file on your harddrive? –  topskip Feb 21 '12 at 13:10
@microspino you could look up the executable pdftk that will let you extract and edit the pdf in place via text files and such. Further it can be used to remove pages, add attachments etc. This should do what you want. From how I understood your query. –  zeroth Feb 21 '12 at 13:18
show 1 more comment

2 Answers

up vote 8 down vote accepted

If I understood you correctly, you want to have fields in your PDF document displaying the current author as stated in the file's metadata. Like this, you want to be able to update the document by changing the metadata with an external program, which is easier than manipulating the text directly.

Theoretically, this is possible using PDF forms and Acrobat JavaScript: The hyperref package is capable of creating fillable forms, and with the insdljs package, you are able to insert the code to update a field with the document information. (insdljs is part of the AcroTeX bundle, which is in MiKTeX, but not in TeX Live, so you may have to install it manually.)

A proof of concept:

\OpenAction{/S /JavaScript /JS (this.getField("fullname").value = this.info.author;)}
\TextField[name=fullname]{Name: }

(pdfauthor is set so that the form field displays something, you can change the PDF author with an external program to see that it works.)


filled form field

However, this approach has two drawbacks:

  1. The inserted text looks quite different from the surrounding text.
  2. JavaScript doesn't work in many PDF readers other than Adobe (Reader), so unless you have this program installed and JavaScript activated, you'll get a blank field.

Drawback #1 can be tackled by using the various formatting options described in the hyperref manual.

To overcome drawback #2, I would suggest a different approach than using the document's metadata to update the text:

  1. Create a PDF document containing a fillable form (this is pretty much the same we already did, but without the JavaScript part):

    \TextField[name=fullname]{Name: }
  2. Create a so-called FDF (Forms Data Format) file containing the information you want to insert into the PDF document. For our minimal example, the file would look like this (replace Firstname Lastname with the name you want to insert):

    1 0 obj 
    /Fields [
    /V (Firstname Lastname)
    /T (fullname)
    /Root 1 0 R

    To create a "template" FDF file you can fill yourself, you can use the PDF toolkit pdftk:

    pdftk form.pdf generate_fdf output form.fdf
  3. Now, you can write the prepared FDF file form.fdf into the original PDF form form.pdf using pdftk:

    pdftk form.pdf fill_form form.fdf output form-filled.pdf flatten

This may seem more work than the first approach, but as a result, you get a static document that can be viewed by any PDF reader.

share|improve this answer
add comment

Use pdfinfo from poppler/xpdf.

share|improve this answer
add comment

Your Answer


