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

Free Support Forum - aspose.com

How to set absolute positioning of image using C#

I can’t seem to lock down this image to one corner of the pages. Other nodes on the page seem to have a heavy influence on size and location of the image. Is there a was to give a floating image an absolute position on the document? Attached is the console app and test document that is causing the issue.

https://drive.google.com/file/d/1MzHFwtJsL2wr1fTvBIqF1oK69W_Xi271/view?usp=sharing

Thanks,
John

@johnmann04

We are working over your query and will get back to you soon.

@johnmann04

We have investigated this issue and noticed that position of bookmark is incorrect after moving cursor to paragraph and inserting it. So, the barcode position is also incorrect. We have logged this problem in our issue tracking system as WORDSNET-20025. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

@johnmann04

In your case, we suggest you please move the cursor to the end of paragraph and insert the bookmark as shown below.

builder.MoveToParagraph(paragraphs.IndexOf(paragraph), -1);
builder.StartBookmark("BM_Page" + pageIndex);
builder.EndBookmark("BM_Page" + pageIndex);

Moreover, we have modified the code to set the shape (barcode) position. Please check the ResizeAndPositionBarcodeTopRight method in the attached project. You can set the shape’s position according to your requirement.
BarcodeTestConsoleApp.zip (2.5 MB)

Thanks for the update, I have downloaded the modified code and tested it locally, using my licence, and I’m seeing one page where there are two bookmarks on the same page which causes two barcodes to show up on that page and no barcode on the next page. Did I miss something?
image.png (240.6 KB)

@johnmann04

Please use the latest version of Aspose.Words for .NET 20.2. We have not found this issue at our end. Moreover, please check the method ResizeAndPositionBarcodeTopRight in the Visual Studio project shared in my previous post. You need to modify this method to set the shape’s position according to your requirement.

@johnmann04 Unfortunately, this approach will not give the desired result. The text paginating algorithm in MS Word is not always obvious and predictable; adding text to a paragraph may cause the paragraph to get moved to the previous page. This is exactly what happens in your document:

LayoutCollector correctly identifies that the problematic paragraph is on page 14, however, when adding text to it, the paragraph is moved by MS Word to page 13.
You can try to get workaround this problem in various ways. For example, add text to a separate line initiated by BreakType.LineBreak, so that the logic of the rest of the code is not changed.

CreatePageBarcode.AddBookmarksToEachPage()
{
  ...
  foreach (Paragraph paragraph in paragraphs)
  {
    if (collector.GetEndPageIndex(paragraph) != pageIndex) continue;
    builder.InsertBreak(BreakType.LineBreak);
    builder.MoveToParagraph(paragraphs.IndexOf(paragraph), 0);
    ...
  }

  ...
}