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.