Free Support Forum - aspose.com

Zero Length SVG Crashes PDF Conversion

When a web site returns an empty file in error for a referenced SVG the conversion crashes. With other formats such as GIF, the ALT text is rendered. The sample code produces the same error with a local empty SVG file.

Sample Code
const string zeroLengthFile = “ZeroLength.svg”;
File.WriteAllText(zeroLengthFile, “”);
var html = $"<html><body><img alt=‘Test Image’ src=’{zeroLengthFile}’></body></html>";
using (var document = new Aspose.Html.HTMLDocument(html, “.”))
Aspose.Html.Converters.Converter.ConvertHTML(document, new PdfSaveOptions(), “out.pdf”);

@GrantWalker

Could you please provide the corrupted or a 0KB SVG sample file? We will test the scenario in our environment and address it accordingly.

Hi, the forum won’t allow me to upload SVG files. The sample is just an empty file (eg zero bytes) with an SVG extension. The line with “WriteAllText” creates an empty file with the appropriate extension.

private static void ZeroLengthTest()
{
	const string zeroLengthFile = "ZeroLength.svg";
	File.WriteAllText(zeroLengthFile, "");

	var html = $"<html><body><img alt='Test Image' src='{zeroLengthFile}'></body></html>";

	using (var document = new Aspose.Html.HTMLDocument(html, "."))
		Aspose.Html.Converters.Converter.ConvertHTML(document, new PdfSaveOptions(), "out.pdf");
}

@GrantWalker

Sorry for the delayed response.

We have tested the scenario in our environment while using Aspose.HTML for .NET 20.9 and were able to notice that ALT text was not showing completely in the output PDF. Therefore, have logged an issue as “HTMLNET-2844” in our issue management system. We will further look into its details and keep you posted with the status of its rectification. Please be patient and spare us some time.

We are sorry for the inconvenience.