Hi Daniel, Daniel Noll a écrit : > Hi all. > > There is a requirement in our system where PDF and TIFF output must have > the same content on every page. Because of this, we need to use > identical font metrics for these two renderers. > > By default, the two render differently. The widths of the fonts are > slightly different, so they wrap slightly differently, and once you have > one word wrapping to the next page, it cascades. > > Anyway, I was thinking, why can't I just do this? > > private class MyPDFRenderer extends PDFRenderer { > public void setupFontInfo(FontInfo inFontInfo) { > // Code copied from Java2DRenderer > fontInfo = inFontInfo; > BufferedImage fontImage = new BufferedImage(100, 100, > BufferedImage.TYPE_INT_RGB); > Graphics2D g = fontImage.createGraphics(); > g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, > RenderingHints.VALUE_FRACTIONALMETRICS_ON); > FontSetup.setup(fontInfo, g); > } > } > > If I substitute this renderer in, then the PDF and TIFF outputs look > identical, and I can't see any noticeable problems with the PDF. As an > added bonus, it means I don't even need the XML files hanging around, > which have been a pain to manage. > > So what I want to know is, is there a drawback for performing this hack?
One major drawback I can think of is that you can't embed fonts in the PDF file, as you don't have access to the font files. That's why we can't use that method by default, but if it works for you I guess it's perfectly ok. FWIW, I think the difference we can see between the PDF and Java2D renderers is due to hinting/anti-aliasing performed by the latter one. AFAIU Java2D takes an image with a given number of pixels as a basis, so has to deal with a potentially poor resolution (similar to screens). I'll let Java2D specialists complement/correct my guess. Another possibility would be to render only into PDF and convert the PDF file into TIFF with ghostscript. You should also get identical results that way. Vincent --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]