Hi, I have a problem. The goal is to take different files like PDF or PPT, convert these files to docx documents and then embedd these files into a word document.
The convertion to docx goes fine, and I amd also able to add them into the word document as embedded files (OLE objects). But when I open the embedded file, instead of images I receive an error that says “The linked image cannot be displayed. The file may have been moved, renamed or deleted. Verify the link points to the correct file and location”.
I am not sure what to do. The code is very simple for this:
class Program
{
static void Main(string[] args)
{
var fsPdf = File.ReadAllBytes(@"<path to pdf with linked images>");
var docxBytes = ConvertPdfToDocx(fsPdf);
File.WriteAllBytes(@"<path of converted pdf to docx file>", docxBytes);
CreateFileWithEmbeddedFile(null);
Console.Read();
}
private static void CreateFileWithEmbeddedFile(byte[] embedded)
{
var document = new Aspose.Words.Document();
var builder = new DocumentBuilder(document);
//var ms = new MemoryStream(embedded);
builder.InsertOleObject(@"<path of converted pdf to docx file>", false, true, null);
document.Save(@"<path of file that contains the coverted file as embedded file>");
}
private static byte[] ConvertPdfToDocx(byte[] docData)
{
using (var msDoc = new MemoryStream(docData))
using (var msTmp = new MemoryStream())
{
var doc = new Aspose.Pdf.Document(msDoc);
var saveOptions = new Aspose.Pdf.DocSaveOptions
{
Format = Aspose.Pdf.DocSaveOptions.DocFormat.DocX,
ExtractOcrSublayerOnly = false,
};
doc.Save(msTmp, saveOptions);
return msTmp.ToArray();
}
}
}
I use the 21.40 version.
Thanks. DIma