Saving to memory stream results in a "Illegal characters in path" error

I am converting .mht files to pdf. Most of the files work 100%, but some .mht files result in the following error when I call Aspose.Pdf.Generator.PdfAspose.Pdf.Generator.Pdf.Save(memorystream);

Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();
Aspose.Pdf.Generator.Section section = pdf.Sections.Add();

using (StreamReader r = File.OpenText(fileToCombine))
{
Aspose.Pdf.Generator.Text text2 = new Aspose.Pdf.Generator.Text(section, r.ReadToEnd());
text2.IsHtmlTagSupported = true;
section.Paragraphs.Add(text2);
}

MemoryStream ms = new MemoryStream();
pdf.Save(ms);
var pdfDocument = new Aspose.Pdf.Document(ms);
foreach (Page page in pdfDocument.Pages)
{
document.Pages.Add(page);
} Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();
Aspose.Pdf.Generator.Section section = pdf.Sections.Add();

using (StreamReader r = File.OpenText(fileToCombine))
{
Aspose.Pdf.Generator.Text text2 = new Aspose.Pdf.Generator.Text(section, r.ReadToEnd());
text2.IsHtmlTagSupported = true;
section.Paragraphs.Add(text2);
}

MemoryStream ms = new MemoryStream();
pdf.Save(ms); // this line throws an error with specific files
var pdfDocument = new Aspose.Pdf.Document(ms);
foreach (Page page in pdfDocument.Pages)
{
document.Pages.Add(page);
}

The error details are:

System.ArgumentException was caught
Message=Illegal characters in path.
Source=mscorlib
StackTrace:
at System.IO.Path.CheckInvalidPathChars(String path)
at System.IO.Path.Combine(String path1, String path2)
at . . ( , Image )
at . . ( )
at . . ( , Int32 )
at . . ( , Int32 )
at . . ( , Int32 )
at . . ( )
at . . (String )
at . . (Pdf , Section , Cell , Text , HeaderFooter , , )
at . . (Pdf , Section , Table , Cell , Text , HeaderFooter , , )
at . . (Pdf , Section , HeaderFooter , Table , Row , Cell , Text , , , Boolean )
at . . (Pdf , Section , )
at . . (Pdf )
at . . ( , Pdf )
at Aspose.Pdf.Generator.Pdf.Save(Stream stream)
at PDFCombine.PDFCombine.appendHTMLFileToPDFDocument(String fileToCombine, Document document) in c:\Work\Personal\Jason\Projects\Test\PDFCombine\PDFCombine\PDFCombine.cs:line 414
at PDFCombine.PDFCombine.combinePDFWithAssociatedFiles(String pdfFilePath) in c:\Work\Personal\Jason\Projects\Test\PDFCombine\PDFCombine\PDFCombine.cs:line 143
InnerException:
System.ArgumentException was caught
Message=Illegal characters in path.
Source=mscorlib
StackTrace:
at System.IO.Path.CheckInvalidPathChars(String path)
at System.IO.Path.Combine(String path1, String path2)
at . . ( , Image )
at . . ( )
at . . ( , Int32 )
at . . ( , Int32 )
at . . ( , Int32 )
at . . ( )
at . . (String )
at . . (Pdf , Section , Cell , Text , HeaderFooter , , )
at . . (Pdf , Section , Table , Cell , Text , HeaderFooter , , )
at . . (Pdf , Section , HeaderFooter , Table , Row , Cell , Text , , , Boolean )
at . . (Pdf , Section , )
at . . (Pdf )
at . . ( , Pdf )
at Aspose.Pdf.Generator.Pdf.Save(Stream stream)
at PDFCombine.PDFCombine.appendHTMLFileToPDFDocument(String fileToCombine, Document document) in c:\Work\Personal\Jason\Projects\Test\PDFCombine\PDFCombine\PDFCombine.cs:line 414
at PDFCombine.PDFCombine.combinePDFWithAssociatedFiles(String pdfFilePath) in c:\Work\Personal\Jason\Projects\Test\PDFCombine\PDFCombine\PDFCombine.cs:line 143
InnerException:

I have attached the .mht file.

Hi Jason,


Thanks for using our products.

I have tested the scenario and I am able to notice the same problem. For the sake of correction, I have logged this issue as PDFNEWNET-34745 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.

I presume an ETA is out of the question?? Do you have any workarounds for us? Or should we put our project on hold and inform the customer that the project will be late due the faulty software from Aspose??

Hi Jason,

Thanks for your inquiry. I have verified the status of your issue. The development team has completed the analysis phase and it is pending in the queue for development. I have requested the team for ETA and as soon as I get feedback, I will update you via this forum thread.

Sorry for the inconvenience faced.

Best Regards,

Hi Jason,

Thanks for your patience. We have investigated the issue and would like to suggest you to use new DOM appraoach for MHT to PDF conversion, it will resolve the exception issue. However, unfortunately we have noticed that image is not rendering in resultant PDF, so we have logged another issue PDFNEWNET-40595 to rectify it. We will notify you as soon as it is resolved.

Aspose.Pdf.MhtLoadOptions options = new Aspose.Pdf.MhtLoadOptions();

Aspose.Pdf.Document doc = new Aspose.Pdf.Document("EXM_44083_REY001_5008640.Mht", options);

doc.Save("output.pdf");

We are sorry for the inconvenience.

Best Regards

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