Thanks for your quick response.
There is no downtime when opening HTML page in IE browser under user account we use to render PDF. Are there any other reasons why thread may hang? Could you please review the following code:
[STAThread]
public static MemoryStream Convert(byte[] content, string uriString, bool isAttachment, string userName = null, string password = null)
{
PdfDocument pdfDocument;
pdfDocument = new PdfDocument();
pdfDocument.PageSettings.Orientation = PdfPageOrientation.Portrait;
PdfPage page = pdfDocument.Pages.Add();
PdfUnitConvertor convertor = new PdfUnitConvertor();
float width = -1;
float height = -1;
SizeF pageSize = page.GetClientSize();
width = convertor.ConvertToPixels(pageSize.Width, PdfGraphicsUnit.Point);
using (HtmlConverter html = new HtmlConverter())
{
html.EnableJavaScript = true;
html.AutoDetectPageBreak = true;
html.EnableHyperlinks = false;
using (HtmlToPdfResult result = html.Convert(uriString, ImageType.Metafile, (int)width, (int)height, AspectRatio.KeepWidth, userName, password))
{
if (result.RenderedImage == null)
throw new Exception("Error Randering HTML Image");
PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();
format.Break = PdfLayoutBreakType.FitPage;
format.Layout = PdfLayoutType.Paginate;
format.SplitTextLines = false;
format.SplitImages = true;
result.Render(page, format);
}
MemoryStream resultStream = new MemoryStream();
pdfDocument.Save(resultStream);
return resultStream;
}
}
Note, that stream size is no more than 3Mb, therefore it is unclear why it takes so long to execute (we experience 30 sec timeout).
Have you encountered any similar problems with methods HtmlToPdfResult.Render or PdfDocument.Save? Can they cause any memory leaks, etc? Looking forward to your reply.