Free Support Forum - aspose.com

Layout In Table Cell suddenly set in Word document

Hi,

We've been testing the 9.7 version and we've been importing images into our documents like this:

Dim shpShape As Aspose.WordsAspose.Words.Drawing.Shape =
builder.InsertImage(fileName:=sFile, _
horzPos:=Aspose.Words.Drawing.RelativeHorizontalPosition.Page, _
Left:=Image.LeftPosition, _
vertPos:=Aspose.Words.Drawing.RelativeVerticalPosition.Page, _
top:=Image.TopPosition, _
width:=Image.Width, _
height:=Image.Height, _
wrapType:=Aspose.Words.Drawing.WrapType.None)
With shpShape
.Fill.On = False
.Stroked = False
.AnchorLocked = True
End With

What we want is place the image floating on a position mesured from the sides of the page.
This all worked fine, so we decided to buy Aspose.Words.

Now we have installed the just bought version 10.1 and to our disapointment suddenly all images are misplaced. When we check inside Word we see that the option 'Layout in Table cell' is checked. This was not the case in de 9.7 version. Is there a way to force this option not to be set?

Hello

Thanks for your request. Could you please attach your input and expected output documents here for testing and also your images? I will check them and provide you more information.

Also as I can see MS Word does the same during inserting images.

Best regards,

I've been investigating it a bit more and found out that even in version 9.7 of Aspose.Words it is not as we wanted. But because the evaluation version added the evaluation message on the begin of the document the table there moved down one line and we did not notice the problem...

The problem we have is actually based on a very old bug of Micorosft Word (I think even when they introduced Word XP):

  • Import a floating image into a document and set its position to 'absolute' measured from the edges of the page;
  • Now move the anchor of the image into a table... Suddenly the postion of the image jumps and is measured from the edges of the table instead of the edges of the page :-(

Microsoft discovered the bug but didn't want to solve it because that would break a lot of their customers macro's, so they kept it in newer Word versions and introduced the option 'Layout in Table Cell'. If you switch off the option, the image is behaving more logical: When you move its anchor in or out of table the position doesn't change...

What we need in our program is the latter behaviour: We want to import an image on some position measured from the page edges and not be dependent on some table that might be in the document or not, so we want the 'Layout in Table Cell' option to be set off - is there a way of doing this with Aspose.Words (Other then importing the evalution text :-))

Hi Frans,

Thank you for additional information. Unfortunately, currently there is no way to set off “Layout in Table Cell” option using Aspose.Words.

But I am wondering how evaluation watermark affects the behavior of shape. It would be great if you attach sample document here to demonstrate the issue. Maybe we will be able to find another workaround.

Best regards,

Hi Frans,

Thanks for your inquiry.

By the sounds of it you can just anchor your image to a paragraph in the document body instead of a table and the issue should disappear.

Please let us know if this is an acceptable solution for you.

Thanks,

Hi Adam,

I understand that moving the anchor solves the problem. The problem is that I don't know where the anchor might be... Our solution is a tool for managing house styles and the end-user can define a template themselve in wich our solution imports an image (the customer marks this location with a bookmark) ... This bookmark might be in the body, but also in a header, a footer or a table...

Ik think for now our solution should be finding out if the bookmark is in a table and if so, minus the position of the table from the wanted postion of the image... The option 'Layout in Table Cell' would be really great to have in a new release because that would solve this issue much more easy. We always used the option 'Layout in table cell' before. (our tool used COM automation for years and now we want to leave that mechanism)

@Alaxey: In your evaluation version the extra evaluation text is entered as the first paragraph in the body. A bookmark which was on the very first position of the body stayed there, but the table which was positioned in the first body-paragrah moved to the next paragraph because of the evaluation text. Result was that the inserted image was anchored in the evaluation text, with the proper result. As soon as the evaluation text was removed when we bought, the anchor ended up in the table again with the unwanted result.

Hi Frans,

Thank you for additional information. I logged your request into our defect database. We will consider exposing this property. We will keep you informed regarding status of this issue and let you know once it is resolved.

If simply adding a paragraph at the beginning of the document resolved the problem. You can use this as a temporary workaround. Just insert an empty paragraph before the table if the table is the first node of the document.

Best regards,

Hi Frans,

Thanks for your inquiry.

You can also work around this issue by creating a template which contains a shape with Layout in table cell turned off, import this node into your document and then set the new image. The resulting image will have layout in table cell disabled.

Please see the code below for a demonstration. I have also attached a sample template containing an example image with this setting turned off. Please note the image is white but can be found at the top of the document.

Document doc = new Document();<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Document imageDoc = new Document("ImageTemplate.doc");

Shape imageShape = (Shape)doc.ImportNode(imageDoc.GetChild(NodeType.Shape, 0, true, true));

imageShape.ImageData.SetImage(File.ReadAllBytes("MyImage.jpg"));

doc.FirstSection.Body.FirstParagraph.AppendChild(imageShape);

Thanks,

Hi Adam,

Thanks for this suggestion. I think for now it is the best solution...

The issues you have found earlier (filed as WORDSNET-4898) have been fixed in this Aspose.Words for .NET 18.8 update and this Aspose.Words for Java 18.8 update.