Hello, we are using Aspose.HTML to convert an HTML page to PDF. We have styling to create page breaks when printing but when that style is applied in Aspose.HTML it causes the application to lock up and enter an infinite loop. We are on version 23.12.0 of Aspose.HTML for .NET. Application is not dotnet core, it is dotnet framework.
public static byte[] ConvertHTMLToPDF(string html, bool landscape = false)
{
using (var config = new Aspose.Html.Configuration())
{
config.Security |= Sandbox.Scripts;
using (var doc = new HTMLDocument(html, ConfigurationManager.AppSettings["APIUrl"] ?? string.Empty, config))
{
var saveOptions = new Aspose.Html.Saving.PdfSaveOptions
{
JpegQuality = 100
};
double width = landscape ? 11 : 8.5;
double height = landscape ? 8.5 : 11;
var pageSize = new Aspose.Html.Drawing.Size(Aspose.Html.Drawing.Unit.FromInches(width), Aspose.Html.Drawing.Unit.FromInches(height));
var pageMargin = new Aspose.Html.Drawing.Margin(20, 10, 20, 10);
saveOptions.PageSetup.PageLayoutOptions = Aspose.Html.Rendering.PageLayoutOptions.ScaleToPageWidth;
saveOptions.PageSetup.AnyPage = new Aspose.Html.Drawing.Page(pageSize, pageMargin);
using (var streamprovider = new AsposeHtmlStreamProvider())
{
// A "Nullable object must have a value" exception from Aspose here seems to
// indicate a failure to break pages cleanly. Try converting a single page
// worth of content at a time.
Aspose.Html.Converters.Converter.ConvertHTML(doc, saveOptions, streamprovider);
return streamprovider.Streams.First().ToArray();
}
}
}
}
HTML is like this:
.page-break {
page-break-before: always;
break-before: always;
break-before: page;
}
..markup
<div class="page-break"></div>
..more markup