public static PdfMapFile ValidatePdf(string pdfFileName, out float dpi, out Size bitmapSize, out string errorMessageText) { IPdfLoadingStatus loadingStatus = new PdfLoadingUI(); // UNDONE: Should this be passed in instead? PdfMapFile mapFile = new PdfMapFile(pdfFileName); bool ok = true; PdfMapFile.ConversionStatus status = mapFile.BeginConversion(); if (status == PdfMapFile.ConversionStatus.Working) { // Put up a modal dialog until loading is complete. mapFile.ConversionCompleted += delegate { loadingStatus.LoadingComplete(mapFile.Status == PdfMapFile.ConversionStatus.Success, mapFile.ConversionOutput); }; if (status == PdfMapFile.ConversionStatus.Working) { ok = loadingStatus.ShowLoadingStatus(pdfFileName); } } status = mapFile.Status; if (!ok || status == PdfMapFile.ConversionStatus.Failure) { errorMessageText = MiscText.PdfConversionFailed; if (!string.IsNullOrWhiteSpace(mapFile.ConversionOutput)) errorMessageText += ": " + mapFile.ConversionOutput; dpi = 0; bitmapSize = default(Size); return null; } // Make sure resulting image file can be read. try { Bitmap bitmap = (Bitmap)Image.FromFile(mapFile.PngFileName); dpi = bitmap.HorizontalResolution; bitmapSize = bitmap.Size; bitmap.Dispose(); errorMessageText = ""; return mapFile; } catch { // Couldn't read the resulting PNG errorMessageText = string.Format(MiscText.PdfResultNotReadable, mapFile.PngFileName); dpi = 0; bitmapSize = default(Size); return null; } }