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

Free Support Forum - aspose.com

PDFs created in Word 2010 - concatenation problem

If a use Word 2010 to produce 2 PDF file using Save_As…

I then merge the files using
pdfDocument1.Pages.Add(pdfDocument2.Pages);
pdfDocument1.Save(args.Destination.FullName);

The resulting file can be opened by adobe reader without error.

If I then open the pdf in aspose.pdf and save to a file stream
originalDoc.Save(outputStream);


I get the error

[ArgumentNullException: Value cannot be null.
Parameter name: output]

If there is a single PDF from Word2010 and it is stitched with other PDFs from other sources, there isn’t an error.

If the stitched file is opened in adobe reader and saved again then this can be streamed. This means that the original concatenated file is corrupt some how.

I have attached 2 pdfs created by word2010. I have also included the resultant stitched file.

I have some more information for you. If word saves as PDFs using the defaults it fails, but if the option ‘Minimum size (publishing online)’ is selected rather than the default ‘Standard(publishing online and printing)’ it then works.

This helps a little in that when we convert DOCs to PDFs we can make the correct selection, but this will not help if the our file suppliers have done the conversion and used the defaults.

Hi Peter,


Thanks for your inquiry. I have tested your scenario with Aspsoe.Pdf for .NET 10.1.0 and unable to replicate the issue. Please download and try latest version of Aspose.Pdf for .NET, it will resolve the issue. If issue persist then please share your complete code here, so we will look into it and guide you accordingly.

Best Regards,

I have found the problem and a bodge that fixes it. The problem is in optimizing the stitched file. I’ve also found that it is a late binding issue, if I add a breakpoint on

resDocument.Optimize();
and then inspect the resDocument object, it will not throw the exception on continuing.

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Aspose.Pdf;

namespace WordGeneratedPDFdemo
{
class Program
{
static void Main(string[] args)
{

        <span style="color:#4ec9b0;">Document</span> <span style="color:gainsboro;">pdfDocument1</span> <span style="color:#b4b4b4;">=</span> <span style="color:#569cd6;">new</span> <span style="color:#4ec9b0;">Document</span>(<span style="color:#d69d85;">"document 1.pdf"</span>);
        <span style="color:#57a64a;">// Open the second document</span>
        <span style="color:#4ec9b0;">Document</span> <span style="color:gainsboro;">pdfDocument2</span> <span style="color:#b4b4b4;">=</span> <span style="color:#569cd6;">new</span> <span style="color:#4ec9b0;">Document</span>(<span style="color:#d69d85;">"document 2.pdf"</span>);

        <span style="color:#57a64a;">// Add pages of second document to the first</span>
        <span style="color:gainsboro;">pdfDocument1</span><span style="color:#b4b4b4;">.</span><span style="color:gainsboro;">Pages</span><span style="color:#b4b4b4;">.</span><span style="color:gainsboro;">Add</span>(<span style="color:gainsboro;">pdfDocument2</span><span style="color:#b4b4b4;">.</span><span style="color:gainsboro;">Pages</span>);

        <span style="color:#57a64a;">//clean up any repvious test files</span>
        <span style="color:#569cd6;">if</span> (<span style="color:#4ec9b0;">File</span><span style="color:#b4b4b4;">.</span><span style="color:gainsboro;">Exists</span>(<span style="color:#d69d85;">"res.pdf"</span>)) <span style="color:#4ec9b0;">File</span><span style="color:#b4b4b4;">.</span><span style="color:gainsboro;">Delete</span>(<span style="color:#d69d85;">"res.pdf"</span>);
        <span style="color:#569cd6;">if</span> (<span style="color:#4ec9b0;">File</span><span style="color:#b4b4b4;">.</span><span style="color:gainsboro;">Exists</span>(<span style="color:#d69d85;">"out.pdf"</span>)) <span style="color:#4ec9b0;">File</span><span style="color:#b4b4b4;">.</span><span style="color:gainsboro;">Delete</span>(<span style="color:#d69d85;">"out.pdf"</span>);

        <span style="color:#57a64a;">//Uncomment the next line fixes the problem</span>
        <span style="color:#57a64a;">// pdfDocument1.Optimize();</span>
        <span style="color:gainsboro;">pdfDocument1</span><span style="color:#b4b4b4;">.</span><span style="color:gainsboro;">Save</span>(<span style="color:#d69d85;">"res.pdf"</span>);

        <span style="color:#4ec9b0;">Document</span> <span style="color:gainsboro;">resDocument</span> <span style="color:#b4b4b4;">=</span> <span style="color:#569cd6;">new</span> <span style="color:#4ec9b0;">Document</span>(<span style="color:#d69d85;">"res.pdf"</span>);
        <span style="color:gainsboro;">resDocument</span><span style="color:#b4b4b4;">.</span><span style="color:gainsboro;">Optimize</span>();
        <span style="color:gainsboro;">resDocument</span><span style="color:#b4b4b4;">.</span><span style="color:gainsboro;">Save</span>(<span style="color:#d69d85;">"out.pdf"</span>);

    }
}

}


Hi Peter,


Thanks for sharing the additional information. It is good to know that you have managed to find a workaround. However we have reproduced the reported issue at our end and logged as PDFNEWNET-38342 in our issue tracking system for further investigation and resolution. We will notify you as soon as we resolve it.

We are sorry for the inconvenience caused.

Best Regards,

The issues you have found earlier (filed as PDFNET-38342) have been fixed in Aspose.PDF for .NET 21.11.