Aspose.Words generates an empty PDF from the attached mhtml file (I use Enterprise license).
Can you please check if my code does something wrong or there is an issue in product?
Here ist the code:
private static string _inputPath = “…\TestPath”;
private static string _pattern = “*.mhtml”;
public static void ReadAndSaveWordDoc()
{
foreach (FileInfo wordFile in new DirectoryInfo(_inputPath).GetFiles(_pattern, SearchOption.AllDirectories))
{
try
{
Console.WriteLine(string.Format("Processing file '{0}'.", wordFile.FullName));
string testWordDocPath = wordFile.FullName;
SetLicense(Properties.Resources.Aspose_Total);
WordDocs.Saving.PdfSaveOptions options = new WordDocs.Saving.PdfSaveOptions();
WordDocs.LoadOptions loadOptions = new WordDocs.LoadOptions();
loadOptions.LoadFormat = WordDocs.LoadFormat.Mhtml;
WordDocs.Document wordDoc = new WordDocs.Document(testWordDocPath, loadOptions);
string outputPDF = Path.GetFileNameWithoutExtension(testWordDocPath) + ".pdf";
string savePath = Path.GetDirectoryName(testWordDocPath);
options.Compliance = WordDocs.Saving.PdfCompliance.Pdf15;
options.JpegQuality = 90;
options.PageIndex = 0;
options.PageCount = wordDoc.PageCount;
options.ZoomBehavior = WordDocs.Saving.PdfZoomBehavior.FitWidth;
options.CustomPropertiesExport = WordDocs.Saving.PdfCustomPropertiesExport.Standard;
wordDoc.CustomDocumentProperties.Add("CV_TextLayerGood ", true);
string savePdfPath = Path.Combine(savePath, outputPDF);
wordDoc.Save(savePdfPath, options);
}
catch (Aspose.Words.FileCorruptedException)
{
Console.WriteLine(string.Format("File '{0}' is corrupted.", Path.GetFileNameWithoutExtension(wordFile.FullName)));
continue;
}
catch (Aspose.Words.IncorrectPasswordException)
{
Console.WriteLine(string.Format("File '{0}' is password protected.", Path.GetFileNameWithoutExtension(wordFile.FullName)));
continue;
}
catch (Exception)
{
throw;
}
}
}
}
The mhtml file attached in the zip folder.
MHTMLToPDF.zip (3.7 KB)