Add SetCellStretchToFit() and ResetCellStretch functions #23
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The SetCellStretchToFit function can be used to set horizontal stretching
of text to fit the full width of a cell. This is particularly useful when
trying to precisely line up text in a cell with an OCR image below it, and
as a pleasant side-effect can also prevent PDF readers from assuming that
words in cells on the same line with some space between them are in fact on
different lines when copy-pasting the text.
The ResetCellStretch function resets the cell stretch value to the default,
which is no stretch (100%).
This uses the Tz text state operator described in section 9.3.1 of the PDF 3200-1:2008 specification.
An alternative (php) implementation http://www.fpdf.org/en/script/script62.php wraps the Cell() method instead, but I prefer the stateful approach here, as it's cleaner and simpler.
This is super useful for me in creating searchable PDFs from page images (using invisible text), as it means I can set the text in each Cell to take the whole space allocated, and as the OCR engine gives the exact size of each text box this makes the whole thing very accurate.