You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-dev@xmlgraphics.apache.org by bu...@apache.org on 2011/05/17 12:20:27 UTC
DO NOT REPLY [Bug 51210] New: FO transform to PDF completely in
memory!? => OutOfMemoryError
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: fop-dev@xmlgraphics.apache.org
ReportedBy: mhilpert@gmx.de
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.
DO NOT REPLY [Bug 51210] FO transform to PDF completely in memory!?
=> OutOfMemoryError
Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=51210
Glenn Adams <gl...@skynav.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |CLOSED
--- Comment #2 from Glenn Adams <gl...@skynav.com> 2012-04-01 13:42:42 UTC ---
batch transition to closed for remaining resolved bugs
--
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
DO NOT REPLY [Bug 51210] FO transform to PDF completely in memory!?
=> OutOfMemoryError
Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=51210
Andreas L. Delmelle <ad...@apache.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |DUPLICATE
OS/Version| |All
--- Comment #1 from Andreas L. Delmelle <ad...@apache.org> 2011-05-24 21:45:50 UTC ---
(In reply to comment #0)
> 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!?
Yes and no.
The entire content would only be in memory if any of the following conditions
are met:
* all content is placed inside a single fo:page-sequence
* the document contains forward references to the last fo:page-sequence
(typically: "page x of y" requirements, or TOCs at the start of a huge
document)
The former can currently only be resolved by splitting up the input, which
means altering the stylesheet code, and an unavoidable trade-off of a forced
page break, but is considered better practice anyway. A monolithic
page-sequence (as its correlate: paragraph) is a typographical monstrosity.
The impact of the latter can be reduced by calling
foUserAgent.setConserveMemoryPolicy(true);. That will result in finished pages
with unresolved references being serialized to disk.
In other cases, if a page-sequence can be rendered, it will be. I am not 100%
sure, but I even think that, if the output stream can be written to disk, it
will be. Ultimately, that is also a decision of the JVM/OS.
Marking this as a duplicate of bug #1063. Until that is resolved: see above.
*** This bug has been marked as a duplicate of bug 1063 ***
--
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.