Free Support Forum - aspose.com

EndOfStreamException when reading XPS Files

Hello,

when trying to convert XPS files to PDF format, a System.IO.EndOfStreamException is raised in mscorlib.dll. The exception is showing in the Output Window.

Aspose.Pdf seems to handle the exception but is this the correct behaviour?

See the attached file for an XPS file that generates the exception, and the code at the end of the post for a program that can reproduce the exception.

thanks,

Henrik

namespace AsposePdfConvert
{
    using System.Diagnostics;
    using System.IO;
<span style="color: blue;">using</span> Aspose.Pdf;

<span style="color: blue;">class</span> <span style="color: rgb(43, 145, 175);">Program</span>
{
    <span style="color: blue;">static</span> <span style="color: blue;">void</span> Main(<span style="color: blue;">string</span>[] args)
    {
        <span style="color: blue;">if</span> (args.Length < 1)
        {
            <span style="color: rgb(43, 145, 175);">Trace</span>.WriteLine(<span style="color: rgb(163, 21, 21);">"Invalid number of arguments: Expecting AsposePdfConvert.exe <source>"</span>);
            <span style="color: blue;">return</span>;
        }

        <span style="color: blue;">string</span> l_sourceFile = args[0];

        <span style="color: blue;">if</span> (!<span style="color: rgb(43, 145, 175);">File</span>.Exists(l_sourceFile))
        {
            <span style="color: rgb(43, 145, 175);">Trace</span>.WriteLine(<span style="color: rgb(163, 21, 21);">"Specified source file does not exist: "</span> + l_sourceFile);
            <span style="color: blue;">return</span>;
        }

        Aspose.Pdf.<span style="color: rgb(43, 145, 175);">License</span> l_license = <span style="color: blue;">new</span> Aspose.Pdf.<span style="color: rgb(43, 145, 175);">License</span>();

        l_license.SetLicense(<span style="color: rgb(163, 21, 21);">"Aspose.Total.lic"</span>);

        <span style="color: blue;">string</span> l_targetFile = l_sourceFile + <span style="color: rgb(163, 21, 21);">".pdf"</span>;

        Aspose.Pdf.<span style="color: rgb(43, 145, 175);">Document</span> l_pdfDocument = <span style="color: blue;">new</span> Aspose.Pdf.<span style="color: rgb(43, 145, 175);">Document</span>(l_sourceFile, <span style="color: blue;">new</span> <span style="color: rgb(43, 145, 175);">XpsLoadOptions</span>());

        l_pdfDocument.Save(l_targetFile);
            
    }
}

}

namespace AsposePdfConvert
{
    using System.Diagnostics;
    using System.IO;
 
    using Aspose.Pdf;
 
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Trace.WriteLine("Invalid number of arguments: Expecting AsposePdfConvert.exe ");
                return;
            }
 
        <span style="color: blue;">string</span> l_sourceFile = args[0];

        <span style="color: blue;">if</span> (!<span style="color: rgb(43, 145, 175);">File</span>.Exists(l_sourceFile))
        {
            <span style="color: rgb(43, 145, 175);">Trace</span>.WriteLine(<span style="color: rgb(163, 21, 21);">"Specified source file does not exist: "</span> + l_sourceFile);
            <span style="color: blue;">return</span>;
        }


Aspose.Pdf.License l_license = new Aspose.Pdf.License();
        l_license.SetLicense(<span style="color: rgb(163, 21, 21);">"Aspose.Total.lic"</span>);


string l_targetFile = l_sourceFile + “.pdf”;
        Aspose.Pdf.<span style="color: rgb(43, 145, 175);">Document</span> l_pdfDocument = <span style="color: blue;">new</span> Aspose.Pdf.<span style="color: rgb(43, 145, 175);">Document</span>(l_sourceFile, <span style="color: blue;">new</span> <span style="color: rgb(43, 145, 175);">XpsLoadOptions</span>());

        l_pdfDocument.Save(l_targetFile);
            
    }
}

}

Hi Henrik,


Thanks for contacting support.

I have tested the scenario where I have tried using Aspose.Pdf for .NET 7.7.0 to convert XPS file to PDF format and I am unable to notice any issue. The PDF file is properly being generated. For your reference, I have also attached the resultant PDF generated over my end. We are sorry for this inconvenience.

Hello,

and thanks for your response.

The Pdf file is generated correctly but an exception is raised when the Xps file is loaded in the constructor of the Aspose.Pdf.Document. This exception is handled but when debugging in Visual Studio the program execution is interrupted.

See attached screenshot of Output Window.

thanks,

Henrik

Hi Henrik,


I have again tested the scenario where I have used Visual Studio 2010 application with target platform as .NET Framework 4.0 Client Profile running over Windows 7 (X64) and I am still unable to notice any exception message in console output. As shared earlier, I have used the latest release version of Aspose.Pdf for .NET 7.7.0.

Can you please share which version of Aspose.Pdf for .NET you are using also please share some details regarding your working environment. Furthermore, if possible, can you please share some sample project which can help us in replicating this issue at our end. We are really sorry for this inconvenience.