PDF Technique 08

Providing definitions for abbreviations via an E entry for a structure element

The ‘E’ in this technique is for “Expansion”. When words are abbreviated, they still make sense visually, but when read out loud with no visual cues, they no longer make sense. For example, the word “Doctor” is abbreviated “Dr.”, but when the abbreviation is read out loud, it sounds like Der.

package ca.discotek.itext.guide;

import java.io.*;

import ca.discotek.itext.DocumentStructure;
import ca.discotek.itext.DocumentStructure.PageStructure;

import com.itextpdf.text.*;
import com.itextpdf.text.pdf.*;

public class Pdf08Expansion {

  public static void main(String[] args) {
    try {
      Document document = new Document(PageSize.LETTER);
      PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(

      Rectangle rect = document.getPageSize();



      PdfContentByte cb = writer.getDirectContent();
      PdfStructureTreeRoot rootElement = writer.getStructureTreeRoot();

      DocumentStructure documentStructure = new DocumentStructure(rootElement, "en-us");
      PageStructure pageStructure = documentStructure.getPage(0);

      PdfStructureElement paragraphElement = new PdfStructureElement(pageStructure.bodyElement, PdfName.P);


      BaseFont bf = BaseFont.createFont(BaseFont.COURIER, "Cp1252", false);

      PdfDictionary dict = new PdfDictionary();
      dict.put(PdfName.E, new PdfString("Doctor Watson, I presume."));
      cb.beginMarkedContentSequence(new PdfName("Span"), dict, true);


      cb.setFontAndSize(bf, 12);

      cb.moveText(rect.getLeft() + 50, rect.getTop() - 50);

      cb.showText("Dr. Watson, I presume.");

      cb.endMarkedContentSequence();  // end span
      cb.endMarkedContentSequence();  // end paragraphElement

    catch (Exception e) {


It’s worth noting that I could have just spanned the expansion across the word “Dr.” and not the entire sentence. However, when this happens, some screen readers will interpret this as a break and pause in mid-sentence. The only solution is to expand the entire sentence.

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>