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,
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,
The issues you have found earlier (filed as PDFNET-38342) have been fixed in Aspose.PDF for .NET 21.11.