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

Free Support Forum - aspose.com

Anchored images and textboxes shift during mail merging

Hi,


I am having an issue where image and textboxes inserted in a document start to shift up during mail merging. With a single page it looks fine, but as soon as I add mail merging (even when there a no fields on the page), the image and textboxes shift and drastically changing the layout. However when doing a mail merge via MS Word all the elements are positioned accurately for each subsequent page.

I am able to fix the issue to some extent when enabling “Fix Position on Page” for the page elements.

Our product is centered around allowing users to upload word docs which we then mail merge and prepare for direct mail printing. Having the layout change is kind of a show stopper for us as the client won’t be previewing all pages of the mail merged document.

package aspose.bug;
import com.aspose.words.Document;
import com.aspose.words.IMailMergeDataSource;
import java.io.FileInputStream;
public class MailMergeBug {
public static void main(String… args) {
try {
new com.aspose.words.License().setLicense(new FileInputStream(“C:\mailmerge\Aspose.Words.lic”));
final Document doc = new Document(“C:\mailmerge\mail-out-A4.docx”);
doc.getMailMerge().execute(new IMailMergeDataSource() {
int i=0;
public String getTableName() throws Exception {
return “mock”;
}
public boolean moveNext() throws Exception {
return i++ < 10;
}
public boolean getValue(String s, Object[] objects) throws Exception {
return false;
}
public IMailMergeDataSource getChildDataSource(String s) throws Exception {
return null;
}
});
doc.save(“C:\mailmerge\preview.docx”);
} catch (Exception e) {
e.printStackTrace();
}
}
}

Thank you,

Daniel

I just found a solution to my own problem.


By enabling section start= new page as per https://docs.aspose.com/display/wordsjava/About+Mail+Merge#AboutMailMerge-HowtoControlNewPagesduringMailMerge does fix it effectively.

But it does wonder me though why mail merging via MSWord works without that setting.

Also, in order to ensure that mail merging works 100% all the time, can section start= new page be automated or at least be checked via Aspose?

I have found a way to fix it by enforcing the new page section start:

doc.getLastSection().getPageSetup().setSectionStart(SectionStart.NEW_PAGE);

I will perform testing on a wide variety of different templates to ensure that this doesn't have any unexpected side effects.

Hi Daniel,


Thanks for your inquiry. It is nice to hear from you that you have found the solution of your query. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.