Rank: Newbie Groups: Member
Joined: 8/17/2012 Posts: 3
|
I'm converting multiple html files into a single pdf by calling ConvertToHtml multiple times and it's working beautifully. However, when I try to loop through the pages after the fact to add footer content, I run into an OutOfMemory exception. Can someone please point out what I'm doing wrong?
Code: C#
PdfDocument doc = new PdfDocument();
HtmlToPdf.Options.PageSize = new SizeF(PdfPageSizes.Letter.Width, PdfPageSizes.Letter.Height);
HtmlToPdf.Options.AutoFitX = HtmlToPdfAutoFitMode.None;
HtmlToPdf.Options.AutoFitY = HtmlToPdfAutoFitMode.None;
float pageWidth = HtmlToPdf.Options.PageSize.Width-(float)0.25;
float pageHeight = HtmlToPdf.Options.PageSize.Height - (float)1.75;
HtmlToPdf.Options.OutputArea = new RectangleF(1.0f, 1.0f, pageWidth, pageHeight);
HtmlToPdf.ConvertHtml(html, doc); //<--- called several times for different html
for (int i = 0; i < doc.Pages.Count; i++)
{
AcmRender render = new AcmRender(doc.Pages[i], 0, new AcmPageLayout(new AcmPadding(0)));
AcmText text = new AcmText(string.Format("Page {0} of {1}", i + 1, doc.Pages.Count));
text.Style.ForegroundColor = Color.LightGray;
AcmBlock block = new AcmBlock(text);
block.Style.Top = 11.15f;
block.Style.Left = 7.0f;
AcmBlock footer = new AcmBlock(block);
render.Render(footer);
}
MemoryStream stream = new MemoryStream();
doc.Save(stream);
return stream.ToArray();
While debugging, I have noticed that every time render.Render() is called another page gets added to my doc.Pages collection. It just keeps expanding until I run out of memory. Thanks.
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,196
|
Hi,
You must make sure the footer renders within the page. Your page size is Letter size, the height of letter size is 11 inch. So you can not put your text at 11.15f. That will cause automatic overflow to the next page, and when the next page does not exist, it will automatically add a new page. Thus causing the problem for you.
Thanks!
|