I’ve got a document that’s being created via a mail merge. I’m taking this document and drawing shapes on the odd-numbered pages. My current approach involves looping through the child nodes that are either Inline or Paragraph-related nodes. I use LayoutCollector to determine if that node is on an odd or even-numbered page. On odd pages, I’m using DocumentBuilder and calling “MoveTo”, passing in the appropriate node.
This works fine on most pages and the shapes are coming up fine. However, I’m finding that if a given page only has nodes that are contained within a table (in other words, if there is a Table node somewhere in the chain up through the ParentNode references), if I use DocumentBuilder and “MoveTo” that node within the table, the shape nodes I’m adding do not appear on that page.
Is this a known issue? Is there another way I can draw a shape on this page?
Thanks in advance.
Thanks for your inquiry. It would be great if you please share following details for testing purposes. I will investigate the issue on my side and provide you more information.
- Please create a simple application (for example a Console Application Project) that helps us reproduce the same problem on our end and attach it here for testing.
- Please supply us with the input document that is causing the issue
- Please supply us with the output document showing the undesired behavior
- Please supply us with the expected document showing the desired behavior (You can create this document using Microsoft Word).
Most likely what is happening is the image has “Layout in table cell” option set which causes the image to move relative to the table location. Placed outside the table the image would be located in the right position however inside the table you will most likely find the image somewhere off the page because of this.
I’m afraid there is no API to change this option at the moment. Could you perhaps add a check to only use paragraphs in the document body?
That’s exactly what’s happening. It looks like the shape, even though I’ve specified it to be positioned relative to the page, isn’t obeying that setting. It’s setting it relative to the table and not to the page. I’ve attached a sample I’ve built using your NestedMailMerge example where I tweaked the merge document, sample data and added some code to add a shape on each page.
Unfortunately, due to the nature of the merge, I cannot guarantee there will be a paragraph on every page outside of a table – especially if the table data runs long.
This sounds like it’s a bug, then. I am setting a shape to be positioned relative to the page, but DocumentBuilder doesn’t place it relative to a page if the node I move to is within a table.
Can you guys confirm this?
Thanks for sharing the detail.
Unfortunately, Aspose.Words does not support the setting of image layout option “Layout in table cell” at the moment. If this option is unchecked for all shapes, you will get the required output. However, we had already logged this feature request as WORDSNET-4898 in our issue tracking system. You will be notified via this forum thread once this feature is available. We apologize for your inconvenience.
In your case, I suggest you please set the shape RelativeHorizontalPosition/RelativeVerticalPosition as Margin. I have modified AddShapesOnEachPage method and attached it with this post. I have also attached the output document with this post for your kind reference.
If you still face problem, please manually create your expected Word document using Microsoft Word and attach it here for our reference. We will investigate, how you want your final Word output be generated like. We will then provide you more information on this along with code.
Unfortunately, I won’t be able to use this temporary solution. I need to have control over vertical and horizontal placement. In the example document you had sent, there is a page where the vertical placement is inconsistent.
My work around for the time being is to use Aspose PDF and add the shapes on there per page.
Thanks for your feedback. It is nice to hear from you that you have found the workaround of your issue. Regarding WORDSNET-4898 (Allow setting “Layout in Table Cell” option of shapes), we will update you via this forum thread once this feature is available.
We apologize for your inconvenience.
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.