In one of my projects we are using PDF templates for the generating the PDF files. Like we create a template first with the textboxes on it and later we can use the template with filling the dynamic data and saving the resulting file. The issue was with the dynamic data not fitting in to the textboxes when the data from database is in Capital Letters. As we were not using the mono spaced fonts like courier. Mono spaced font takes equal number of points while printing on screen or paper say 8X12 pixels for all characters it may be ‘I’ or ‘W’. But non mono spaced font will take different width for different characters to save space, like ‘I’(may be say 3 pixels) will take less width on paper or screen than ‘W’(say 12pixels). And also capital letters take more width than small case. Got it?
There are more than 10 textboxes on my PDF for a paragraph like content to show on the PDF to look like lines of running text. Initially I set the line length to some 100 characters for each line in my code like if the text to show is 400 characters I was displaying in 4 lines. My issue was it is giving space on right side of the PDF textbox when text is in small letters. Then I increased number of characters to show from 100 to 120. Then the issue was with the uppercase text it was concatenated as the textbox width on the PDF form is limited and cannot increase.
The solution is to calculate the best fit of text length at runtime instead hard coding to 100 or 120. When the text is in uppercase the length can be calculated to 90 or so. And when the text is in lower case the length can be 120 characters.
Best fit of text length while printing PDF templates - CodeProject
No comments:
Post a Comment