Aspose.Pdf XImage.Save to TIFF reversing black/white on Server 2012

We are using Aspose.Pdf to extract images from a PDF created by a copier. On Windows Server 2012 the images are being extracted with a black background and white text. On Windows Server 2008 and Windows 7 the images are being extracted with a white background and black text just like the PDF through FoxIt Reader or Acrobat Reader displays.


The exact same code/exe is being run in all the various environments against the exact same pdf. I have uploaded the PDF as “sample.pdf”. I have uploaded copies of the TIFFs in the “ExtractedPages.zip” file. The zip file contains a folder for Server 2008 and Server 2012 that shows the output TIFFs from the code below.

Can you help me understand what is going on.

using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using Aspose.Pdf;

namespace PdfToTiff
{
class Program
{
static void Main(string[] args)
{
var license = new License();
license.SetLicense(“Aspose.Total.lic”);

var sourceStream = File.OpenRead(“sample.pdf”);
var document = new Document(sourceStream);

var pdfImages = document.Pages
.Cast()
.Select(x => x.Resources.Images[1])
.ToArray();

for (var i = 0; i <pdfImages.Length; i++)
{
var pdfImage = pdfImages[i];
using (var stream = File.OpenWrite(“sample-” + i + “.tiff”))
{
pdfImage.Save(stream, ImageFormat.Tiff);
}
}
}
}
}


Hi Mike,


Thanks for contacting support.

I have tested the scenario and I am able to
notice the same problem. For the sake of correction, I have logged this problem
as PDFNEWNET-39958 in our issue tracking system. We will
further look into the details of this problem and will keep you updated on the
status of correction. Please be patient and spare us little time. We are sorry
for this inconvenience.

Do I have anyway to view the status of the issue in your issue tracker? Is there anyway to know priority or where it is in the queue of items to be researched?

Hi Mike,


Thanks for contacting support.

As we recently have been able to notice the issue, so its pending for review and until or unless we have investigated the issue in details, I am afraid we might not be able to share the possible timelines by which it will be resolved. Please note that issues are fixed in first come first serve basis as we believe its the fairest policy to all the customers. As soon as we have some definite updates, we will let you know.

Please be patient and spare us little time.

Any solution to this problem?

Hi Mike,


Thanks for your patience.

I am afraid the earlier reported issue is pending for review and is not yet resolved. However the product team will surely consider investigating/fixing it as per development schedule and as soon as we have some definite updates regarding its resolution, we will let you know. Please be patient and spare us little time. We are sorry for this delay and inconvenience.

The workaround I used was to Save the XImage to disk as a BMP then use Aspose.Image to convert it to a TIFF.


Has been working reliably for me.

foreach (var pdfImage in pdfImages)
{
// for some reason on Win Server 2012 and Win 10 it works much
// better to write it as a Bitmap first. When directly writing
// to a TIFF it is flipping the white/black values because
// it is not using the indexed palette
var bmpFile = TempFile.Create(GetType(), FileFormat.Bmp);
using (var stream = bmpFile.OpenWrite())
{
pdfImage.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);
}

var tiffFile = TempFile.Create(bmpFile.FullName + FileFormat.Tiff.Extension);
using (var bmpImage = (BmpImage)AImage.Load(bmpFile.FullName))
{
var options = new TiffOptions(TiffExpectedFormat.Default)
{
ResolutionUnit = TiffResolutionUnits.Inch,
Xresolution = new TiffRational(System.Convert.ToUInt32(bmpImage.HorizontalResolution)),
Yresolution = new TiffRational(System.Convert.ToUInt32(bmpImage.VerticalResolution))
};

bmpImage.Save(tiffFile.FullName, options);
}

TempFile.TryDelete(bmpFile);

tiffFile.Refresh();
tiffFiles.Add(tiffFile);
}

Hi Mike,


Thanks for your feedback and sharing your workaround. We will notify you as soon as your original logged issue is investigated and it is fixed in Aspose.Pdf for .NET.

Thanks for your patience and cooperation.

Best Regards,

Is this an issue you guys intend to fix?

@mike.doerfler,
The linked ticket ID PDFNET-39958 is not resolved yet. We have logged an ETA request under the same ticket ID PDFNET-39958. We will let you know once a significant progress has been made in this regard.

Best Regards,
Imran Rafique

is this an issue you guys intend to fix?

I can use the workaround but it has an impact on performance - the combination of using Save as BMP and then using Aspose.Image.Save for the TIFF is taking almost twice as long.

@mike.doerfler

Thank you for getting back to us.

We are afraid that the issue is still pending for investigations. However, we have recorded your concerns and will schedule it soon. We really appreciate your patience and comprehension in this regard.