I can't load stream of png in Aspose.Pdf.Document (error={"Startxref not found"})

how can I load in the constructor Aspose.Pdf.Document a png stream (like the case of stream pdf)

        var doc = new global::Aspose.Pdf.Document(stream); // stream of PNG
       
        var page = doc.Pages.Add();

        if (info.Width < 3 || info.Height < 3)
        {
            page.PageInfo.Margin.Top = 1.5f;
            page.PageInfo.Margin.Bottom = 1.5f;
            page.PageInfo.Margin.Left = 1.5f;
            page.PageInfo.Margin.Right = 1.5f;

            page.PageInfo.Width = info.Width + 3f;
            page.PageInfo.Height = info.Height + 3f;
        }
        else
        {
            page.PageInfo.Margin.Top = 0f;
            page.PageInfo.Margin.Bottom = 0f;
            page.PageInfo.Margin.Left = 0f;
            page.PageInfo.Margin.Right = 0f;

            page.PageInfo.Width = info.Width;
            page.PageInfo.Height = info.Height;
        }

        return doc;

i Have the error “Startxref not found” !

Thanks for help

@MohammedHa,

There is no direct way to import PNG into the Document instance. You can create a new PDF document, add a page, and then insert an image as well as set page settings. Please refer to this help topic: Convert an Image to PDF

Thx @imran.rafique,

I want to transform a PNG stream and add a specific resolution to generate another PNG file using Aspose.Pdf.Document !

It does not work :frowning:

it’s resolved, you have to save the document with “Document.Save” even if you do not need.

Thanks.

@MohammedHa,

It is nice to hear from you that the problem has been resolved. Please feel free to let us know in case of any more queries or assistance.

1 Like