I have a program that loops through Microsoft Office files, converts them to a PDF steam, and then adds them to a single PDF.
When adding the converted Word documents to the main PDF I receive the following error:
Aspose.Total for .NET
Words 16.3.0.0
PDF 11.5.0.0
Sample Code:
Document masterPDF = new Document();
masterPDF.Pages.Add(Convert2PDF(fileName).Pages);
public static Document Convert2PDF(string path)
{
MemoryStream stream = new MemoryStream();
switch (Path.GetExtension(path).ToLower())
{
case ".pdf":
Document doc = new Document(path);
return doc;
case ".xls":
Workbook workbook = new Workbook(path);
workbook.Save(stream, Aspose.Cells.SaveFormat.Pdf);
break;
case ".doc":
case ".docx":
Aspose.Words.Document word = new Aspose.Words.Document(path);
WarningCallback warningCallback = new WarningCallback();
warningCallback.FileName = Path.GetFileName(path);
word.WarningCallback = warningCallback;
word.Save(stream, Aspose.Words.SaveFormat.Pdf);
break;
case ".ppt":
using (Aspose.Slides.Presentation pres = new Aspose.Slides.Presentation(path))
{
pres.Save(stream, Aspose.Slides.Export.SaveFormat.Pdf);
}
break;
default:
return new Document();
}
return new Document(stream);
}
public class WarningCallback : Aspose.Words.IWarningCallback
{
public string FileName { set; get; }
public void Warning(Aspose.Words.WarningInfo info)
{
//Log Warnings
}
}