0

Some facts:

  • I have a licensed font that cannot be embedded in the PDF I have created.
  • The only text in the PDF is found in editable form fields. These fields' 'font' property is set to the licensed font.
  • I am programmatically filling in these form fields with a dynamically generated .fdf file using pdftk

    pdftk infile.pdf fill_form data.fdf output outfile.pdf flatten
    
  • The flatten argument causes the form fields in the PDF to be converted to non-editable text.

I'm looking for a way to get this text to display in the licensed font without actually embedding the font in the PDF.

I have installed the font on the server that is generating the PDF. Is there a way to, for example, convert the text while displayed in the licensed font-face, to a static/flattened image?

deefour
  • 34,974
  • 7
  • 97
  • 90

1 Answers1

1

It is possible to do this in PDF. Whether or not it's possible in pdftk is another matter.

When form fields are created in PDF they can contain an optional set of appearance streams which define how the form field will appear in a viewer. In particular, you want to look at section 12.5.5 in the PDF reference on Appearance Streams.

What it comes down to is an XObject of subtype /Form which includes the appearance for the field in question. You would need to render the text into an image (presumably with a box outline in it) of the same proportions as the form field's /Rect element and create a /Form XObject that matches that.

This is entirely doable, but it is also a fair amount of detail work to make that happen.

Here's the work for any given text field

  1. Get the dimensions of the form field from the /Rect (PDF units)
  2. Create an image with the rendered text in the same proportions as the form field, probably at 96 dpi, translate that image into an XObject of subtype /Image
  3. Create an XObject of subtype /Form, put a reference to the /Image from step 2 into the resources, Create a content stream that renders the /Image scaled to the right size
  4. Set the /AP element of the form field's dictionary to a new dictionary with one element, /N, which refers to the /Form XObject in #3
  5. Set the ReadOnly flag in the field's /Ff element
plinth
  • 48,267
  • 11
  • 78
  • 120