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

Free Support Forum - aspose.com

Image position on page is not correct when it is inside table's cell using C#

When positioning an image vertically on the top right of a page margin the image ends up in a table cell when the page only contains a table. Please click the link below for example and code. In the document on page 7 is an example of the issue.

https://drive.google.com/file/d/1TGGCzoddlyCA-YJPNx_ZHgqS6326GkgD/view?usp=sharing

@johnmann04

You can use ShapeBase.IsLayoutInCell property to set a flag indicating whether the shape is displayed inside a table or outside of it.

In ResizeAndPositionBarcode method, you can use following code to set this property.

bool isInCell = shape.GetAncestor(NodeType.Cell) != null;
if (isInCell)
{
    shape.IsLayoutInCell = false;
}

Moreover, you need to save the document with following compatibility options.

doc.CompatibilityOptions.OptimizeFor(MsWordVersion.Word2010);
doc.Save(@"c:\temp\20.2.docx");

If you do not want to optimize document for MsWordVersion.Word2010, you can use layout API to get the position of bookmark/shape inside the table’s cell and set the position of shape using Shape.Left and Shape.Top properties.

I think, you want to save the final document to PDF. So, please use the first approach to get the desired output.

Thank you very much that fixed the issue with the table cell.

@johnmann04

Thanks for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.