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

Free Support Forum - aspose.com

Programmatic workaround for floating images issue

Hi,

Could you please provide a programmatic workaround for floating images issue happening during word to pdf conversion?

This is a known bug by you already and I understand that you are working on it. Also workaround you provided such as changing image layout settings to 'inline with text' is a manual workaround.

This issue is extremely high priority for us and unfortunately we are holding our release beacause of this issue. An urgent programmatic workaround is needed.

If we can simulate manual workaround programmatically, I believe this much improvement will be acceptable as for now. Since currently floating images result in loss of content by overlaping other images/text, changing their layout setting to 'inline with text' programmatically will at least resolve loss of content.

Thanks

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. You can try to set wrapping of all shapes in your document as shown in the following code:

// Open document.

Document doc = new Document(@"Test001\in.doc");

// Get all shapes.

NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true);

// loop through all shapes and change wrapping.

foreach (Shape shape in shapes)

shape.WrapType = WrapType.Inline;

// Save output document.

doc.Save(@"Test001\out.pdf");

I hope this could help you.

Best regards.

Thanks for your reply. With code you provided, i was able to convert layout of all images to inline. Doing so, now images are not overlapping with text anymore, which also means that there is no content loss.

However now the paragraph starts right after the image, resulting in a slight format loss.

Is it possible to enter a new line (blank line) after each image, so that at least paragraph starts from a new line rather than right next to image itself?

I'll be glad if you can modify your sample code above accordingly so that it inserts a new line after each image.

Thanks

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. Please try using the following code:

// Open document.

Document doc = new Document(@"Test001\in.doc");

DocumentBuilder builder = new DocumentBuilder(doc);

// Get all shapes.

NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true);

// loop through all shapes and change wrapping.

foreach (Shape shape in shapes)

{

shape.WrapType = WrapType.Inline;

if (shape.NextSibling != null)

{

builder.MoveTo(shape.NextSibling);

builder.Writeln();

}

}

// Save output document.

doc.Save(@"Test001\out.doc");

Hope this helps.

Best regards.

I realized one thing after changing images to inline, that is, text which should go before image is now displayed after image.

For ex, firstly there is a paragraph for description and then a non-inline image and below that one line saying 'Figure xyz'. In such a case, after changing image to inline, now document flow is,

1. image 2. paragraph 3.figure description

where it should be

1. paragraph 2.image 3.figure desciption.

So, my question is: how can i swap places of those two nodes, namely, image node and paragraph node, so that it appears with correct flow as mentioned above? Can you please provide a code sample for that?

Thanks

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. Actually, when you make a shape inline, it is moved to its original place. When you insert floating shapes into the document, you can drag it where you need. But anyway shape is inserted at the cursor position. You can see this if open your document using DocumentExplorer (Aspose.Words demo application).

Best regards.