Click here to Skip to main content
15,880,392 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am trying to get a pdf document using the stream and I get as "Aspose.Pdf.invalidPdfFileformatException: 'Incorrect file format'"

What I have tried:

C#
<pre>internal async void ExtractImages(CloudFilePath sourcePath, string filePath, CloudFilePath outputFilenameTemplate, int startPage, int endPage, int dpi)
        {
            var fileStreamContainer = await this.fileSystem.ReadFileAsync(sourcePath, default);
            Stream fileStream = new MemoryStream(fileStreamContainer);
            string extension = Path.GetExtension(filePath);
            var pngDevice = new PngDevice(new Resolution(dpi));
            Document doc = new Document(fileStream);

            using (var document = new Document(filePath))
            {
                for (var pageIndex = startPage; pageIndex <= endPage; pageIndex++)
                {
                    using (var stream = File.Create(outputFilenameTemplate.ToString()))
                    {
                         pngDevice.Process(document.Pages[pageIndex], stream);
                    }
                }
            }
        }


I get the error message in the
C#
Document doc = new Document(fileStream);
line of the code. Not sure what I am missing.
I have uploaded the pdf which I also made sure by getting the extension, which also returns as pdf. In the above the filepath is
C#
var filePath = Path.Combine(amazonConfiguration.LocalStack + sourcePath.ToString());


Can anyone help me to fix this issue.
Posted
Updated 6-Jan-21 3:16am
Comments
Richard MacCutchan 12-Nov-20 8:58am    
What is the actual value in filePath? Does fileStream contain the actual content of the file? Is the stream seekable?

1 solution

For 3rd party components, always use their official forum for quick answers. And you have purchased components so they must support you.

Are you using trail version? If yes, then probably that's the reason, check below thread.
Incorrect file format - Aspose.PDF Product Family - Free Support Forum - aspose.com[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900