I tried to generate a preview of the first page a secured pdf file. The file is only secured and is not password protected. But I got an PasswordProtectedException exception.
public byte[] GeneratePreview(byte[] fileContent)
{
var name = Guid.NewGuid().ToString();
var saveOptions = new ImageSaveOptions
{
ConvertFileType = ImageSaveOptions.ImageFileType.Jpg,
OutputType = OutputType.Stream,
UsePdf = false,
Dpi = 72,
PageNumber = 1,
NumPagesToConvert = 1,
Width = 350,
Height = 500,
CustomName = name,
UseWidthForCustomName = false,
};
var conversionHandler = new ConversionHandler(GroupDocsConfig.ConversionConfig.Value);
try
{
var stream = conversionHandler.Convert<IList>(new MemoryStream(fileContent), saveOptions)[0];
stream.Seek(0, SeekOrigin.Begin);
var bytes = new byte[stream.Length];
stream.Read(bytes, 0, (int)stream.Length);
return bytes;
}
catch (Exception ex)
{
throw;
}
}
Exception:
Message = "Exception of type 'GroupDocs.Conversion.Exception.PasswordProtectedException' was thrown."
StackTrace:
Exception:
Message = "Exception of type 'GroupDocs.Conversion.Exception.PasswordProtectedException' was thrown."
StackTrace:
at . [T](LoadOptions , SaveOptions )
at GroupDocs.Conversion.Handler.ConversionHandler. [T](Stream , , LoadOptions , SaveOptions )
at GroupDocs.Conversion.Handler.ConversionHandler.Convert[T](Stream fileStream, LoadOptions loadOptions, SaveOptions saveOptions)
at GroupDocs.Conversion.Handler.ConversionHandler.Convert[T](Stream fileStream, SaveOptions saveOptions)
at xxx.yyy.Service.Preview.PreviewServiceBase.GeneratePreview(Byte[] fileContent) in E:\Code\yyy\xxx.yyy.Services\Preview\PreviewServiceBase.cs:line 35