We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Html to pdf System.ArgumentException was unhandled by user code

Hi


I’m trying to save a html email as pdf but aspose.pdf throws System.ArgumentException “value”. Here is code to replicate the issue.

Code:

string b =
“<p class=“MsoNormal” style=“text-align: justify; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;”><span style=“font-family: ‘Bell MT’, serif;”>Dear Mr Test<span style=“font-family: Tahoma, sans-serif;”><o:p></o:p>”;

byte[] correspondenceBytes = Encoding.UTF8.GetBytes(b);
string fileName = “c:\temp\test.pdf”;
using (MemoryStream ms = new MemoryStream(correspondenceBytes))
{
Document document = new Document(ms, new HtmlLoadOptions()); // Exception
document.Save(fileName, SaveFormat.Pdf);
}

Stack trace:

System.ArgumentException was unhandled by user code
HResult=-2147024809
Message=value
Source=Aspose.Pdf
StackTrace:
at . .TryGetValue(String token, & value)
at . .GetValue(String )
at . . T
at . . T
at . . ()
at . .Initialize( , )
at . …ctor( , , )
at . …ctor( , )
at . . ( )
at . . ( )
at . . ( )
at . . ( )
at . . ( )
at . . ( )
at . . ( )
at . . ( )
at . . ( )
at . .Convert( , )
at . .Convert(Stream , )
at . .Convert(Stream , Document , , HtmlLoadOptions )
at Aspose.Pdf.Document. (Stream , LoadOptions )
at Aspose.Pdf.Document…ctor(Stream input, LoadOptions options)

If I remove “background-attachment” etc. from style then pdf is generated.

Thanks

Sourabh

Aspose.Pdf 10.9.0.0

Hi Sourabh,


Thanks for contacting support.

I have tested the scenario and I am able to
notice the same problem. For the sake of correction, I have logged this problem
as PDFNEWNET-40043 in our issue tracking system. We will
further look into the details of this problem and will keep you updated on the
status of correction. Please be patient and spare us little time. We are sorry
for this inconvenience.

The issues you have found earlier (filed as PDFNET-40043) have been fixed in Aspose.PDF for .NET 19.11.