Last page data overflowing to next page while appending docx and converting to pdf

651045772122222071314941.pdf (8.2 MB)
FIA-1140 (B) Tagged.docx (88.8 KB)
FIA-1140 (E)_Tagged.docx (87.2 KB)
HRA-102c (B)_Tagged.docx (230.9 KB)
HRA-102c (E)_Tagged.docx (227.4 KB)

@bhanu410 The problem occurs because your document were created using different version of MS Word and as a result have different set of compatibility options. When you concatenate the documents compatibility options of the main document are applied and the content is reflowed appropriately.
You can workaround this and convert each document to PDF and then concatenate them using Aspose.PDF:

string[] docs = new string[] {
    @"C:\Temp\FIA-1140 (B) Tagged.docx",
    @"C:\Temp\HRA-102c (B)_Tagged.docx",
    @"C:\Temp\FIA-1140 (E)_Tagged.docx",
    @"C:\Temp\HRA-102c (E)_Tagged.docx"
};

Document target = null;
int i = 0;
foreach (string path in docs)
{
    Document doc = new Document(path);
    doc.LayoutOptions.TextShaperFactory = Aspose.Words.Shaping.HarfBuzz.HarfBuzzTextShaperFactory.Instance;
    doc.Save(string.Format(@"C:\Temp\out_{0}.pdf", i++));
}

I tried above workaround but getting the error below
At most 4 elements (for any collection) can be viewed in evaluation mode

@bhanu410 It looks like you are using Aspose.PDF in evaluation mode. You should apply the license for both Aspose.Words and Aspose.PDF products. Please see our documentation for more information:
https://docs.aspose.com/words/net/licensing/#using-multiple-aspose-products

Hi @alexey.noskov, We only have license for Aspose.Words, is there any alternate solution apart from this workaround?

Thanks in advance.

@bhanu410 Unfortunately, there is no other good workaround of this issue. We are working on providing a functionality to merge PDF document using Aspose.Words. This functionality will be available in on of future versions of Aspose.Words for .NET. We will keep you informed and let you know once it is available.

@alexey.noskov thanks for the help

1 Like

The issues you have found earlier (filed as WORDSNET-24246) have been fixed in this Aspose.Words for .NET 23.2 update also available on NuGet.

@bhanu410 With the latest 22.2 version of Aspose.Words you can use the following code to merge PDF documents without parsing them into Aspose.Words DOM:

Aspose.Words.Pdf2Word.FixedFormats.PdfFixedRenderer pdfFixedRenderer = new Aspose.Words.Pdf2Word.FixedFormats.PdfFixedRenderer();

using (FileStream pdf1 = File.OpenRead(@"C:\Temp\in1.pdf"))
using (FileStream pdf2 = File.OpenRead(@"C:\Temp\in2.pdf"))
{
    using (Stream resultStream = pdfFixedRenderer.MergePdf(pdf1, pdf2))
    using (FileStream resultFile = File.Create(@"C:\Temp\out.pdf"))
        resultStream.CopyTo(resultFile);
}

@alexey.noskov thanks for the update.

How to handle list of paths? For example

 string[] docs = new string[] {
    @"C:\Temp\FIA-1140 (B) Tagged.docx",
    @"C:\Temp\HRA-102c (B)_Tagged.docx",
    @"C:\Temp\FIA-1140 (E)_Tagged.docx",
    @"C:\Temp\HRA-102c (E)_Tagged.docx"
};

@bhanu410 You can use code like this to merge multiple PDF documents:

string[] docs = new string[] {
    @"C:\Temp\in1.pdf",
    @"C:\Temp\in2.pdf",
    @"C:\Temp\in3.pdf",
    @"C:\Temp\in4.pdf",
};

Aspose.Words.Pdf2Word.FixedFormats.PdfFixedRenderer pdfFixedRenderer = new Aspose.Words.Pdf2Word.FixedFormats.PdfFixedRenderer();

Stream result = null;
foreach (string path in docs)
{
    FileStream pdf = File.OpenRead(path);
    if (result == null)
    {
        result = pdf;
    }
    else
    {
        Stream resultStream = null;
        using (result)
        using (pdf)
            resultStream = pdfFixedRenderer.MergePdf(result, pdf);

        result = resultStream;
    }
}

using (result)
using (FileStream resultFile = File.Create(@"C:\Temp\out.pdf"))
    result.CopyTo(resultFile);

Thank you @alexey.noskov

1 Like

Hi @alexey.noskov I tried above solution but PDF merge is not working properly with ASPOSE.WORDS which worked fine with ASPOSE.PDF

Please refer to the attached input and out pdf’s651045772021423053755561.pdf (529.8 KB)
651045772021423053755561_1.pdf (202.8 KB)
651045772021423053755561_E.pdf (103.5 KB)
651045772021423053755561_E_1.pdf (146.8 KB)
out.pdf (249.6 KB)

@bhanu410
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): WORDSNET-24991

You can obtain Paid Support services if you need support on a priority basis, along with the direct access to our Paid Support management team.

Hi @alexey.noskov when can we expect this fix as we are planning to purchase Aspose.Words license instead of purchasing both words and pdf to meet our requiement

@bhanu410 Unfortunately, the issue is not yet scheduled for development. So at the moment no estimates are available.
I am afraid currently you need both Aspose.Words to convert MS Word documents to PDF and Aspose.PDF to concatenate PDF documents.

@alexey.noskov Yes we are using both as per the workaround you suggested, we don’t have no other use of Aspose.PDF apart from this

1 Like

Starting from 23.6 version we have introduced LowCode concept in Aspose.Words. You can now use Merger class and the following code to merge PDF or other documents with only one line of code:

Aspose.Words.LowCode.Merger.Merge(@"C:\Temp\out.pdf", new string[] { @"C:\Temp\in1.pdf",@"C:\Temp\in2.pdf"});