Content Moved To Column2 Without Completing Column1

Hello, I am trying write content to word template, I wanted to have two columns for each page. The content should be written to column1 for the first page then should be written to column2 on the first page. Once first page is complete then should move to second page. It works great for all pages except for the last page where the content being written to column2 without completing column1

@ryazali Could you please attach the problematic document here for our reference? We will check the issue and provide you more information. Unfortunately, it is impossible to say what causes the problem on your side without your problematic document.

24R15664.A.Pinning Chart.071724.pdf (88.6 KB)

Look at that last page, not sure what Aspose property needs to be reset, the content on the last page should fit in column1 instead half in column1 and half in column2. You can propose different solution too but my pinning reports should write to column1 first the column2 then only go to next page and also one pinning content should not spread across column1 and column2

@ryazali Could you please attach the source MS Word document here for testing and provide code that will allow us to reproduce the problem? Unfortunately, the output PDF document does not give enough information for problem analysis.

PinningChartTemplate.docx (149.9 KB)

Here it is

@ryazali Thank you for additional information. But could you please also provide sample data and code you use to generate the problematic document? If possible, please create a simple console application that will demonstrate the problem.

Sure, get me a day, I would build the console app with data and share it

1 Like

Hey there, My zip file is around 24 MB but I am not able to upload here

@ryazali You can upload your files to google drive and then share a link here.

@alexey.noskov Please try access this link and download AsposePlayGround.zip - Google Drive

@ryazali The problem is causes by an empty section at the end of the document. If remove the empty section the output looks correct. You can try using the following code to remove empty sections from the document end:

while(string.IsNullOrEmpty(wordDocument.LastSection.ToString(SaveFormat.Text).Trim()))
    wordDocument.LastSection.Remove();

out.docx (111.8 KB)
out.pdf (78.8 KB)

1 Like

@alexey.noskov Thank you and I am so excited to apply this code, please guide me where exactly I need to apply the code you provided

@ryazali Please try adding this code just before saving the document.

@alexey.noskov I had no luck adding this code, may be something wrong I did. Please verify this below code

@ryazali I have used the same code on my side:

while(string.IsNullOrEmpty(wordDocument.LastSection.ToString(SaveFormat.Text).Trim()))
    wordDocument.LastSection.Remove();

wordDocument.Save(@"C:\Temp\out.docx");
wordDocument.Save(@"C:\Temp\out.pdf");

@alexey.noskov I debugged the code, in my case while loop is evaluating to false and so below statement never executed.
wordDocument.LastSection.Remove();

@ryazali The problem occurs because you are using Aspose.Words in evaluation mode. In this case Aspose.Words adds an evaluation message, and the code does not detect the last section as empty.

@alexey.noskov Wow, it worked. Thank you very much really really appreciate it.

1 Like

@alexey.noskov I worked for all reports except the one I attached here, Code wise not much difference and I added the code you provided just before the Save. Can you please guess why this particular report has the issue
Sample.pdf (71.9 KB)

@ryazali Unfortunately, it is impossible to say what is wrong by the output PDF document. Could you please attach the template and output DOCX documents? We will check them and provide you more information.