Blue tint after converting PDF to image

When I convert PDF to image, the resulting image has a blue tint. This only happens for some PDFs.

One such case is a PDF created by Aspose image-to-PDF using a PNG source image. The PDF looks fine when opened in Adobe Reader. However when I render the PDF to an image, there is a light blue tint. This only seems to happen for some PNG images. I will attach one such image, which was created by taking a printscreen in Windows 7, then pasted and saved by Paint.NET.

Changing the BackgroundColor property of the various elements when creating the PDF has no effect (which it shouldn't because the image has no transparency and the PDF looks fine).

Image to PDF code:

static Document ImageToPDF(string imageFilePath, ImageFileType imageFileType)
{
    using (var img = System.Drawing.Image.FromFile(imageFilePath))
    {
        var width = (float)img.Width * 72 / img.HorizontalResolution;
        var height = (float)img.Height * 72 / img.VerticalResolution;
        var pdf = new Pdf
        {
            PageSetup =
            {
                Margin = new MarginInfo(),
                PageBorderMargin = new MarginInfo(),
                PageWidth = width,
                PageHeight = height,
            }
        };
        var section = new Section(pdf)
        {
            PageInfo =
            {
                PageWidth = width,
                PageHeight = height,
                Margin = new MarginInfo(),
                PageBorderMargin = new MarginInfo(),
            }
        };
        var image = new Image(section)
        {
            Margin = new MarginInfo(),
            ImageInfo =
            {
                SystemImage = img,
                ImageFileType = imageFileType,
            }
        };
        section.Paragraphs.Add(image);
        pdf.Sections.Add(section);
    var tempStream = new MemoryStream();
    pdf.Save(tempStream);

    return new Document(tempStream);
}

}

PDF to image code:

static System.Drawing.Image PDFToImage(string pdfFilePath, ImageFormat format)
{
    var conv = new PdfConverter();
    conv.BindPdf(pdfFilePath);
    conv.StartPage = 1;
    conv.EndPage = 1;
    conv.Resolution = new Resolution(150);
    conv.DoConvert();
    if (!conv.HasNextImage())
        throw new InvalidOperationException("Failed to render");
using (var ms = new MemoryStream())
{
    conv.GetNextImage(ms, format);
    return System.Drawing.Image.FromStream(ms);
}

}

Usage:

var doc = ImageToPDF("msn.png", ImageFileType.Png);
doc.Save("msn.pdf"); // PDF looks fine
var image = PDFToImage("msn.pdf", ImageFormat.Png);
image.Save("msn-rendered.png"); // image has a blue tint compared to original
 

Using Aspose.Pdf 6.7.0.0

This attached pdf has a different problem: when I convert PDF to image, the image is black with white text.

Hi,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for sharing the template files and sample code.

I am able to generate both of your mentioned issues using your code and template files. For rectification, your issues have been registered in our issue tracking system with issue ids: PDFNEWNET-33306 (for blue blur effect) and PDFNEWNET-33307 (for black and white image). You will be notified via this forum thread regarding any updates against your issues.

Sorry for the inconvenience,

The issues you have found earlier (filed as PDFNEWNET-33307;PDFNEWNET-33306) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.

Hi, we are experimenting this issue with Aspose.PDF for .NET v 10.3.0, which is the newer version we can get because our license allows free upgrades until 4/21/2015. In our workflow, we convert individual pages of a PDF document to TIFF files, this is the portion of code where this is happening:

 public static void ConvertPDFPageToTIFF(Document pdfDocument, int pageNumber, string outputPath) 
    {
        JpegDevice jpgDevice = new JpegDevice(new Resolution(96), 100);

        using (MemoryStream imageStream = new MemoryStream())
        {
            jpgDevice.Process(pdfDocument.Pages[pageNumber], imageStream);

            System.Drawing.Image image = System.Drawing.Image.FromStream(imageStream);

            ImageCodecInfo codecInfo = GetEncoder(ImageFormat.Tiff);

            EncoderParameter qualityParam = new EncoderParameter(Encoder.Quality, 100L);

            EncoderParameter compresionParam = new EncoderParameter(Encoder.Compression, (long)EncoderValue.CompressionLZW);

            EncoderParameters encoderParameters = new EncoderParameters(2);

            encoderParameters.Param[0] = qualityParam;

            encoderParameters.Param[1] = compresionParam;

            using (MemoryStream memoryStream = new MemoryStream())
            {
                image.Save(memoryStream, codecInfo, encoderParameters);

                File.WriteAllBytes(outputPath, memoryStream.ToArray());
            }
        }
    }

    private static ImageCodecInfo GetEncoder(ImageFormat format)
    {

        ImageCodecInfo[] codecs = ImageCodecInfo.GetImageDecoders();

        foreach (ImageCodecInfo codec in codecs)
        {
            if (codec.FormatID == format.Guid)
            {
                return codec;
            }
        }
        return null;
    }

Usage:

       string outputPath = @"D:\Temp\";

        FileInfo file = new FileInfo("D:\\Temp\test.pdf");

        using (FileStream fs = file.OpenRead())
        {
            Document pdfDocument = new Document(fs);

            foreach (var page in pdfDocument.Pages)
            {
                ConvertPDFPageToTIFF(page, outputPath);
            }
        }

@lmarzetti

We are afraid that you are using quite older version of the API whereas it is always recommended to use latest one. However, would you please share your sample document with us? We will test the scenario using the latest version and share our feedback with you.