Hi, we are using the latest ASPOSE library for C # Net Core. We need to convert small and large html files to pdf with the addition of stamps. Unfortunately, when converting large files, a lot of RAM is eaten up, and this is quite slow. I think the whole file is kept in memory as an aspose structure. Is it possible to do streaming conversion? Without holding the entire file structure in memory?
public static byte[] ConvertHtmlToPdf(string html, Stream header = null, string htmlStamp = null)
{
try
{
var htmlOptions = new HtmlLoadOptions();
htmlOptions.PageInfo.IsLandscape = true;
htmlOptions.PageInfo.Width = PageSize.A4.Height * 1.2;
htmlOptions.PageInfo.Height = PageSize.A4.Width * 1.2;
htmlOptions.PageInfo.Margin = new MarginInfo(35, 35, 35, 80);
var document = new Document(new MemoryStream(Encoding.UTF8.GetBytes(html)), htmlOptions);
var pageNumberStamp = new PageNumberStamp
{
Background = false,
Format = "Страница №# из " + document.Pages.Count,
TopMargin = 40.0,
RightMargin = 60.0,
HorizontalAlignment = HorizontalAlignment.Right,
VerticalAlignment = VerticalAlignment.Top,
StartingNumber = 1
};
pageNumberStamp.TextState.Font = FontRepository.FindFont(“Arial”);
pageNumberStamp.TextState.FontSize = 9.0F;
pageNumberStamp.TextState.ForegroundColor = Color.Black;
foreach (var t in document.Pages)
{
t.AddStamp(pageNumberStamp);
}using var ms = new MemoryStream(); document.Save(ms); return ms.ToArray(); } catch (Exception e) { BackgroundWork.LogException(e, "ConvertToPdf ConvertHtmlToPdf"); } return new byte[0]; }