Create Document object from Stream in Aspose.PDF for .NET - method or operation is not implemented

Hi,
I am trying to create a pdf document from stream using the following constructor:
Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(stream);
but I got an error saying that the method or operation is not implemented.
Please help.
thanks

Hi Aleazhao,

Thanks for contacting support.

I have tested the scenario using Aspose.Pdf for .NET 10.2.0 using the following simple code lines in VisualStudio 2012 application with target platform as .NET Framework 4.0, running over Windows 7 (x64) and I am unable to notice any issue. Can you please share some further details regarding your working environment.

If possible, please share some sample application which can help us in replicating this problem in our environment. We are sorry for this inconvenience.

C#

Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(new FileStream(@"C:\pdftest\ld\ld_output.pdf",  FileMode.Open));
Console.WriteLine(pdfDocument.Pages.Count);

I pasted the method below. Since I have got a stream and I don’t want to save it and open it again. I would like to create aspose new pdf document from the input stream and compress it if possible.

Thanks for your help.

internal Aspose.Pdf.Document CompressPDF(Stream stream)
{
Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(stream);
foreach (Aspose.Pdf.Page page in pdfDocument.Pages)
{
int idx = 1;
foreach (Aspose.Pdf.XImage image in page.Resources.Images)
{
using (var imageStream = new MemoryStream())
{
// To compress images change the image type and resolution
image.Save(imageStream, System.Drawing.Imaging.ImageFormat.Png, 72);
imageStream.Seek(0, SeekOrigin.Begin);
// Control image quality for better compression
page.Resources.Images.Replace(idx, imageStream, 80);
}
idx = idx + 1;
}
}
//pdfDocument.OptimizeResources();
pdfDocument.OptimizeResources(new Aspose.Pdf.Document.OptimizationOptions()
{
LinkDuplcateStreams = true,
RemoveUnusedObjects = true,
RemoveUnusedStreams = true,
});
return pdfDocument;
}

Hi Aleazhao,

Thanks for sharing the details.

I have again tested the scenario using the following code snippet and I am unable to notice any issue. Can you please share the console application, so that we can try replicating the issue at our end.

C#

Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(new FileStream(@"C:\pdftest\TableRenderingIssue.pdf", FileMode.Open));

foreach (Aspose.Pdf.Page page in pdfDocument.Pages)
{
    int idx = 1;
    foreach (Aspose.Pdf.XImage image in page.Resources.Images)
    {
        using (var imageStream = new MemoryStream())
        {
            // To compress images change the image type and resolution
            image.Save(imageStream, System.Drawing.Imaging.ImageFormat.Png, 72);
            imageStream.Seek(0, SeekOrigin.Begin);
            // Control image quality for better compression
            page.Resources.Images.Replace(idx, imageStream, 80);
        }
        idx = idx + 1;
    }
}

//pdfDocument.OptimizeResources();

pdfDocument.OptimizeResources(new Aspose.Pdf.Document.OptimizationOptions()
{
    LinkDuplcateStreams = true,
    RemoveUnusedObjects = true,
    RemoveUnusedStreams = true,
});

Console.WriteLine(pdfDocument.Pages.Count);