Hello Team,
We are using the below mentioned code to insert an image in the document but image is getting overlapped with the footer of the page. it is not identifying the space is there or not.
Document doc = new Document(filepath);
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveToDocumentEnd();
Aspose.Words.Drawing.Shape shape = builder.InsertImage(path + "input\\Dummy.jpg");
shape.WrapType = WrapType.None;
shape.RelativeHorizontalPosition = RelativeHorizontalPosition.Page;
shape.HorizontalAlignment = Aspose.Words.Drawing.HorizontalAlignment.Center;
shape.VerticalAlignment = VerticalAlignment.Bottom;
shape.AllowOverlap = false;
doc.Save(path + "output\\Output2.doc");
Dummy.zip (15.1 KB)
We are using ASPOSE.WORD 23.4 (latest version)
Attachment is there for reference
@Sudrashya You should use RelativeVerticalPosition.Margin
to get the desired result:
shape.RelativeHorizontalPosition = RelativeHorizontalPosition.Page;
shape.HorizontalAlignment = HorizontalAlignment.Center;
shape.RelativeVerticalPosition = RelativeVerticalPosition.Margin;
shape.VerticalAlignment = VerticalAlignment.Bottom;
Hello @alexey.noskov,
Thanks for response.
The solution is not working it is overlapping the text of last line in the page. please insert some more text in the last line of page.
Error.JPG (33.8 KB)
@Sudrashya This is an expected behavior. The shape is absolutely positioned and is placed above the document’s content. If you would like to place the shape behind content, you can use Shape.BehindText
property:
shape.BehindText= true;
Hello @alexey.noskov
In our case image is the legal stamp which can not go behind and vice versa. If space is not available for the image then it must go in the second page bottom.
@Sudrashya In this case you should use WrapType.Square
instead of WrapType.None
:
shape.WrapType = WrapType.Square;
Thanks @alexey.noskov
Now it is working. Now we have to place one table in word document on the bottom of the page but it should not overlap the footer of document.
We are not able to find the same properties in table. if we use VerticalAlignment.Bottom table starts overlapping with footer. below is the code:
var table = builder.StartTable();
builder.InsertCell();
builder.CellFormat.ClearFormatting();
table.RelativeVerticalAlignment = VerticalAlignment.Bottom;
table.RelativeHorizontalAlignment = HorizontalAlignment.Center;
builder.EndRow();
builder.EndTable();
Could you please let us know?
@Sudrashya I am afraid there is no way to achieve this with table. I can suggest you to put the table into the floating shape and use the approach you use for shape.
@alexey.noskov
At some times we have to places some legal information just above the footer. and that information can not go anywhere. It can be free-text or wordings etc.
So How we can achieve that?
@Sudrashya You can put the required content into a shape and use the same approach as for an image.
@alexey.noskov
Thanks for response. As i said while converting document to pdf shape does not hold its placement. if there is space available in the document it floats upward.
@Sudrashya Could you please attach your problematic DOC or DOCX and output PDF document here for our reference? We will check the issue and provide you more information.
Hello @alexey.noskov
I have attached the html, image and output word document. you can see image is not going in bottom of the next page if there is text. Try to convert in word
I think it could be done if shape can take space for complete row
We are using below code
Test.zip (310 Bytes)
builder.MoveToDocumentEnd();
Aspose.Words.Drawing.Shape shape = builder.InsertImage(path + "output\\Dummy.jpg");
shape.WrapType = WrapType.Square;
shape.RelativeHorizontalPosition = RelativeHorizontalPosition.Page;
shape.HorizontalAlignment = HorizontalAlignment.Center;
shape.RelativeVerticalPosition = RelativeVerticalPosition.Margin;
shape.VerticalAlignment = VerticalAlignment.Bottom;
@Sudrashya As I can see the following code puts the image at the bottom of the page in both MS Word and PDF output:
Document doc = new Document(@"C:\Temp\in.html");
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveToDocumentEnd();
Aspose.Words.Drawing.Shape shape = builder.InsertImage(@"C:\Temp\test.png");
shape.WrapType = WrapType.Square;
shape.RelativeHorizontalPosition = RelativeHorizontalPosition.Page;
shape.HorizontalAlignment = HorizontalAlignment.Center;
shape.RelativeVerticalPosition = RelativeVerticalPosition.Margin;
shape.VerticalAlignment = VerticalAlignment.Bottom;
doc.Save(@"C:\Temp\out.docx");
doc.Save(@"C:\Temp\out.pdf");
out.docx (12.1 KB)
out.pdf (37.9 KB)
If you need to place the image on a separate page, you can insert a page break before inserting the image:
builder.MoveToDocumentEnd();
builder.InsertBreak(BreakType.PageBreak);
Aspose.Words.Drawing.Shape shape = builder.InsertImage(@"C:\Temp\test.png");