printing - Calculating a formatted string's width & height in C# -
I try to convert XML from a database to generate a PDF using an XML XML (XML-FO) I am doing
Due to complex rules in the context of paging for this document, when I generate XML, which is consumed by XSL, then calculate in determining the page break I have seen that these calculations I am getting inconsistent results. For example, in the context of height, the required print area is 9 inches, which I increase by 72 points to points with a score (64 inches per inch) = 648 points.
So for every line, I want to reduce the line height to the measurement string, which I want to reduce by then 648, to see if the line is still available to print. But whenever a page break is determined, there will be a large white spot left below. It seems that the 648pt conversion is wrong. Now I am also worried that the height of the measurement string method can also be wrong.
I apologize for the long post, but I appreciate any input / suggestion that what I am doing. P>
Thank you very much!
I think the biggest problem is that you are using GDI to measure the string Methods that will be displayed in PDF. It's just not going to be accurate enough (even if you find the fonts alike, they use different rendering techniques while remembering me.)
So, you have to calculate Other forms should try. A simple first step would be to estimate the characters per line, and then the height of each line will be in PDF. Then, just use those numbers once you turn off, you can improve the technique to pay attention to specific characters and assess. (You probably do not want to reach the level of calculation of karning.)
Another technique might be to do something that I had worked in a previous project. Using ITextSharp, we had to add a diagonal text to a page (as a type of watermark) since the text was unknown, so we guessed the original font size. Then the code went into a loop where it measures the size of the rendered text, and it was the right size to fill the page without clipping any text, and adjust it up or down. (All this was done with guessing and measuring iTextSharp.)
Comments
Post a Comment