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).
@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 .
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 - just curious - did you find a workaround for the initial issue you reported? I am encountering a similar issue, and am also not using the SavePageStream as was suggested in the recommended solution.
If you have a workaround, would you be able to share what you did?
Hi Brian, I did not really find or look for a workaround but just using SavePageStream and discarding the second file should be one.
It turned out that an empty page was generated at conversion (maybe some new-lines shifted) and that was the reason why saving to a single file did not work (there were two pages now). So the issue only occurred with a certain file.
If the same thing happens for you too, maybe sharing your document could help them fix the issue
Was this ever resolved? I’m getting same issue when trying pull first page from Excel to JPG. If I change output type to TIFF, I get 4 pages when I’m asking only for 1. This only happens with some Excels and not all.
ImageConvertOptions optionsImage = new ImageConvertOptions
{
Format = ImageFileType.Tif,
PageNumber = 1,
PagesCount = 1,
Width = 800
};
That code gets me 4 pages in tiff in some Excels. Clearly a bug.
@Clemens@NPozdniakov
The key point is to provide SpreadsheetLoadOptions with property OnePagePerSheet = true
Here is a sample code snippet, which provides one image for the complete sheet.
using (Converter converter = new GroupDocs.Conversion.Converter("ALEWIS_0000000021.0001.XLS", type => new SpreadsheetLoadOptions
{
OnePagePerSheet = true
}))
{
ImageConvertOptions options = new ImageConvertOptions { Format = GroupDocs.Conversion.FileTypes.ImageFileType.Jpg };
options.PageNumber = 1;
options.PagesCount = 1;
converter.Convert((i,type) => new FileStream($"result-page{i}.{type.Extension}", FileMode.Create, FileAccess.ReadWrite), options);
}
hmm… that doesn’t really work for me. Text on page is too small for most since we do OnePagePerSheet. I just want page 1 without any scaling. It should work exactly like for Doc file.
If OnePagePerSheet is applied - then the complete sheet is exported as one image. There is no scale, just the image, big in width and height and may need zoom to 100% to be viewed properly.
Otherwise, if OnePagePerSheet is set to no, the worksheet is exported as 18 images. It is the same as it is exported from MS Excel.
Could you please export your sample with Excel and show us the result?