Hi
I have been testing Aspose.pdf for .Net, as my company is looking to purchase several copies of Aspose for manipulation of images within PDFs.
It all works fine, apart from when I have to extract a specific image that is a png with a transparent background. In the provided attachment it is the third image down and is labelled as “info.png”.
When I save this image to file as a jpg, the transparent background turns black, whilst when it is saved as a png, the whole image becomes transparent.
For my company to use Aspose, we would require this to work.
Could you please advise?
Below is the code that I use for the extraction of the images.
private void ExtractImages(string filename, string path)
{
ImageFormat format = ImageFormat.Png;
string extension = “.png”;
using (Document pdfDocument = new Document(filename))
{
for (int i = 1; i <= pdfDocument.Pages.Count; ++i)
{
using (Page page = pdfDocument.Pages[i])
{
for (int y = 1; y <= page.Resources.Images.Count; ++y)
{
string savefile = Path.Combine(path, string.Format(“image_{0}_{1}{2}”, i, y, extension));
bool success = true;
using (FileStream fstream = new FileStream(savefile, FileMode.Create))
{
XImage image = page.Resources.Images[y];
try
{
image.Save(fstream, format);
}
catch (Exception)
{
Console.WriteLine(“Failed to handle image at {0}-{1}”, i, y);
success = false;
}
}
if (!success)
{
File.Delete(savefile);
}
}
}
}
}
}