FONET out of memory error

Sep 16, 2009 at 4:18 PM

HI am using Fonet to generate pdfs from an xml file and an xsl file. This has been working fine for small xml files however I have encountered a larger than normal xml record adn the result is that processing takes an age and eventually times out and throws the following error:

System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
   at Fonet.Fo.FOText.Layout(Area area)
   at Fonet.Fo.Flow.Block.Layout(Area area)
   at Fonet.Fo.Flow.TableCell.Layout(Area area)
   at Fonet.Fo.Flow.TableRow.Layout(Area area)
   at Fonet.Fo.Flow.AbstractTableBody.Layout(Area area)
   at Fonet.Fo.Flow.Table.Layout(Area area)
   at Fonet.Fo.Flow.Block.Layout(Area area)
   at Fonet.Fo.Flow.TableCell.Layout(Area area)
   at Fonet.Fo.Flow.TableRow.Layout(Area area)
   at Fonet.Fo.Flow.AbstractTableBody.Layout(Area area)
   at Fonet.Fo.Flow.Table.Layout(Area area)
   at Fonet.Fo.Flow.Flow.Layout(Area area, Region region)
   at Fonet.Fo.Flow.Flow.Layout(Area area)
   at Fonet.Fo.Pagination.PageSequence.Format(AreaTree areaTree)
   at Fonet.StreamRenderer.Render(PageSequence pageSequence)
   at Fonet.Fo.FOTreeBuilder.EndElement()
   at Fonet.Fo.FOTreeBuilder.Parse(XmlReader reader)

The pdf does not contain any graphics. Any help or advice you can give would be much appreciated.

Sep 17, 2009 at 11:02 AM
I have found the cause of this issue. It was caused by content spanning over pages and a wrongly set Keep-together="Always" Thanks for your time
Oct 23, 2009 at 9:48 AM

DecMac,

<Quote>HI am using Fonet to generate pdfs from an xml file and an xsl file.</Quote>

Can I ask how you are using FO.NET to do the above as I can't find a way to specify and Input XML and an Input XSL file?

Oct 24, 2009 at 8:37 AM

ok in your aspx page code behind create something like

protected void Page_Load(object sender, EventArgs e)
    {

        XmlDocument xml = new XmlDocument();

//get or create your xml somehow and also the xslfile name

//at this stage I have already created these and added them to the session cache so I have something like


        xml = (XmlDocument)Session["CRXML"];
        string xslFile = (string)Session["xslFile"];

        byte[] getBytes;
        try
        {
           
            getBytes = PDFGenerator.StreamPDF(xml, Server.MapPath(xslFile));
        }
        catch (Exception ec)
        {

            throw;
        }

        Response.Clear();
        Response.AddHeader("Accept-Header", getBytes.Length.ToString());
        Response.ContentType = "application/pdf";
        Response.OutputStream.Write(getBytes, 0, Convert.ToInt32(getBytes.Length));
        Response.Flush();
        try { Response.End(); }
        catch { }
        

    }

Then create a class like so

public class PDFGenerator
    {
        public static byte[] StreamPDF(XmlDocument objSourceData, string XSLTFile)
        {
            XslCompiledTransform xslt = new XslCompiledTransform();
            xslt.Load(XSLTFile);
            MemoryStream ms = new MemoryStream();
            xslt.Transform(objSourceData, null, ms);
            MemoryStream output = new MemoryStream();
            XmlDocument doc = new XmlDocument();
            ms.Position = 0;
            doc.Load(ms);

            // Set options of the PDF document
            PdfRendererOptions options = new PdfRendererOptions();
            options.EnableAdd = false;
            options.EnableCopy = false;
            options.EnableModify = false;
            options.Title = "some title";


            // Create the pdf
            FonetDriver driver = FonetDriver.Make();
            driver.Options = options;
            driver.Render(doc, output);
            return output.ToArray();
        }
    }

 

HTH

Declan

Oct 26, 2009 at 8:25 AM

Declan,

Although I am not using ASP.NET ( WinForms ) your code sample fills in the missing info that I need.

Many thanks,

Martin

Nov 1, 2013 at 2:57 PM
Regarding the original post, I am also getting a problem with keep-together='always' when the content's height is more than the page height. The Fo.Net code enters an infinite loop.

The w3c standard states that for keep-together='always', the renderer should raise an overflow error. However, I require it to actually continue to render the rest of the row/table on the subsequent page. Anyone got any ideas on how to do this?

I don't mind modifying the Fo.Net code, if someone can give me a pointer.

Thanks in advance.

Kevin