Convert PDF to PNG8 instead of PNG24

Hello,


Does anybody know how to convert PDF to PNG8 ? By défault in my code, the PDF document is converted to PNG24. Is there any option that can be added ? I join my code below.

Thanks in advance for your help.
David
public static void GeneratePngWithASPOSE(PDF pdfInfo)
{
var pdfDocument = new Document(pdfInfo.SourceFolder + pdfInfo.FileName + sourceExtension);
try
{
if (!Directory.Exists(pdfInfo.DestinationFolder))
{
Directory.CreateDirectory(pdfInfo.DestinationFolder);
}
}
catch
{
throw new Exception(String.Format(“Droits d’écriture insuffisant, création de ‘{0}’ impossible”, pdfInfo.DestinationFolder));
}

pdfInfo.NumberOfPages = pdfDocument.Pages.Count;
for (int pageCount = 1; pageCount <= pdfDocument.Pages.Count; pageCount++)
{
var folderAndFileToSavePng = pdfInfo.DestinationFolder + pdfInfo.FileName + "
" + pageCount + _destinationExtension;
using (var imageStream = new FileStream(folderAndFileToSavePng, FileMode.Create))
{
var resolution = new Resolution(80);
var pngDevice = new PngDevice(resolution);
try
{
pngDevice.Process(pdfDocument.Pages[pageCount], imageStream);
}
catch
{
throw new Exception(String.Format(“Un problème est survenu la création de {0}”, folderAndFileToSavePng));
}
finally
{
imageStream.Close();
}
}

using (var myImage = System.Drawing.Image.FromFile(folderAndFileToSavePng))
{
if (myImage.Width < myImage.Height) // Portrait
{
myImage.RotateFlip(RotateFlipType.Rotate90FlipNone);
try
{
myImage.Save(folderAndFileToSavePng);
}
catch
{
throw new Exception(String.Format(“Un problème est survenu lors de la rotation de {0}”, folderAndFileToSavePng));
}
}
}
}
}

Hi David,


Thanks for your inquiry. I am afraid currently Aspose.Pdf does not support 8 bit PNG generation. However, we have logged a feature request PDFNEWNET-37840 in our issue tracking system for further investigation and implementation. We will notify you as soon as it is resolved.

Meanwhile, as a workaround you can accomplish your task with collaboration of Aspose.Pdf and Aspose.Imaging. Initially convert PDF to PNG using Aspose and later convert 24 bit PNG to 8 bit using Aspose.Imaging. My Aspose.Imaging colleague will share related details soon.

We are sorry for the inconvenience caused.

Best Regards,

Hi David,


As my fellow colleague has mentioned, you can convert the PNG images generated with Aspose.Pdf for .NET API to 8 bit PNG using the Aspose.Imaging for .NET API. Please check the following piece of code and give it a try on your side against the latest version of Aspose.Imaging for ,NET 2.6.0.

C#

using (var image = Image.Load(myDir + “sample.png”))
{
PngOptions options = new PngOptions();
options.ColorType = PngColorType.Grayscale;
image.Save(myDir + “output.png”, options);
}


Please feel free to write back in case you face any difficulty.

Thank you very much for your help !