Some more fun... see
https://forums.adobe.com/thread/1003116/UserUnit scale can be added to the Page Dictionary (just ahead of
MediaBox) to map user space units to points (real world coordinate space). For example,
/UserUnit 72.0 means your user units would be in inches (Letter size
/MediaBox [0 0 8.5 11]). Resolution may suffer (blocky effect). UserUnit comes first, and then all other dimensions and coordinates (including MediaBox) come after, in User Space Units (points divided by the UserUnit, which is by default 1.0). Multiply any dimension or coordinate by UserUnit to get real world point size.
According to the article,
- Changing UserUnit from page to page may result in rendering anomalies. They recommend picking one UserUnit and using the same one for each page. In theory, you should be able to change UserUnit on each page, so this may be considered an Acrobat bug or limitation.
- While Acrobat adheres to the PDF standard of a maximum of 14400 User Space Units, some PDF writers and readers produce PDFs outside of the 14400 limit, with or without UserUnit. For PDF::Builder to import these and write out a PDF that Acrobat can successfully render, thought needs to be given to forcing a UserUnit entry and scaling down all dimensions and coordinates on a page by that amount!
- Adobe Distiller apparently does not support UserUnit, and is still limited to 14400 points (200 inches). Earlier PDF versions have smaller limits, and only readers supporting PDF 1.6 or higher (most, these days) support UserUnit.
We need to consider
- A new global setting for UserUnit, to be inserted on each page. This might include a flag indicating whether all user dimensions in calls are already scaled to this UserUnit, or PDF::Builder needs to divide each by UserUnit.
- Allow a per-page UserUnit setting, to override the global setting for this one page, but warn the user that there might be rendering difficulties on some readers.
- What to do when an existing PDF is read in that contains dimensions or coordinates in excess of 14400. Given that we normally don't process a read-in PDF, but just write it back out more or less intact (and tack on additional stuff), we might only be able to warn the user in the documentation and leave it at that.
- Should PDF::Builder allow creation of PDFs (whether read-in or from scratch) with dimensions in excess of 14400? It might be good to have a global switch to allow this, so that the user understands that some readers won't be able to handle this output. Perhaps output a one-time (per run) message that a non-conforming dimension was seen, and allow that message to be suppressed? This would work only for new material (not read-in PDFs).
- Note that outputting UserUnit means raising the output PDF version to a minimum of 1.6.
The simplest path is to allow a global (and possibly per-page override) UserUnit setting. It would be up to the user to properly scale their coordinates to work with this scale factor. There would be no check of user space coordinate values (no bounds checking), in case the user wants to output PDFs that are
not universally readable, but are for a specific reader. Without extensive processing of read-in PDFs (possible in the future), there is no easy way to scale down existing read-in PDFs to Acrobat (or Distiller) compatibility.
We need to check whether MediaBox and UserUnit can be set globally (inherited per page), or must be set on a per-page basis. Also need to consider scaling down
mediabox(name) by dividing by any UserUnit given. So,
mediabox('Letter') would output
/MediaBox [0 0 8.5 11] if UserUnit was 72.