Beispiel #1
0
        private void LoadDocument(string fileName, bool loadDefault)
        {
            try
            {
                using (RasterCodecs codecs = new RasterCodecs())
                {
                    // Set load resolution
                    codecs.Options.RasterizeDocument.Load.XResolution = 300;
                    codecs.Options.RasterizeDocument.Load.YResolution = 300;

                    int firstPage = 1;
                    int lastPage  = 1;
                    List <SvgDocument> documents = new List <SvgDocument>();

                    if (!loadDefault)
                    {
                        // Check if the file can be loaded as svg
                        bool canLoadSvg = codecs.CanLoadSvg(fileName);
                        using (CodecsImageInfo info = codecs.GetInformation(fileName, true))
                        {
                            if (!canLoadSvg)
                            {
                                // Check if the file type is not PDF
                                if (info.Format != RasterImageFormat.PdfLeadMrc &&
                                    info.Format != RasterImageFormat.RasPdf &&
                                    info.Format != RasterImageFormat.RasPdfCmyk &&
                                    info.Format != RasterImageFormat.RasPdfG31Dim &&
                                    info.Format != RasterImageFormat.RasPdfG32Dim &&
                                    info.Format != RasterImageFormat.RasPdfG4 &&
                                    info.Format != RasterImageFormat.RasPdfJbig2 &&
                                    info.Format != RasterImageFormat.RasPdfJpeg &&
                                    info.Format != RasterImageFormat.RasPdfJpeg411 &&
                                    info.Format != RasterImageFormat.RasPdfJpeg422 &&
                                    info.Format != RasterImageFormat.RasPdfJpx &&
                                    info.Format != RasterImageFormat.RasPdfLzw &&
                                    info.Format != RasterImageFormat.RasPdfLzwCmyk)
                                {
                                    MessageBox.Show("The selected file can't be loaded as an SVG file", "Invalid File Format", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    return;
                                }
                            }

                            if (info.TotalPages > 1)
                            {
                                using (ImageFileLoaderPagesDialog dlg = new ImageFileLoaderPagesDialog(info.TotalPages, false))
                                {
                                    if (dlg.ShowDialog(this) == DialogResult.Cancel)
                                    {
                                        return;
                                    }

                                    firstPage = dlg.FirstPage;
                                    lastPage  = dlg.LastPage;
                                }
                            }
                        }
                    }

                    using (WaitCursor wait = new WaitCursor())
                    {
                        for (int page = firstPage; page <= lastPage; page++)
                        {
                            SvgDocument svgDoc = codecs.LoadSvg(fileName, page, _loadSvgOptions) as SvgDocument;
                            documents.Add(svgDoc);
                        }

                        SetDocument(fileName, documents, firstPage);
                    }

                    UpdateControls();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, string.Format("Error {0}{1}{2}", ex.GetType().FullName, Environment.NewLine, ex.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
Beispiel #2
0
        public bool Load(IWin32Window owner, RasterCodecs codecs, bool autoLoad)
        {
#if LEADTOOLS_V16_OR_LATER && !LEADTOOLS_V17_OR_LATER
            // Load using the RasterizeDocument options
            codecs.Options.RasterizeDocument.Load.Enabled = true;
#endif

            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.Multiselect           = false;
            ofd.ShowGeneralOptions    = true;
            ofd.ShowLoadCompressed    = true;
            ofd.ShowLoadOptions       = true;
            ofd.ShowLoadRotated       = true;
            ofd.ShowMultipage         = true;
            ofd.ShowPdfOptions        = true;
            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;
#if LEADTOOLS_V16_OR_LATER
            ofd.ShowRasterizeDocumentOptions = true;
            ofd.ShowXlsOptions = true;
#endif
            bool ok = false;

            if (ofd.ShowDialog(owner) == DialogResult.OK)
            {
                RasterDialogFileData firstItem = ofd.OpenedFileData[0] as RasterDialogFileData;
                FileName = firstItem.Name;

                ok = true;

                _filterIndex = ofd.FilterIndex;

                CodecsImageInfo info;

                using (WaitCursor wait = new WaitCursor())
                    info = codecs.GetInformation(FileName, true);

                if (info.Format == RasterImageFormat.RasPdf ||
                    info.Format == RasterImageFormat.RasPdfG31Dim ||
                    info.Format == RasterImageFormat.RasPdfG32Dim ||
                    info.Format == RasterImageFormat.RasPdfG4 ||
                    info.Format == RasterImageFormat.RasPdfJpeg ||
                    info.Format == RasterImageFormat.RasPdfJpeg422 ||
                    info.Format == RasterImageFormat.RasPdfJpeg411)
                {
                    if (!codecs.Options.Pdf.IsEngineInstalled)
                    {
#if !LEADTOOLS_V17_OR_LATER
                        PdfEngineDialog dlg = new PdfEngineDialog();
                        if (dlg.ShowDialog(owner) != DialogResult.OK)
                        {
                            return(false);
                        }
#endif
                    }
                }

#if LEADTOOLS_V16_OR_LATER
                // Set the RasterizeDocument load options before calling GetInformation
#if !LEADTOOLS_V17_OR_LATER
                codecs.Options.RasterizeDocument.Load.Enabled = firstItem.Options.RasterizeDocumentOptions.Enabled;
#endif
                codecs.Options.RasterizeDocument.Load.PageWidth    = firstItem.Options.RasterizeDocumentOptions.PageWidth;
                codecs.Options.RasterizeDocument.Load.PageHeight   = firstItem.Options.RasterizeDocumentOptions.PageHeight;
                codecs.Options.RasterizeDocument.Load.LeftMargin   = firstItem.Options.RasterizeDocumentOptions.LeftMargin;
                codecs.Options.RasterizeDocument.Load.TopMargin    = firstItem.Options.RasterizeDocumentOptions.TopMargin;
                codecs.Options.RasterizeDocument.Load.RightMargin  = firstItem.Options.RasterizeDocumentOptions.RightMargin;
                codecs.Options.RasterizeDocument.Load.BottomMargin = firstItem.Options.RasterizeDocumentOptions.BottomMargin;
                codecs.Options.RasterizeDocument.Load.Unit         = firstItem.Options.RasterizeDocumentOptions.Unit;
                codecs.Options.RasterizeDocument.Load.XResolution  = firstItem.Options.RasterizeDocumentOptions.XResolution;
                codecs.Options.RasterizeDocument.Load.YResolution  = firstItem.Options.RasterizeDocumentOptions.YResolution;
                codecs.Options.RasterizeDocument.Load.SizeMode     = firstItem.Options.RasterizeDocumentOptions.SizeMode;
#endif

                // Set the user Options
                codecs.Options.Load.Passes     = firstItem.Passes;
                codecs.Options.Load.Rotated    = firstItem.LoadRotated;
                codecs.Options.Load.Compressed = firstItem.LoadCompressed;
                _FileFormatType = firstItem.Options.FileType;

                switch (firstItem.Options.FileType)
                {
                case RasterDialogFileOptionsType.Meta:
                {
                    // Set the user options
                    codecs.Options.Wmf.Load.XResolution = firstItem.Options.MetaOptions.XResolution;
                    codecs.Options.Wmf.Load.YResolution = firstItem.Options.MetaOptions.XResolution;

                    break;
                }

                case RasterDialogFileOptionsType.Pdf:
                {
                    if (codecs.Options.Pdf.IsEngineInstalled)
                    {
#if !LEADTOOLS_V175_OR_LATER
                        if (!_firstPdfLoaded)
                        {
                            PdfDPIOptions DPIOptions = new PdfDPIOptions();

                            if (DPIOptions.ShowDialog() == DialogResult.OK)
                            {
                                codecs.Options.Pdf.Load.XResolution = DPIOptions.XResolution;
                                codecs.Options.Pdf.Load.YResolution = DPIOptions.YResolution;
                                _firstPdfLoaded = true;
                            }
                            else
                            {
                                codecs.Options.Pdf.Load.XResolution = 150;
                                codecs.Options.Pdf.Load.YResolution = 150;
                            }
                        }
                        else
                        {
                            // Set the user options
                            codecs.Options.Pdf.Load.DisplayDepth  = firstItem.Options.PdfOptions.DisplayDepth;
                            codecs.Options.Pdf.Load.GraphicsAlpha = firstItem.Options.PdfOptions.GraphicsAlpha;
                            codecs.Options.Pdf.Load.TextAlpha     = firstItem.Options.PdfOptions.TextAlpha;
                            codecs.Options.Pdf.Load.UseLibFonts   = firstItem.Options.PdfOptions.UseLibFonts;
                        }
#endif
                    }

                    break;
                }

                case RasterDialogFileOptionsType.Misc:
                {
                    switch (firstItem.FileInfo.Format)
                    {
                    case RasterImageFormat.Jbig:
                    {
                        // Set the user options
                        codecs.Options.Jbig.Load.Resolution = new LeadSize(firstItem.Options.MiscOptions.XResolution,
                                                                           firstItem.Options.MiscOptions.YResolution);
                        break;
                    }

                    case RasterImageFormat.Cmw:
                    {
                        // Set the user options
                        codecs.Options.Jpeg2000.Load.CmwResolution = new LeadSize(firstItem.Options.MiscOptions.XResolution,
                                                                                  firstItem.Options.MiscOptions.YResolution);
                        break;
                    }

                    case RasterImageFormat.Jp2:
                    {
                        // Set the user options
                        codecs.Options.Jpeg2000.Load.Jp2Resolution = new LeadSize(firstItem.Options.MiscOptions.XResolution,
                                                                                  firstItem.Options.MiscOptions.YResolution);
                        break;
                    }

                    case RasterImageFormat.J2k:
                    {
                        // Set the user options
                        codecs.Options.Jpeg2000.Load.J2kResolution = new LeadSize(firstItem.Options.MiscOptions.XResolution,
                                                                                  firstItem.Options.MiscOptions.YResolution);
                        break;
                    }
                    }

                    break;
                }
                }

                int firstPage = 1;
                int lastPage  = 1;

                if (ShowLoadPagesDialog)
                {
                    firstPage = 1;
                    lastPage  = info.TotalPages;

                    if (firstPage != lastPage)
                    {
                        ImageFileLoaderPagesDialog dlg = new ImageFileLoaderPagesDialog(info.TotalPages, LoadOnlyOnePage);
                        if (dlg.ShowDialog(owner) == DialogResult.OK)
                        {
                            firstPage = dlg.FirstPage;
                            lastPage  = dlg.LastPage;
                        }
                        else
                        {
                            ok = false;
                        }
                    }
                }
                else
                {
                    firstPage = firstItem.PageNumber;
                    lastPage  = firstItem.PageNumber;
                }

                _firstPage = firstPage;
                _lastPage  = lastPage;

                if (autoLoad && ok)
                {
                    using (WaitCursor wait = new WaitCursor())
                    {
                        _image = codecs.Load(FileName, 0, CodecsLoadByteOrder.BgrOrGray, firstPage, lastPage);
                    }
                }
            }

            return(ok);
        }