fix corner case crash in xhtml headless export as pdf

Change-Id: I255504e2c84783387d2fc308800812bef5e82734