Last line in the page is pushing down to next page

Hi,

I am trying to convert the word (doc) file to pdf, after conversion I see the the last line is pushed to next line. This is happening specifically when we append the document to the existing document.

I tried to turn off/on compatibility mode but still its behaving same. Can you please let me know how to resolve this issue.

I am using the 16.5.0 version of aspose dll for .net

Thanks
Puri

Hi Puri,

Thanks for your inquiry. We will appreciate it if you please share your sample input and output documents along with sample code. We will test the scenario at our end and will guide you accordingly.

Best Regards,

Hi,

Please find the code

var concatDoc = new Aspose.Words.Document();
concatDoc.RemoveAllChildren();
concatDoc.Unprotect();
Aspose.Words.License license = new Aspose.Words.License();
license.SetLicense("Aspose.Words.lic");
List docs = new List();
docs.Add(new Document(@"H:\Desktop\RandDPDF\RandDPDF\Sample.doc"));
docs.Add(new Document(@"H:\Desktop\RandDPDF\RandDPDF\16.docx"));
docs.Add(new Document(@"H:\Desktop\RandDPDF\RandDPDF\17.docx"));
foreach (var document in docs)
{
    document.Unprotect();
    document.FirstSection.PageSetup.SectionStart = SectionStart.NewPage;
    document.FirstSection.HeadersFooters.LinkToPrevious(false);
    concatDoc.AppendDocument(document, ImportFormatMode.KeepSourceFormatting);
    concatDoc.UpdatePageLayout();
}

concatDoc.Save(@"H:\Desktop\RandDPDF\Sample.pdf", new PdfSaveOptions { SaveFormat = SaveFormat.Pdf });
Console.WriteLine("done");
Console.ReadKey();

The bottom line is moved to next page occupying entire page without any further content when tried to append. Attaching all input docs and output pdf in zip

Thanks
Puri

Hi Puri,

Thanks for sharing your sample documents and code. Please note 16.docx and 17.docx documents contain a lot of empty paragraphs. You may remove the empty paragraphs before appending the document. Hopefully it will help you to accomplish the task.

document.Unprotect();
RemoveEmptyPara(document);
document.FirstSection.PageSetup.SectionStart = SectionStart.NewPage;
document.FirstSection.HeadersFooters.LinkToPrevious(false);
concatDoc.AppendDocument(document, ImportFormatMode.KeepSourceFormatting);
concatDoc.UpdatePageLayout();
/////////
public static void RemoveEmptyPara(Document document)
{
    Document doc = document;
    foreach (Paragraph paragraph in doc.GetChildNodes(NodeType.Paragraph, true))
    {
        if (string.IsNullOrEmpty(paragraph.ToString(SaveFormat.Text).Trim()))
        {
            if (paragraph.HasChildNodes)
                continue;
            paragraph.Remove();
        }
    }
}

Best Regards,

Hi,

I’ve tried the solution you provided but it is removing all the empty paragraph throughout the pages.

I don’t want to loose the formatting and don’t even want to remove the blank paragraphs.

If you save these documents as pdf, there is no loss of document formatting and also the last line is not moving to next page.

can you please check it once ?

Regards,
Puri

Hi Puri,

Thanks for your feedback. We have logged a ticket WORDSNET-15399 in our issue tracking system for further investigation and rectification. We will notify you as soon as it is resolved.

We are sorry for the inconvenience.

Best Regards,

This is required urgently. Can you please give us reply as soon as possible.

Please let me know if we can setup the call to discuss?

Regards,
Adarsh

Hi Adarsh,

Thanks for your inquiry. Your issue is still not resolved as we have recently noticed it. It is pending for analysis in the queue. We will notify you as soon as some update is available.

Furthermore, please note we do not provide technical support over phone. Phone support is only available for Sales related queries.

Thanks for your patience and cooperation.

Best Regards,

@puri

Thanks for your patience. We have investigated the issue and would like to update you that we must add headers/footers to unlink sections, but adding headers/footers also adds extra space, which leads to adding of new pages, which is undesirable. So, a workaround to resolve this issue is to add zero-height headers/footers, this will unlink sections and preserve the initial height of the documents.

private static void UnLinkToPreviousSafe(Section section)
{
    if (section.HeadersFooters.Count == 0)
    {
        SectPr sectPr = section.SectPr;
        sectPr.FooterDistance = 0;
        sectPr.HeaderDistance = 0;
    }
    section.HeadersFooters.LinkToPrevious(false);
}

To get desired output, please, modify your code as followig, it will help you to get desired results.

you should use this function
UnLinkToPreviousSafe(document.FirstSection);
Instead of
document.FirstSection.HeadersFooters.LinkToPrevious(false);

Please feel free to contact us for any further assistance.

Best Regards,

Hi Tilal,

I’ve tried this code but it’s giving me compilation error in below line:

SectPr sectPr = section.SectPr;

Where SectPr is defined ? Which version does it support ?

Can you please reply quickly. We are paid customer and waiting for the issue to get resolve from long time.

Please let me know in case you need any more details.

It would be good to have a technical conversation or on call resolution if possible.

Regards,
Adarsh

@puri

I am sorry for the confusion. Actually, it was an internal discussion for a possible workaround that I mistakenly shared here. Please disregard this at the moment.

Meanwhile, We will appreciate it if you please append your documents using MS Word and create an expected document for reference. It will help us to address your issue exactly.

Again, I apologize for the confusion.

Best Regards,

Hi Team,

as I mentioned before in this thread:

If you open any of these document in word and save these documents as pdf, there is no loss of formatting and also the last line is not moving to next page.

can you please check it once ? Let me know in case you need more details.

Regards,

@puri

Thanks for your feedback. When we render individual document to PDF using Aspose.Words it renders as expected. We are getting issue during document appending process. It seems when we append 16.docx and 17.docx documents, with no headers/footers, Aspose.Words adds empty headers/footers that makes them 2-page documents. We have noticed the same behavior with MS Word.

So to double check, we have requested you to create, ZIP and share expected document using MS Word.

Best Regards,

Hi Tilal,

I’ve tried appending the document 16 and 17 with word 2016 and we faced the same issues. In terms of expected document we don’t want any extra spaces or something.
I understood that the word is appending header and footer but this is what we want to avoid.

I’ve tried an alternative where I saved individual documents in pdf and Merge those pdf using one of the open source and it looks fine and i am not finding any issues.

Can we get a solution around the same lines ?

Regards,
Adarsh

@puri

Thanks for your feedback. We have shared your findings with the product team.

You can use Aspose.Words and Aspose.Pdf to use this workaround. Initially, render word documents to PDF using Aspose.Words and later use Aspose.Pdf to concatenate the resultant PDF documents. Please check following documentation link for details.