private void UpdateInputPages(bool reset) { try { using (var wait = new WaitCursor()) { var fileName = _inputDocumentFileTextBox.Text.Trim(); if (File.Exists(fileName)) { _preferences.InputDocumentPageCount = _preferences.RasterCodecsInstance.GetTotalPages(fileName); } } } catch (Exception ex) { // We do not know _preferences.InputDocumentPageCount = 0; Debug.WriteLine(ex.Message); } // Reset the pages if (_preferences.InputDocumentPageCount > 0) { // We know the pages _fromPageNumericUpDown.Maximum = _preferences.InputDocumentPageCount; _toPageNumericUpDown.Maximum = _preferences.InputDocumentPageCount; } else { // We do not know the pages _fromPageNumericUpDown.Maximum = Int16.MaxValue; _toPageNumericUpDown.Maximum = Int16.MaxValue; } if (reset || _preferences.InputFirstPage > _preferences.InputDocumentPageCount || _preferences.InputLastPage > _preferences.InputDocumentPageCount || (_preferences.InputFirstPage == 1 && (_preferences.InputLastPage == -1 || _preferences.InputLastPage == _preferences.InputDocumentPageCount))) { if (_preferences.InputLastPage > _preferences.InputDocumentPageCount) { _preferences.InputLastPage = _preferences.InputDocumentPageCount; } _fromPageNumericUpDown.Value = 1; _toPageNumericUpDown.Value = Math.Max(1, Math.Max(_preferences.InputLastPage, _preferences.InputDocumentPageCount)); _firstPageCheckBox.Checked = true; _lastPageCheckBox.Checked = true; } else { _fromPageNumericUpDown.Value = _preferences.InputFirstPage; if (_preferences.InputLastPage == -1) { if (_preferences.InputDocumentPageCount > 0) { _toPageNumericUpDown.Value = _preferences.InputDocumentPageCount; } else { _toPageNumericUpDown.Value = 1; } } else { _toPageNumericUpDown.Value = _preferences.InputLastPage; } _firstPageCheckBox.Checked = false; _lastPageCheckBox.Checked = (_preferences.InputLastPage == -1); } UpdateActualTotalPages(); }
//Use this load to load an image using the open dialog public int Load(IWin32Window owner, RasterCodecs codecs, bool autoLoad) { using (RasterOpenDialog ofd = new RasterOpenDialog(codecs)) { ofd.DereferenceLinks = true; ofd.CheckFileExists = false; ofd.CheckPathExists = true; ofd.EnableSizing = true; ofd.Filter = Filters; ofd.FilterIndex = _filterIndex; ofd.LoadFileImage = false; ofd.LoadOptions = false; ofd.LoadRotated = true; ofd.LoadCompressed = true; ofd.LoadMultithreaded = codecs.Options.Jpeg.Load.Multithreaded; ofd.ShowLoadMultithreaded = true; ofd.Multiselect = _multiSelect; ofd.ShowGeneralOptions = true; ofd.ShowLoadCompressed = true; ofd.ShowLoadOptions = true; ofd.ShowLoadRotated = true; ofd.ShowMultipage = true; ofd.UseGdiPlus = UseGdiPlus; ofd.ShowPdfOptions = ShowPdfOptions; ofd.ShowXpsOptions = ShowXpsOptions; ofd.ShowXlsOptions = ShowXlsOptions; ofd.ShowRasterizeDocumentOptions = ShowRasterizeDocumentOptions; ofd.EnableFileInfoModeless = true; ofd.EnableFileInfoResizing = true; ofd.ShowVffOptions = ShowVffOptions; ofd.ShowAnzOptions = ShowAnzOptions; ofd.ShowVectorOptions = ShowVectorOptions; ofd.ShowPreview = true; ofd.ShowProgressive = true; ofd.ShowRasterOptions = true; ofd.ShowTotalPages = true; ofd.ShowDeletePage = true; ofd.ShowFileInformation = true; ofd.UseFileStamptoPreview = true; ofd.PreviewWindowVisible = true; ofd.Title = "LEADTOOLS Open Dialog"; ofd.FileName = FileName; ofd.LoadCorrupted = LoadCorrupted; ofd.PreferVector = PreferVector; if (!String.IsNullOrEmpty(_openDialogInitialPath)) { ofd.InitialDirectory = _openDialogInitialPath; } if (ofd.ShowDialog(owner) == DialogResult.OK) { foreach (RasterDialogFileData item in ofd.OpenedFileData) { FileName = item.Name; _filterIndex = ofd.FilterIndex; // Set the RasterizeDocument load options before calling GetInformation codecs.Options.RasterizeDocument.Load.PageWidth = item.Options.RasterizeDocumentOptions.PageWidth; codecs.Options.RasterizeDocument.Load.PageHeight = item.Options.RasterizeDocumentOptions.PageHeight; codecs.Options.RasterizeDocument.Load.LeftMargin = item.Options.RasterizeDocumentOptions.LeftMargin; codecs.Options.RasterizeDocument.Load.TopMargin = item.Options.RasterizeDocumentOptions.TopMargin; codecs.Options.RasterizeDocument.Load.RightMargin = item.Options.RasterizeDocumentOptions.RightMargin; codecs.Options.RasterizeDocument.Load.BottomMargin = item.Options.RasterizeDocumentOptions.BottomMargin; codecs.Options.RasterizeDocument.Load.Unit = item.Options.RasterizeDocumentOptions.Unit; codecs.Options.RasterizeDocument.Load.XResolution = item.Options.RasterizeDocumentOptions.XResolution; codecs.Options.RasterizeDocument.Load.YResolution = item.Options.RasterizeDocumentOptions.YResolution; codecs.Options.RasterizeDocument.Load.SizeMode = item.Options.RasterizeDocumentOptions.SizeMode; if (item.FileInfo.Format == RasterImageFormat.Afp || item.FileInfo.Format == RasterImageFormat.Ptoca) { codecs.Options.Ptoka.Load.Resolution = codecs.Options.RasterizeDocument.Load.XResolution; } // Set the user Options codecs.Options.Load.Passes = item.Passes; codecs.Options.Load.Rotated = item.LoadRotated; codecs.Options.Load.Compressed = item.LoadCompressed; codecs.Options.Load.LoadCorrupted = ofd.LoadCorrupted; codecs.Options.Load.PreferVector = ofd.PreferVector; codecs.Options.Jpeg.Load.Multithreaded = item.LoadMultithreaded; switch (item.Options.FileType) { case RasterDialogFileOptionsType.Meta: { // Set the user options codecs.Options.Wmf.Load.XResolution = item.Options.MetaOptions.XResolution; codecs.Options.Wmf.Load.YResolution = item.Options.MetaOptions.XResolution; break; } case RasterDialogFileOptionsType.Pdf: { if (codecs.Options.Pdf.Load.UsePdfEngine) { // Set the user options codecs.Options.Pdf.Load.DisplayDepth = item.Options.PdfOptions.DisplayDepth; codecs.Options.Pdf.Load.GraphicsAlpha = item.Options.PdfOptions.GraphicsAlpha; codecs.Options.Pdf.Load.TextAlpha = item.Options.PdfOptions.TextAlpha; codecs.Options.Pdf.Load.UseLibFonts = item.Options.PdfOptions.UseLibFonts; } break; } case RasterDialogFileOptionsType.Misc: { switch (item.FileInfo.Format) { case RasterImageFormat.Jbig: { // Set the user options codecs.Options.Jbig.Load.Resolution = new LeadSize(item.Options.MiscOptions.XResolution, item.Options.MiscOptions.YResolution); break; } case RasterImageFormat.Cmw: { // Set the user options codecs.Options.Jpeg2000.Load.CmwResolution = new LeadSize(item.Options.MiscOptions.XResolution, item.Options.MiscOptions.YResolution); break; } case RasterImageFormat.Jp2: { // Set the user options codecs.Options.Jpeg2000.Load.Jp2Resolution = new LeadSize(item.Options.MiscOptions.XResolution, item.Options.MiscOptions.YResolution); break; } case RasterImageFormat.J2k: { // Set the user options codecs.Options.Jpeg2000.Load.J2kResolution = new LeadSize(item.Options.MiscOptions.XResolution, item.Options.MiscOptions.YResolution); break; } } break; } case RasterDialogFileOptionsType.Xls: { // Set the user options codecs.Options.Xls.Load.MultiPageSheet = item.Options.XlsOptions.MultiPageSheet; codecs.Options.Xls.Load.ShowHiddenSheet = item.Options.XlsOptions.ShowHiddenSheet; #if LEADTOOLS_V20_OR_LATER codecs.Options.Xls.Load.MultiPageUseSheetWidth = item.Options.XlsOptions.MultiPageUseSheetWidth; codecs.Options.Xls.Load.PageOrderDownThenOver = item.Options.XlsOptions.PageOrderDownThenOver; codecs.Options.Xls.Load.MultiPageEnableMargins = item.Options.XlsOptions.MultiPageEnableMargins; #endif //#if LEADTOOLS_V20_OR_LATER } break; case RasterDialogFileOptionsType.Vff: { codecs.Options.Vff.Load.View = item.Options.VffOptions.View; break; } case RasterDialogFileOptionsType.Anz: { codecs.Options.Anz.Load.View = item.Options.AnzOptions.View; break; } case RasterDialogFileOptionsType.Vector: { codecs.Options.Vector.Load.BackgroundColor = item.Options.VectorOptions.Options.BackgroundColor; codecs.Options.Vector.Load.BitsPerPixel = item.Options.VectorOptions.Options.BitsPerPixel; codecs.Options.Vector.Load.ForceBackgroundColor = item.Options.VectorOptions.Options.ForceBackgroundColor; codecs.Options.Vector.Load.ViewHeight = item.Options.VectorOptions.Options.ViewHeight; codecs.Options.Vector.Load.ViewMode = item.Options.VectorOptions.Options.ViewMode; codecs.Options.Vector.Load.ViewWidth = item.Options.VectorOptions.Options.ViewWidth; break; } } int firstPage = 1; int lastPage = 1; int infoTotalPages; CodecsImageInfo info = null; using (WaitCursor wait = new WaitCursor()) { info = codecs.GetInformation(FileName, true); infoTotalPages = info.TotalPages; } if (_showLoadPagesDialog) { firstPage = 1; lastPage = infoTotalPages; if (firstPage != lastPage) { using (ImageFileLoaderPagesDialog dlg = new ImageFileLoaderPagesDialog(infoTotalPages, LoadOnlyOnePage)) { if (dlg.ShowDialog(owner) == DialogResult.OK) { firstPage = dlg.FirstPage; lastPage = dlg.LastPage; } else { if (info != null) { info.Dispose(); } return(0); } } } } else { firstPage = item.PageNumber; lastPage = item.PageNumber; } _firstPage = firstPage; _lastPage = lastPage; if (!SetDocumentLoadResultion(codecs, info, firstPage, lastPage)) { info.Dispose(); return(0); } if (autoLoad) { using (WaitCursor wait = new WaitCursor()) { _image = codecs.Load(FileName, 0, CodecsLoadByteOrder.BgrOrGray, firstPage, lastPage); if (codecs.LoadStatus != RasterExceptionCode.Success) { String message = String.Format("The image was only partially loaded due to error: {0}", codecs.LoadStatus.ToString()); Messager.Show(null, message, MessageBoxIcon.Information, MessageBoxButtons.OK); } if (_image != null) { _image.CustomData.Add("IsBigTiff", info.Tiff.IsBigTiff); _images.Add(new ImageInformation(_image, item.Name)); } } } info.Dispose(); } } return(ofd.OpenedFileData.Count); } }