Memory measurement -- importance of Driver.reset()
After reading the Sept 2003 thread about Memory Performance, leaks (and how wonderful ADA is), I modified my test program that generates 3 PDF files. The program now sleeps 30 seconds, calls Driver.reset(), nulls the reference and sleeps again. In JMP this plots a square wave between that you can read on the attached graphs. It is clear that there is a fair bit of memory freed by Driver.reset(). After thinking it over, I modified the same test to skip reset() and just null the reference and issue System.gc(). This should be the same as letting it go out of scope (which happens afterwards but this way I get the square wave on the graph). Guess what ? Attachment 2: footprint2.png has about 1Mb more heap in use! And this is a very short test file with just one member name address. The test prints a letter, envelope and a renewal form for a non-profit Gardening group. The difference ... no call to Driver.reset() !!! Why ? Does this suggest that there are finalizers (destructors) that are not being called ? References set to null inside reset() should all be unreachable when the reference to Driver goes out of scope. This might explain problems people are reporting when generating multiple PDF files using FOP. Especially if their programs don't lose references to instances of Driver. Personally, I suspect there are a lot of logical memory leaks inside FOP. A reset() at the end of using a Driver instance is a catch-all way of releasing all of the logically leaked memory allocated from inside Driver() (and therefore inside FOP). This approach is of little help to the developer who builds an application that dies of memory exhaustion in production. We will have to fix the logical leaks inside FOP to improve the user experience. -- John Austin [EMAIL PROTECTED] attachment: footprint2.pngattachment: footprint.pngimport java.io.File; import java.io.IOException; import javax.xml.transform.Result; import javax.xml.transform.Source; import javax.xml.transform.sax.SAXResult; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory ; import org.apache.avalon.framework.logger.ConsoleLogger; import org.apache.avalon.framework.logger.Logger; import org.apache.fop.apps.Driver; import org.apache.fop.apps.FOPException; /** * Use JAXP 1.1 to apply two transformations and FOP to generate PDF output * for the Friends of the Gardens (FOG) project for the MUN Botanical Garden * * Requires: * (i) Java = 1.4 to obtain the XML parser and XSLT processor - JAXP 1.1 * (ii) FOP = 0.20.5, fop.jar and the associated batik.jar and avalon-cvs-20020806000.jar * (iii) Input file: members.xml * (iv) Transforms: letter.xsl, letter2fo.xsl, * env.xsl, env2fo.xsl, * renewal.xsl, renewal2fo.xsl * Compile: * javac -classpath .;fop.jar;avalon-framework-cvs-20020806.jar SimpleJaxp.java * * Execute: * java -Xmx4 -classpath .;fop.jar;batik.jar;avalov-framework-cvs-20020806.jar SimpleJaxp * * Alternative: * cocoon: pipelines like this: map:match pattern=renewal map:enerate src=members.xml/ map:transform src=renewal.xsl / map:transform srcrenewal2fo.xsl / map:serialize type=fo2pdf/ /map:match */ public class SimpleJaxp extends java.lang.Thread { public static void main(String[] args) throws javax.xml.transform.TransformerException { java.util.Calendar cal = java.util.Calendar.getInstance(); long start = cal.getTimeInMillis(); transformToPDF( letter, members.xml, letter.xsl, letter2fo.xsl ); transformToPDF( env, members.xml, env.xsl, env2fo.xsl ); transformToPDF( renewal, members.xml, renewal.xsl, renewal2fo.xsl ); System.out.println( Elapsed + ((java.util.Calendar.getInstance().getTimeInMillis() - start + 500)/1000) + seconds. ); try { sleep(24*360); } catch (InterruptedException e ) { System.err.println( sleep() Interrupted. ); } } public static void transformToPDF( String namePart, String xmlFileName, String xsltFileName1, String xsltFileName2 ) throws javax.xml.transform.TransformerException { File xmlFile = new File( xmlFileName ); File xsltFile = new File( xsltFileName1); File out1 = null; try { out1 = File.createTempFile( namePart, .xml ); out1.deleteOnExit(); } catch( IOException ioe ) { System.err.println( Could not create temp file ); System.exit(0); } //*** First transformation *** Source xmlSource = new StreamSource(xmlFile); Source xsltSource = new StreamSource(xsltFile); Result result = new StreamResult(out1); TransformerFactory transFact = TransformerFactory.newInstance(); Transformer trans = transFact.newTransformer(xsltSource); trans.transform(xmlSource, result ); trans = null; //*** Second transformation *** File xsltFile2 = new File( xsltFileName2); Source
PDF-Report with dynamic JPEG-Image
Hello,I'm using FOP (0.20.5) for several month. It's a nice tool to generatedynamic pdf-documents in a web-environment (tomcat 4, java 1.4.1).Now I want to integrate charts which I generate in a servlet powered by theJFreeChart-classes (an open source project). The response of the servlet is"image/jpeg". I use it on a html-site in an image-tag.I thought it must be easy to use the fop-image-tag to reference this dynamicimage on the pdf-page like:fo:external-graphicsrc="" width="570"/But no graphic is shown in my pdf-result.If I put the URL in the address-bar of my browser, the image is shown. ThenI've saved the image (104 kB) on hard disk and referenced it absolute in thefo-document. Now I see the result as expected. But I still have to generatethe jpeg-image dynamically ;-(Some searches in the log's only shows one little error without any othermessages: HTTP-ERROR 302 (FOUND)w3.org describes this error as:"10.3.3 302 FoundThe requested resource resides temporarily under a different URI. Since theredirection might be altered on occasion, the client SHOULD continue to usethe Request-URI for future requests. This response is only cacheable ifindicated by a Cache-Control or Expires header field.The temporary URI SHOULD be given by the Location field in the response.Unless the request method was HEAD, the entity of the response SHOULDcontain a short hypertext note with a hyperlink to the new URI(s).If the 302 status code is received in response to a request other than GETor HEAD, the user agent MUST NOT automatically redirect the request unlessit can be confirmed by the user, since this might change the conditionsunder which the request was issued. "Does anybody knows what I'm doing wrong? Is it possible to referance anexternal image with a http-URL? Does someone use such dynamic images?Thanks in advance,Torsten
attribute-set
I am having a problem when trying to use attribute sets, and I am unsure on whether this is a problem with FOP or my newbie implementation of the syntax (the most likely possibility) I have the following attribute-set within my document which reads in values from an XML file : xsl:attribute-set name=title_table_block xsl:attribute name=font-sizexsl:value-of select=report_generics/report_title_font_size//xsl:attribute xsl:attribute name=font-weightxsl:value-of select=report_generics/report_title_font_weight//xsl:attribute xsl:attribute name=text-alignxsl:value-of select=report_generics/report_title_text_align//xsl:attribute /xsl:attribute-set Below this I use the following block to define the text within a table cell : fo:block xsl:use-attribute-sets=title_table_block xsl:value-of select=report_generics/report_title/ /fo:block Now from what I understand from these URLs the syntax above is correct : http://www.devguru.com/Technologies/xslt/quickref/xslt_element_attribute set.html http://www.w3schools.com/xsl/el_attributeset.asp The problem is that when I set the text properties it overrides all the font size/weight/align settings defined in other parts of the document, so when I create the PDF all parts of the document use these settings (at the moment this is the only attribute set and this block is the only block that calls it.) - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: CMYK again
Timo, Timo Haberkern wrote: 1.) FOP (or XSL:FO) doesn't support CMYK directly I don't know if the XSL-FO color space support supports CMYK or not. Others may comment on this who have read the spec more than I. 2.) CMYK JPEGs shouldn't be a problem in FOP through JAI support I use CMYK JPEGs in FOP all the time. Ben: How about release your mentioned tool as open source? The President of my employer is a lawyer. Dunno if open-source will happen anytime soon for that lib. ;-) Have you checked if the open-source Multivalent lib supports this type of operation? I'll try and take a gander too, but you should check and see. Ben - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: CMYK again
Ben, The President of my employer is a lawyer. Dunno if open-source will happen anytime soon for that lib. ;-) Have you checked if the open-source Multivalent lib supports this type of operation? I'll try and take a gander too, but you should check and see. I will check it next week. Thanks for the tip. I think it should be possible to create cmyk pdf from FOP directly. So if you can't open-source your solution, maybe you can talk a little bit about how to do such a replacement, so that i can maybe hack something similar into FOP? Timo - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: CMYK again
Well, in FOP 0.20.5 it is possible to generate uncompressed PDF documents. Although this may increase the file size, sometimes dramatically, it makes the RGB-CMYK replace operation much simpler, Because the PDF document wont need to be decompressed before performing those tasks. Then, what you will need is a regular expression, that finds any 'RG' or 'rg' color commands, to replace them with 'K' or 'k', respectively. Of course, the expression needs to be smart enough only to replace occurrences of 'RG' or 'rg' that is actually color commands. Searching for occurrences of three space separated numbers followed by space and then 'RG' or 'rg' is a hack, that might (but only might) be good enough. Then, the XRef Table needs to be rebuilt. This tasks should be possible to do with another regular expression, That searches for any occurrences of '[anInteger] [anotherInteger] obj' and adds the byte offset positions of these matches into a new XRef Table, that in the end should replace the existing XRef Table. Also, the number on the second last line of the document should be replaced with the number of bytes written until the occurrence of the last 'endobj' command. There is a number of plug-ins, that can be used from within Adobe Reader to convert the RGB colors of a PDF document into CMYK colors. There is a tool named QuiteABoxOfTricks that can be found at http://www.quite.com doing this. I am sure it is possible to setup a batch processing solution as well, in order to create a totally automated hack solution for this lack. PitStop server is another solution. Regards, Dennis JD Myrén Developer Tel: (+47) 98 00 11 92 Mail: [EMAIL PROTECTED] Web: www.oslokb.no -Original Message- From: Timo Haberkern [mailto:[EMAIL PROTECTED] Sent: 21. november 2003 14:38 To: [EMAIL PROTECTED] Subject: Re: CMYK again Ben, The President of my employer is a lawyer. Dunno if open-source will happen anytime soon for that lib. ;-) Have you checked if the open-source Multivalent lib supports this type of operation? I'll try and take a gander too, but you should check and see. I will check it next week. Thanks for the tip. I think it should be possible to create cmyk pdf from FOP directly. So if you can't open-source your solution, maybe you can talk a little bit about how to do such a replacement, so that i can maybe hack something similar into FOP? Timo - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: CMYK again
Then, what you will need is a regular expression, that finds any 'RG' or 'rg' color commands, to replace them with 'K' or 'k', respectively. Of course, the expression needs to be smart enough only to replace occurrences of 'RG' or 'rg' that is actually color commands. Searching for occurrences of three space separated numbers followed by space and then 'RG' or 'rg' is a hack, that might (but only might) be good enough. Ok, i understood that. But i think the color values must be changed too or i'm wrong. I think there must be a conversion from rgb to cmyk values?!? Then, the XRef Table needs to be rebuilt. This tasks should be possible to do with another regular expression, That searches for any occurrences of '[anInteger] [anotherInteger] obj' and adds the byte offset positions of these matches into a new XRef Table, that in the end should replace the existing XRef Table. Sorry don't understand that. For what is this task? Timo Also, the number on the second last line of the document should be replaced with the number of bytes written until the occurrence of the last 'endobj' command. There is a number of plug-ins, that can be used from within Adobe Reader to convert the RGB colors of a PDF document into CMYK colors. There is a tool named QuiteABoxOfTricks that can be found at http://www.quite.com doing this. I am sure it is possible to setup a batch processing solution as well, in order to create a totally automated hack solution for this lack. PitStop server is another solution. Regards, Dennis JD Myrén Developer Tel: (+47) 98 00 11 92 Mail: [EMAIL PROTECTED] Web: www.oslokb.no -Original Message- From: Timo Haberkern [mailto:[EMAIL PROTECTED] Sent: 21. november 2003 14:38 To: [EMAIL PROTECTED] Subject: Re: CMYK again Ben, The President of my employer is a lawyer. Dunno if open-source will happen anytime soon for that lib. ;-) Have you checked if the open-source Multivalent lib supports this type of operation? I'll try and take a gander too, but you should check and see. I will check it next week. Thanks for the tip. I think it should be possible to create cmyk pdf from FOP directly. So if you can't open-source your solution, maybe you can talk a little bit about how to do such a replacement, so that i can maybe hack something similar into FOP? Timo - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] . -- Grüsse Timo Haberkern EMEDIA OFFICE GmbH Wingertstr. 4 74850 Schefflenz-Kl. http://www.emedia-office.com [EMAIL PROTECTED] Tel.: 06293/921121 Fax: 06293/921129 - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: CMYK again
Timo Haberkern wrote: Ok, i understood that. But i think the color values must be changed too or i'm wrong. I think there must be a conversion from rgb to cmyk values?!? Right. I haven't created code that performs intelligent RGB - CMYK conversion; rather, I replace specific RGB values with specific CMYK values based on decisions we've made ahead of time. Sorry don't understand that. For what is this task? A PDF file is a series of objects, each of which contains instructions for how it should be rendered. At the end of the PDF is a reference table indicating the byte offset of each object. To save space, each object can be compressed using a few different methods. To modify the object's contents, the object must be decompressed. Because decompressing an object changes its size, the reference table must be updated when the object is decompressed. A tool such as Multivalent can take care of this for you (although as I've said previously, I had problems with it when I tried it; many others have not had problems). Once the objects have been decompressed, you can perform a search and replace operation -- BUT, because the replace operation will likely change the size of the objects, you should use a tool that rewrites the reference table. The text you need to replace has this general syntax: [red value] [green value] [blue value] rg or [red value] [green value] [blue value] RG You'll need to replace it with: [cyan] [magenta] [yellow] [black] k and: [cyan] [magenta] [yellow] [black] K respectively. Note that the color values are decimals, not integers. So, 255 = 1.0, 127 = 0.5, etc. Note, that as others have said, going to all this trouble only makes sense if you really need your code to do this. Other tools exist that can automate this process for you via a GUI, etc. So, check if Multivalent can do this. If it can, great. If not, check for other libs -- I'm told several exist. If you decide to get your own hands dirty, while I do not have permission to give you the code, I can offer a steady supply of advice. I've had a few requests for my lib, so I'll check again and see if I can get it released, since a PDF lib isn't neither innovative or proprietary. Ben Timo Also, the number on the second last line of the document should be replaced with the number of bytes written until the occurrence of the last 'endobj' command. There is a number of plug-ins, that can be used from within Adobe Reader to convert the RGB colors of a PDF document into CMYK colors. There is a tool named QuiteABoxOfTricks that can be found at http://www.quite.com doing this. I am sure it is possible to setup a batch processing solution as well, in order to create a totally automated hack solution for this lack. PitStop server is another solution. Regards, Dennis JD Myrén Developer Tel: (+47) 98 00 11 92 Mail: [EMAIL PROTECTED] Web: www.oslokb.no -Original Message- From: Timo Haberkern [mailto:[EMAIL PROTECTED] Sent: 21. november 2003 14:38 To: [EMAIL PROTECTED] Subject: Re: CMYK again Ben, The President of my employer is a lawyer. Dunno if open-source will happen anytime soon for that lib. ;-) Have you checked if the open-source Multivalent lib supports this type of operation? I'll try and take a gander too, but you should check and see. I will check it next week. Thanks for the tip. I think it should be possible to create cmyk pdf from FOP directly. So if you can't open-source your solution, maybe you can talk a little bit about how to do such a replacement, so that i can maybe hack something similar into FOP? Timo - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] . - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: XSL-FO Problem (Line not coming as proper location)
shuva sinha wrote: I am using fo:leader in xsl. But it is not coming. Another attempt at guessing what your problem might be: use text-align-last=justify, see also: http://xml.apache.org/fop/faq.html#leader-expansion J.Pietschmann - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: CMYK again
Ben Galbraith wrote: I don't know if the XSL-FO color space support supports CMYK or not. XSLFO only supports sRGB (gamma corrected!) and ICC colors. Of course, the spec doesn'n mention how the colors in the output should look like. J.Pietschmann - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: CMYK again
Timo Haberkern wrote: A question to the FOP coding gurus: What would be the correct/best way to implement an extension to FOP that can generate a CMYK document? Check whether iText or any other of the handful of PDF libraries on sourceforge can help you with this problem. J.Pietschmann - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: CMYK again
Timo Haberkern wrote: A question to the FOP coding gurus: What would be the correct/best way to implement an extension to FOP that can generate a CMYK document? rgds Timo Here're a couple of ideas of where to look: EXSLFO Project: http://exslfo.sourceforge.net/ EXSLFO Project Home: https://sourceforge.net/projects/exslfo/ which appears to be an extension of: http://exslt.org/ Good luck! - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]