We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

File in File

Hi,

I have a word file which contains another word file which contains an image.

So can I convert the entire structure to pdf?

Also can I extract the image and test it?

Regards,

Pramod Talekar

Hi Pramod,


Thanks for your inquiry. Sure, Aspose.Words preserves OLE objects in documents. That is if you open an MS Word document and then save it (possibly in another MS Word format or PDF format) then OLE objects are preserved. You can also access these objects programmatically, extract their data and preview image. Secondly, you can easily extract image from inside an embedded Word document; please let me know if the code mentioned below works for you?
https://forum.aspose.com/t/63637

Best Regards,

Hey,

Thanks a lot for your reply.

I've a situation where I have a word file which contains a word file which contains an image which I need to extract.

Also if the word file contains non word files e.g. excel sheets, then that should be rejected.

I searched in a couple of articles but got error for the below statements :-

if (shape.OleFormat != null)

{
if (!shape.OleFormat.IsLink)
{
//Extract OLE Word object
if (shape.OleFormat.ProgId == "Word.Document.12")
{
MemoryStream stream = new MemoryStream();
shape.OleFormat.Save(stream);

Document newDoc = new Document(stream);
newDoc.Save(string.Format(@"C:\temp\outEmbeded_{0}.pdf", i));

i++;
}

//Extract OLE Excel object
if (shape.OleFormat.ProgId == "Excel.Sheet.12")
{
// Here you can use Aspose.Cells component
// to be able to convert MS Excel files to PDF
}
}
1. shape.OleFormat can't be resolved.
2. MemoryStream can't be resolved.

I'll keep you posted.

Hi Awais,

Please provide the related code for Java.

Hi Pramod,


Thanks for your request. Here is the code, I believe, you’re looking for:
Document doc = new Document(“C:\Temp\main.docx”);

for (Shape shape : (Iterable<Shape>) doc.getChildNodes(NodeType.SHAPE, true)) {
if (shape.getOleFormat() != null) {
if (shape.getOleFormat().getProgId().equals(“Word.Document.12”)) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
shape.getOleFormat().save(baos);

        InputStream inStream <font color="BLUE">=</font> <font color="RED"><b>new</b></font> ByteArrayInputStream<font color="BLUE"><b>(</b></font>baos<font color="BLUE"><b>.</b></font>toByteArray<font color="BLUE"><b>(</b></font><font color="BLUE"><b>)</b></font><font color="BLUE"><b>)</b></font><font color="BLUE"><b>;</b></font>
        Document newDoc <font color="BLUE">=</font> <font color="RED"><b>new</b></font> Document<font color="BLUE"><b>(</b></font>inStream<font color="BLUE"><b>)</b></font><font color="BLUE"><b>;</b></font>

        <font color="RED"><b>int</b></font> i <font color="BLUE">=</font> <font color="BROWN">0</font><font color="BLUE"><b>;</b></font>
        <font color="RED"><b>for</b></font> <font color="BLUE"><b>(</b></font>DrawingML dml <font color="BLUE">:</font> <font color="BLUE"><b>(</b></font>Iterable<font color="BLUE"><</font>DrawingML<font color="BLUE">></font><font color="BLUE"><b>)</b></font> newDoc<font color="BLUE"><b>.</b></font>getChildNodes<font color="BLUE"><b>(</b></font>NodeType<font color="BLUE"><b>.</b></font>DRAWING_ML<font color="BLUE"><b>,</b></font> true<font color="BLUE"><b>)</b></font><font color="BLUE"><b>)</b></font> <font color="BLUE"><b>{</b></font>
            ShapeRenderer r <font color="BLUE">=</font> dml<font color="BLUE"><b>.</b></font>getShapeRenderer<font color="BLUE"><b>(</b></font><font color="BLUE"><b>)</b></font><font color="BLUE"><b>;</b></font>

            ImageSaveOptions imageOptions <font color="BLUE">=</font> <font color="RED"><b>new</b></font> ImageSaveOptions<font color="BLUE"><b>(</b></font>SaveFormat<font color="BLUE"><b>.</b></font>PNG<font color="BLUE"><b>)</b></font><font color="BLUE"><b>;</b></font>
            r<font color="BLUE"><b>.</b></font>save<font color="BLUE"><b>(</b></font><font color="PURPLE">"C:\\temp\\img\\img"</font> <font color="BLUE">+</font> i <font color="BLUE">+</font> <font color="PURPLE">".png"</font><font color="BLUE"><b>,</b></font> imageOptions<font color="BLUE"><b>)</b></font><font color="BLUE"><b>;</b></font>
            i<font color="BLUE"><font color="BLUE">+</font><font color="BLUE">+</font></font><font color="BLUE"><b>;</b></font>
        <font color="BLUE"><b>}</b></font>
    <font color="BLUE"><b>}</b></font>
<font color="BLUE"><b>}</b></font>

}

Please let me know if I can be of any further assistance.

Best Regards,

Hello,

I am looking for a .Net component to convert Word documents to PDF. One of the key requirements that I have is that the embedded objects should be retained and be clickable on the PDF.

For E.g. I have a word document, with 1 excel document and 1 ppt embedded into it as an object. Once the document is converted to PDF, I would like to be able to open the word doc and the ppt from the PDF. They need not be converted into PDF necessarily. They can stay as word and ppt.

Please advise if Aspose Word has the Ability to support this functionality. From your post it looks like it does, but just wanted to confirm.

If Yes, then please let us know if you could share some sample code on the same (in case we need to do any special handling for this).

Thanks much,
Sandeep

Hi,


Thanks for your inquiry. We are checking with this scenario and will get back to you soon.

Best regards,

Hi,

You can use Aspose.Words for .NET to extract OleObjects and then use Aspose.Pdf for .NET to add attachments.

Best Regards,