https://issues.apache.org/bugzilla/show_bug.cgi?id=51210
Bug #: 51210
Summary: FO transform to PDF completely in memory!? =>
OutOfMemoryError
Product: Fop
Version: 1.0
Platform: PC
Status: NEW
Severity: normal
Priority: P2
Component: general
AssignedTo: [email protected]
ReportedBy: [email protected]
Classification: Unclassified
So far, we had no problems transforming *.fo files with FOP 1.0 to PDF. Now, we
get OutOfMemoryErrors for *.fo files of about 150 MB and bigger. We tried the
64 Bit JVM with -Xmx2048m and still get OutOfMemoryError after a while.
During the long period of PDF transformation we noticed that the destination
*.pdf file is not increasing in size but stays at 0 KB! Therefore, it seems
that FOP/Transform is trying to generate the PDF completely in RAM!?
My transformation method:
--------------------------------------------------------------
/**
* Transform XSL-FO.
*
* @param nameOfInputFile Name of input FO file (e.g. "Test.fo").
* @param nameOfOutputFile Name of output PDF file (e.g. "Test.pdf").
* @param mimeType MIME type for the output format (e.g.
MimeConstants.MIME_PDF).
* @return The generated PDF file or null if failed.
* @throws Exception on error.
* @since 4.15.0
* @see <a
href="http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleFO2PDF.java?view=markup">convertFO2PDF()</a>
*/
@SuppressWarnings("unchecked")
public final File transformFO(final String nameOfInputFile, final String
nameOfOutputFile, final String mimeType) throws Exception {
File result = null;
OutputStream os = null;
try {
final File fileOutput = new File(nameOfOutputFile);
os = new BufferedOutputStream(new FileOutputStream(fileOutput));
final Fop fop = fopFactory.newFop(mimeType, foUserAgent, os);
final StreamSource ssFO = new StreamSource(new
File(nameOfInputFile));
final Transformer transformer = factory.newTransformer();
transformer.setErrorListener(new ErrorListener() {
@Override
public void error(TransformerException exception) throws
TransformerException {
LOGGER.severe("transformFO("+nameOfInputFile+"):
"+exception.getMessage(), exception);
}//error()
@Override
public void fatalError(TransformerException exception) throws
TransformerException {
LOGGER.severe("transformFO("+nameOfInputFile+"):
"+exception.getMessage(), exception);
}//fatalError()
@Override
public void warning(TransformerException exception) throws
TransformerException {
LOGGER.warning("transformFO("+nameOfInputFile+"):
"+exception.getMessage(), exception);
}//warning()
});
final Result res = new SAXResult(fop.getDefaultHandler());
transformer.transform(ssFO, res);
if (LOGGER.isLoggable(Level.FINE)) {
final FormattingResults foResults = fop.getResults();
LOGGER.fine("Generated " + foResults.getPageCount() + " PDF
pages in total:");
final List<PageSequenceResults> pss =
foResults.getPageSequences();
for (final PageSequenceResults psr : pss) {
LOGGER.fine("PageSequence " +
(String.valueOf(psr.getID()).length() > 0 ? psr.getID() : "<no id>") + "
generated " + psr.getPageCount() + " pages.");
}
}
result = fileOutput;
} finally {
if (os != null) { os.close(); }
}
return result;
}//transformFO()
--------------------------------------------------------------------------
--
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.