bug fixes and streamlining

1. Fixed a bug in the injection that could have caused loss of resource
data.
2. streamlined the PDF output to avoid unused objects. This also helped
avoid some duplication of data. when objects were used and saved more
then once.