Here is the bulk of the code. The images are there because they are displayed on the same page that the download to pdf button is on and they display some of the time.
Any assistance would be appreciated.
- Code: Select all
var t = new Thread(() =>
{
try
{
using (var doc = new PdfDocument())
{
var format = new PdfHtmlLayoutFormat()
{
FitToPage = Clip.None,
FitToHtml = Clip.None,
Layout = PdfLayoutType.OnePage
};
var settings = new PdfPageSettings(PdfPageOrientation.Portrait)
{
Size = PdfPageSize.A3,
Margins = new PdfMargins(10, 30)
};
doc.LoadFromHTML(html, true, settings, format);
doc.DocumentInformation.Author = "blah";
doc.DocumentInformation.CreationDate = DateTime.Now;
string fileName = "Filename.pdf";
doc.SaveToHttpResponse(fileName, response, HttpReadType.Save);
doc.Close();
}
// There is a memory leak on the nuget version of this library...
// GC.Collect();
}
catch (Exception ex)
{
response.ContentType = "text/html";
viewBag.Message = ex.ToString();
}
});
t.SetApartmentState(ApartmentState.STA);
// synchronous execution
t.Start();
t.Join();