Free Support Forum - groupdocs.com

Convert a single page of multipaged document to PNG in .NET

Hi,

I just found out that saving a single page of a multi-page document as png fails since the update to Conversion .Net 20.1 with the following error:

Saving complete multi page document to image is not supported. Please save by page.

This code for thumbnail generation was working previously:

    using (var conv = new Converter(sInputFile))
    {
        var options = new ImageConvertOptions()
        {
            Format = ImageFileType.Png,
            //convert only the first page for thumbnail
            PageNumber = 1,
            PagesCount = 1,
            //low dpi for thumbnail
            VerticalResolution = 30,
            HorizontalResolution = 30
        };
        conv.Convert(sOutputFile, options);
    }

Are we forced to use “SavePageStream” now, or how does processing single pages now work?

I saw that there was a bug listed with the 20.1 release:
CONVERSIONNET-3625 Bug PageNumber and PagesCount not respected when converting to image.
Could this be the same issue?

If it is, I apologize for posting a duplicate and want to add that not only PageNumber and PagesCount are ignored, but also the Vertical- and HorizontalResolution property (when using SavePageStream instead).

1 Like

@Clemens_Pestuka,

Using code below, we’re not able to reproduce this issue at our end (you have to use SavePageStream):

 string outputFileTemplate = Path.Combine(@"D:/Samples/", "converted-page-{0}.png");
 GroupDocs.Conversion.Contracts.SavePageStream getPageStream = page => new FileStream(string.Format(outputFileTemplate, page), FileMode.Create);
 using (Converter converter = new Converter(@"D:/Samples/target.pdf"))
 {
        var options = new ImageConvertOptions()
         {
              Format = ImageFileType.Png,
               //convert only the first page for thumbnail
               PageNumber = 1,
               PagesCount = 1,
              //low dpi for thumbnail
              VerticalResolution = 30,
              HorizontalResolution = 30
          };
          converter.Convert(getPageStream, options);
  }

Have a look at output image.png (13.8 KB). Vertical and horizontal resolutions are successfully applied. Have a look at this article.

.

@atirtahir3
Thank you for the reply. I agree that the code you sent works fine, I tried that too.

What worries me is:

(you have to use SavePageStream )

This was not needed in 19.12.1 and the code I sent was working in that version, but with 20.1 it just broke :frowning: .
Do I really need to use SavePageStream now, although I will only have 1 single page (due to PageNumber and PagesCount)?
I did not see this as a breaking change, are such things usually reported?

@Clemens_Pestuka,

We are investigating this. Your investigation ticket ID is CONVERSIONNET-3726. As there is any further update, you’ll be notified.

1 Like

@atirtahir3

When testing another issue I also realized that this issue only seems to happen with a certain docx file.
Portrait_Landscape.zip (14.1 KB)

For this document, a second empty page is created, although pageCount is 1.
Conversion output.zip (5.9 KB)

So it looks like nothing changed and we don’t need to use SavePageStream now.
Just for this one document I got the error

Saving complete multi page document to image is not supported. Please save by page.

because there was actually more than one page to save.
So the actual bug that needs to be fixed, is the second empty page that should not be created.

1 Like

@Clemens_Pestuka,

We’ll further investigate this issue and let you know as there’s any update.

1 Like