Hi,
I am trying to generate a PDF as a MemoryStream using the HtmlToPdfResult object. It seems that the Render method works on small webpages, but doesn't work on large webpages. I have placed two examples below.
Does anyone have an idea what the problem might be and how this can be fixed?
Kind regards,
Pierius
--- Small webpage ---
WebPage:
http://tezt.lubricantadvisor.com/Advice.aspx?Lang=Dan&type=%2bkj%2fTU0LRoSuB8%2fl3Cwj4Q%3d%3dPdf generation:
http://tezt.lubricantadvisor.com/Advice.aspx?Lang=Dan&type=%2bkj%2fTU0LRoSuB8%2fl3Cwj4Q%3d%3d&pdf=1&spdf=1--- Large webpage ---
WebPage:
http://tezt.lubricantadvisor.com/Advice.aspx?Lang=Dan&type=ku0EwOu%2bzZ8wjDi0CN%2byCw%3d%3dPdf generation:
http://tezt.lubricantadvisor.com/Advice.aspx?Lang=Dan&type=ku0EwOu%2bzZ8wjDi0CN%2byCw%3d%3d&pdf=1&spdf=1--- Method that handles the PDF generation ---
private void generate()
{
doc = new PdfDocument();
if (url.Equals(""))
{
failed = true;
return;
}
doc.FileStructure.CrossReferenceType = PdfCrossReferenceType.CrossReferenceTable;
doc.FileStructure.Version = PdfVersion.Version1_4;
doc.Compression = PdfCompressionLevel.BestSpeed;
doc.PageSettings.Orientation = PdfPageOrientation.Portrait;
PdfPage page = doc.Pages.Add();
SizeF pageSize = page.GetClientSize();
AddFooter(doc, "");
PdfUnitConvertor convertor = new PdfUnitConvertor();
float width = convertor.ConvertToPixels(page.GetClientSize().Width, PdfGraphicsUnit.Point);
using (HtmlConverter html = new HtmlConverter())
{
html.AutoDetectPageBreak = true;
html.EnableHyperlinks = false;
HtmlToPdfResult result = html.Convert(url, ImageType.Metafile, (int)width, -1, AspectRatio.KeepWidth);
if (result == null)
{
failed = true;
return;
}
PdfMetafile mf = new PdfMetafile(result.RenderedImage as Metafile);
mf.Quality = 100;
PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();
format.Break = PdfLayoutBreakType.FitPage;
format.Layout = PdfLayoutType.Paginate;
doc.PageSettings.Height = result.RenderedImage.Size.Height;
format.SplitTextLines = false;
format.SplitImages = false;
result.Render(page, format);
mf.Dispose();
html.Dispose();
}
if (doc != null)
{
success = true;
failed = false;
}
else
{
failed = true;
}
}