Hi we’ve implemented a system using aspose.
A user can upload a document into the system which recreates the document’s headers and footers, Other users can then view the document in PDF format. There are thousands of documents in the system, most of these seem to be fine.
For a specific document, after the header and footer is regenerated (using Aspose), when we try and convert that document to PDF (with Aspose) we get a null reference exception.
Call stack is as follows…
System.NullReferenceException: Object reference not set to an instance of an object.
Result StackTrace:
at .(Single , Border )
at .(RectangleF , Border , Border , Border , Border )
at .(RectangleF , Border , Border , Border , Border )
at .( )
at .( , ? , Boolean )
at .( , ? , Boolean )
at .( , Boolean )
at ? .( , Boolean& )
at ? .( , Boolean& )
at ? .(? )
at ? .()
at ? .? ? ()
at ? .? ? ()
at ? .? ? ()
at ? .()
at ? .(? , Int32 )
at ? .(? )
at ? .(? )
at ? .(? , Int32 )
at .( , Int32 , Boolean )
at ? .()
at ? .(? , Int32 , Boolean , Boolean )
at . ()
at .( , Int32 )
at .( )
at .()
at .( )
at .(? )
at .(Boolean )
at .(Boolean )
at . ()
at .(Document , )
at Aspose.Words.Document.UpdatePageLayout()
at . ? ()
at ? .( )
at .( , )
at .(Node , )
at .(Node )
at Aspose.Words.Document.()
at Aspose.Words.Document.(Stream , String , SaveOptions )
at Aspose.Words.Document.Save(Stream stream, SaveOptions saveOptions)
at Aspose.Words.Document.Save(Stream stream, SaveFormat saveFormat)
at Tonic.Documents.DocumentAsposeOperations.WriteDocumentFile(Stream outputStream, String sourceFilePath, String destFileName, Boolean controlled) in s:\Tonic.Documents\DocumentAsposeOperations.cs:line 124
at Tonic.Sonic.Data.Test.Documents.DocumentFileOperationTests.TestConvertPDF() in d:\Projects\Documents\DocumentFileOperationTests.cs:line 82
The code to convert the document to PDF is …
public bool WriteDocumentFile(Stream outputStream, string sourceFilePath, string destFileName, bool controlled)
{
// the destination has a PDF extension
Document wordDocument = new Document(sourceFilePath);
if (controlled)
{
// Controlled is false
}
var format = Aspose.Words.Saving.SaveOptions.CreateSaveOptions(destFileName).SaveFormat;
if (format == SaveFormat.Unknown)
format = GetSaveFormat(sourceFilePath);wordDocument.Save(outputStream, format); // NULL reference Exception here
return true;
}I’ve attached the file causing the issue, this is the file after it has had it’s headers
and footers recreated using Aspose.If you open this file in Word, save it, then attempt to convert it to PDF again,
you do not get the error.