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