We are using Aspose License and trying to reduce PDF document size by using optimization options. All optimization options working fine except images compress options. Its working fine in local environment which is windows. We deployed same code to Linux server(Ubuntu). Its returning Not supported image type error while compressing PDF document. Please suggest if we have a way to resolve this issue.
Error:
System.NotImplementedException: Not supported image type\n at Aspose.Pdf.XImage.#=zIiigXgQ=(ImageFormat #=zuWsmbks=, Int32 #=ze7ihkeI=)\n
at Aspose.Pdf.XImage.#=zixZh8fE=(ImageFormat #=zdcO71xg=)\n at #=ztO64Avni3qq7rQ5p4eNhCJTKDcmtYrkMjNDPhyw=.#=zy5r$HLAiA0h7c$dU4g==(OperatorCollection #=zUMFrcIQ=, Resources #=zucCm36Y=)\n
at #=ztO64Avni3qq7rQ5p4eNhCJTKDcmtYrkMjNDPhyw=.#=zFTd3ulQ=(Document #=zSnDpKwc=)\n
at #=z_xr9QCFPcaX$gihWzRQWC2Q_$bkx.#=zFTd3ulQ=(OptimizationOptions #=zUQgZ6SA=)\n
at Aspose.Pdf.Document.OptimizeResources(OptimizationOptions strategy)\n
Code:
public static byte[] OptimizeResources(Aspose.Pdf.Document pdfDocument, string path)
{
foreach (var page in pdfDocument.Pages)
{
foreach (var annotation in page.Annotations)
{
annotation.Flatten();
}
}
if (pdfDocument.Form.Fields.Count() > 0)
{
foreach (var item in pdfDocument.Form.Fields)
{
item.Flatten();
}
}
var optimizationOptions = new Aspose.Pdf.Optimization.OptimizationOptions();
optimizationOptions.RemoveUnusedObjects = true;
optimizationOptions.RemoveUnusedStreams = true;
optimizationOptions.AllowReusePageContent = true;
optimizationOptions.LinkDuplcateStreams = true;
optimizationOptions.CompressObjects = true;
optimizationOptions.UnembedFonts = true;
optimizationOptions.ImageCompressionOptions.CompressImages = true;
optimizationOptions.ImageCompressionOptions.ImageQuality = 30;
optimizationOptions.ImageCompressionOptions.ResizeImages = true;
optimizationOptions.ImageCompressionOptions.Version = Aspose.Pdf.Optimization.ImageCompressionVersion.Fast;
optimizationOptions.ImageCompressionOptions.MaxResolution = 72;
optimizationOptions.ImageCompressionOptions.Encoding = ImageEncoding.Flate;
pdfDocument.OptimizeResources(optimizationOptions);
pdfDocument.Save(path);
return File.ReadAllBytes(path);
}