I have a large html file, want to convert to pdf. But it stopped for a long time.
code:
public virtual Stream Convert(Stream inputStream)
{
var outputStream = new MemoryStream();
var options = GetOptions();
using (var middleStream = new MemoryStream())
{
try
{
inputStream.Seek(0, SeekOrigin.Begin);
inputStream.CopyTo(middleStream);
middleStream.Seek(0, SeekOrigin.Begin);
var pdf = new Document(middleStream, options);
pdf.Save(outputStream, SaveFormat.Pdf);
outputStream.Seek(0, SeekOrigin.Begin);
middleStream.Close();
}
catch (Exception e)
{
throw new Exception(String.Format(“An error occurred when convert to pdf. Exception :{0}”, e));
}
}
return outputStream;
}
public override LoadOptions GetOptions()
{
var htmlLoadOptions = new HtmlLoadOptions();
htmlLoadOptions.PageInfo.Margin.Bottom = 10;
htmlLoadOptions.PageInfo.Margin.Top = 20;
return htmlLoadOptions;
}
it stopped at var pdf = new Document(middleStream, options);
And it occupied a large number of my computer memory