General algorithm.
Including pdf address.