Hi.
I wrote a small free application that converts image files to PDF documents. When using it on a BMP file, one user encountered this error:
Code:
NotImplementedException: Image format not supported.
at PdfSharp.Pdf.Advanced.PdfImage.InitializeNonJpeg()
at PdfSharp.Pdf.Advanced.PdfImage..ctor(PdfDocument document, XImage image)
at PdfSharp.Pdf.Advanced.PdfImageTable.GetImage(XImage image)
at PdfSharp.Pdf.PdfPage.GetImageName(XImage image)
at PdfSharp.Drawing.Pdf.XGraphicsPdfRenderer.GetImageName(XImage image)
at PdfSharp.Drawing.Pdf.XGraphicsPdfRenderer.Realize(XImage image)
at PdfSharp.Drawing.Pdf.XGraphicsPdfRenderer.DrawImage(XImage image, Double x, Double y, Double width, Double height)
at PdfSharp.Drawing.XGraphics.DrawImage(XImage image, Double x, Double y)
at PdfSharp.Drawing.XGraphics.DrawImage(XImage image, Int32 x, Int32 y)
I was skeptic at first, but he sent me the file and it is correct and accurate. It's a BMP file, which can even be displayed by the basic viewer of TotalCommander, pressing F3.
Debugging the application I found the LOC where the exception is thrown.
It's the one where "DrawImage" is called:
Code:
PdfDocument doc = new PdfDocument();
doc.Pages.Add(new PdfPage());
XGraphics xgr = XGraphics.FromPdfPage(doc.Pages[0]);
XImage img = XImage.FromFile(source);
//adjust page size to fit image
if (doc.Pages[0].Width < XUnit.FromPoint(img.Size.Width))
doc.Pages[0].Width = XUnit.FromPoint(img.Size.Width);
if (doc.Pages[0].Height < XUnit.FromPoint(img.Size.Height))
doc.Pages[0].Height = XUnit.FromPoint(img.Size.Height);
xgr.DrawImage(img, 0, 0, img.Size.Width, img.Size.Height);
doc.Save(destinaton);
doc.Close();
I tested with PDFSharp versions 1 and 1.20 beta and the result is the same. If needed I can provide the BMP file that causes this.
Thanks for your time and effort and keep up the good work!