You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by Christian Pestel <ch...@orange.fr> on 2013/03/07 16:44:01 UTC

fo to Intermediate Format transform - Image file locked after transformation / Fop trunk.Feb.11.2013

Hi,

I try to convert a fo file to Intermediate Format (IF) file with a fop server (i.e. JVM never terminate)  
fo file contain an external-graphics jpg image.
The problem  : at the end of FO2IF transformation, the file signature.jpg remain locked by java.

This problem don’t happen with fo to pdf transformation.
This problem don’t happen with fop used with command line because java terminate and close all files.
I join you a logs.zip (FO2IF.log and FO2PDF.log)

I use version Fop Trunk 1447488   Feb 11 2013

This is my FO source file

<?xml version="1.0" encoding="utf-8"?><fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set><fo:simple-page-master master-name="section1" page-width="8.268in" page-height="11.693in" margin-top="35.4pt" margin-bottom="35.4pt" margin-right="70.85pt" margin-left="70.85pt"><fo:region-body margin-top="35.45pt" margin-bottom="35.45pt" /></fo:simple-page-master></fo:layout-master-set><fo:page-sequence master-reference="section1" format="1">
<fo:flow flow-name="xsl-region-body">

<fo:block><fo:inline><fo:external-graphic src="file:///C:/Images/signature.jpg" /></fo:inline></fo:block>

</fo:flow></fo:page-sequence></fo:root>



This is my java source file

...
Source inputSource = new StreamSource( new File(inputFilename) ); //FO file
File outputFile = new File(outputFilename);  //IF file
convertFromIntermediate(inputSource, outputFile, mimeType); // MimeConstants.MIME_PDF or MimeConstants.MIME_AFP for RendererMimic
...


/**
* Converts an XSL-FO document to an intermediate file.
* @param src the source file
* @param intermediate the target intermediate file
* @param mimeType the MIME type of the final document
* @throws IOException In case of an I/O problem
* @throws FOPException In case of a FOP problem
* @throws TransformerException In case of a XSL transformation problem
*/
public void convertToIntermediate(Source src, File intermediate, String mimeType)
    throws IOException, FOPException, TransformerException 
{
    FopRunner.trace("Converting to intermediate format...");
    //Create a user agent
    FOUserAgent userAgent = fopFactory.newFOUserAgent();

    //Create an instance of the target document handler so the IFSerializer
    //can use its font setup
    FopRunner.trace("MIME Type = " + mimeType);
    IFDocumentHandler targetHandler = userAgent.getRendererFactory().createDocumentHandler(userAgent, mimeType); 

    //Create the IFSerializer to write the intermediate format
    IFSerializer ifSerializer = new IFSerializer(new IFContext(userAgent));

    //Tell the IFSerializer to mimic the target format  
    ifSerializer.mimicDocumentHandler(targetHandler);

    //Make sure the prepared document handler is used
    userAgent.setDocumentHandlerOverride(ifSerializer);

    // Setup output
    OutputStream out = new java.io.FileOutputStream(intermediate);
    out = new java.io.BufferedOutputStream(out);
    
    try 
    {
        // Construct FOP (the MIME type here is unimportant due to the override
        // on the user agent)
        Fop fop = fopFactory.newFop(null, userAgent, out);

        // Setup XSLT
        TransformerFactory factory = TransformerFactory.newInstance();
        Transformer transformer = factory.newTransformer();
        
        // Resulting SAX events (the generated FO) must be piped through to FOP
        Result res = new SAXResult(fop.getDefaultHandler());

        // Start XSLT transformation and FOP processing
        transformer.transform(src, res);
    } 
    finally 
    {
        out.close();
    }
}


 

Christian Pestel

christian.pestel@orange.fr

Re: fo to Intermediate Format transform - Image file locked after transformation / Fop trunk.Feb.11.2013

Posted by Christian Pestel <ch...@orange.fr>.
Hi Vincent,

Thank a lot Vincent, it's work fine now with this patch.

Christian Pestel

christian.pestel@orange.fr


-----Message d'origine----- 
From: Vincent Hennebert
Sent: Tuesday, March 19, 2013 5:29 PM
To: fop-users@xmlgraphics.apache.org
Subject: Re: fo to Intermediate Format transform - Image file locked after 
transformation / Fop trunk.Feb.11.2013

Hi Christian,

On 07/03/13 16:44, Christian Pestel wrote:
> Hi,
>
> I try to convert a fo file to Intermediate Format (IF) file with a fop 
> server (i.e. JVM never terminate)
> fo file contain an external-graphics jpg image.
> The problem  : at the end of FO2IF transformation, the file signature.jpg 
> remain locked by java.

To be more precise the file descriptor corresponding to the image file
was not released, leading to the JVM eventually running out of file
descriptors.

This is because the IF renderer doesn’t close images once it has
‘rendered’ them. See [FOP-2226] for more details.

[FOP-2226] https://issues.apache.org/jira/browse/FOP-2226

The issue should be fixed in rev. 1458382 of the trunk. Thanks for
reporting it.


> This problem don’t happen with fo to pdf transformation.
> This problem don’t happen with fop used with command line because java 
> terminate and close all files.
> I join you a logs.zip (FO2IF.log and FO2PDF.log)
>
> I use version Fop Trunk 1447488   Feb 11 2013
>
> This is my FO source file
>
> <?xml version="1.0" encoding="utf-8"?><fo:root 
> xmlns:fo="http://www.w3.org/1999/XSL/Format">
> <fo:layout-master-set><fo:simple-page-master master-name="section1" 
> page-width="8.268in" page-height="11.693in" margin-top="35.4pt" 
> margin-bottom="35.4pt" margin-right="70.85pt" 
> margin-left="70.85pt"><fo:region-body margin-top="35.45pt" 
> margin-bottom="35.45pt" 
> /></fo:simple-page-master></fo:layout-master-set><fo:page-sequence 
> master-reference="section1" format="1">
> <fo:flow flow-name="xsl-region-body">
>
> <fo:block><fo:inline><fo:external-graphic 
> src="file:///C:/Images/signature.jpg" /></fo:inline></fo:block>
>
> </fo:flow></fo:page-sequence></fo:root>
>
>
>
> This is my java source file
>
> ...
> Source inputSource = new StreamSource( new File(inputFilename) ); //FO 
> file
> File outputFile = new File(outputFilename);  //IF file
> convertFromIntermediate(inputSource, outputFile, mimeType); // 
> MimeConstants.MIME_PDF or MimeConstants.MIME_AFP for RendererMimic
> ...
>
>
> /**
> * Converts an XSL-FO document to an intermediate file.
> * @param src the source file
> * @param intermediate the target intermediate file
> * @param mimeType the MIME type of the final document
> * @throws IOException In case of an I/O problem
> * @throws FOPException In case of a FOP problem
> * @throws TransformerException In case of a XSL transformation problem
> */
> public void convertToIntermediate(Source src, File intermediate, String 
> mimeType)
>      throws IOException, FOPException, TransformerException
> {
>      FopRunner.trace("Converting to intermediate format...");
>      //Create a user agent
>      FOUserAgent userAgent = fopFactory.newFOUserAgent();
>
>      //Create an instance of the target document handler so the 
> IFSerializer
>      //can use its font setup
>      FopRunner.trace("MIME Type = " + mimeType);
>      IFDocumentHandler targetHandler = 
> userAgent.getRendererFactory().createDocumentHandler(userAgent, mimeType);
>
>      //Create the IFSerializer to write the intermediate format
>      IFSerializer ifSerializer = new IFSerializer(new 
> IFContext(userAgent));
>
>      //Tell the IFSerializer to mimic the target format
>      ifSerializer.mimicDocumentHandler(targetHandler);
>
>      //Make sure the prepared document handler is used
>      userAgent.setDocumentHandlerOverride(ifSerializer);
>
>      // Setup output
>      OutputStream out = new java.io.FileOutputStream(intermediate);
>      out = new java.io.BufferedOutputStream(out);
>
>      try
>      {
>          // Construct FOP (the MIME type here is unimportant due to the 
> override
>          // on the user agent)
>          Fop fop = fopFactory.newFop(null, userAgent, out);
>
>          // Setup XSLT
>          TransformerFactory factory = TransformerFactory.newInstance();
>          Transformer transformer = factory.newTransformer();
>
>          // Resulting SAX events (the generated FO) must be piped through 
> to FOP
>          Result res = new SAXResult(fop.getDefaultHandler());
>
>          // Start XSLT transformation and FOP processing
>          transformer.transform(src, res);
>      }
>      finally
>      {
>          out.close();
>      }
> }
>
>
>
>
> Christian Pestel
>
> christian.pestel@orange.fr

Vincent

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org 


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: fo to Intermediate Format transform - Image file locked after transformation / Fop trunk.Feb.11.2013

Posted by Vincent Hennebert <vh...@gmail.com>.
Hi Christian,

On 07/03/13 16:44, Christian Pestel wrote:
> Hi,
>
> I try to convert a fo file to Intermediate Format (IF) file with a fop server (i.e. JVM never terminate)
> fo file contain an external-graphics jpg image.
> The problem  : at the end of FO2IF transformation, the file signature.jpg remain locked by java.

To be more precise the file descriptor corresponding to the image file
was not released, leading to the JVM eventually running out of file
descriptors.

This is because the IF renderer doesn’t close images once it has
‘rendered’ them. See [FOP-2226] for more details.

[FOP-2226] https://issues.apache.org/jira/browse/FOP-2226

The issue should be fixed in rev. 1458382 of the trunk. Thanks for
reporting it.


> This problem don’t happen with fo to pdf transformation.
> This problem don’t happen with fop used with command line because java terminate and close all files.
> I join you a logs.zip (FO2IF.log and FO2PDF.log)
>
> I use version Fop Trunk 1447488   Feb 11 2013
>
> This is my FO source file
>
> <?xml version="1.0" encoding="utf-8"?><fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
> <fo:layout-master-set><fo:simple-page-master master-name="section1" page-width="8.268in" page-height="11.693in" margin-top="35.4pt" margin-bottom="35.4pt" margin-right="70.85pt" margin-left="70.85pt"><fo:region-body margin-top="35.45pt" margin-bottom="35.45pt" /></fo:simple-page-master></fo:layout-master-set><fo:page-sequence master-reference="section1" format="1">
> <fo:flow flow-name="xsl-region-body">
>
> <fo:block><fo:inline><fo:external-graphic src="file:///C:/Images/signature.jpg" /></fo:inline></fo:block>
>
> </fo:flow></fo:page-sequence></fo:root>
>
>
>
> This is my java source file
>
> ...
> Source inputSource = new StreamSource( new File(inputFilename) ); //FO file
> File outputFile = new File(outputFilename);  //IF file
> convertFromIntermediate(inputSource, outputFile, mimeType); // MimeConstants.MIME_PDF or MimeConstants.MIME_AFP for RendererMimic
> ...
>
>
> /**
> * Converts an XSL-FO document to an intermediate file.
> * @param src the source file
> * @param intermediate the target intermediate file
> * @param mimeType the MIME type of the final document
> * @throws IOException In case of an I/O problem
> * @throws FOPException In case of a FOP problem
> * @throws TransformerException In case of a XSL transformation problem
> */
> public void convertToIntermediate(Source src, File intermediate, String mimeType)
>      throws IOException, FOPException, TransformerException
> {
>      FopRunner.trace("Converting to intermediate format...");
>      //Create a user agent
>      FOUserAgent userAgent = fopFactory.newFOUserAgent();
>
>      //Create an instance of the target document handler so the IFSerializer
>      //can use its font setup
>      FopRunner.trace("MIME Type = " + mimeType);
>      IFDocumentHandler targetHandler = userAgent.getRendererFactory().createDocumentHandler(userAgent, mimeType);
>
>      //Create the IFSerializer to write the intermediate format
>      IFSerializer ifSerializer = new IFSerializer(new IFContext(userAgent));
>
>      //Tell the IFSerializer to mimic the target format
>      ifSerializer.mimicDocumentHandler(targetHandler);
>
>      //Make sure the prepared document handler is used
>      userAgent.setDocumentHandlerOverride(ifSerializer);
>
>      // Setup output
>      OutputStream out = new java.io.FileOutputStream(intermediate);
>      out = new java.io.BufferedOutputStream(out);
>
>      try
>      {
>          // Construct FOP (the MIME type here is unimportant due to the override
>          // on the user agent)
>          Fop fop = fopFactory.newFop(null, userAgent, out);
>
>          // Setup XSLT
>          TransformerFactory factory = TransformerFactory.newInstance();
>          Transformer transformer = factory.newTransformer();
>
>          // Resulting SAX events (the generated FO) must be piped through to FOP
>          Result res = new SAXResult(fop.getDefaultHandler());
>
>          // Start XSLT transformation and FOP processing
>          transformer.transform(src, res);
>      }
>      finally
>      {
>          out.close();
>      }
> }
>
>
>
>
> Christian Pestel
>
> christian.pestel@orange.fr

Vincent

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org