예제 #1
0
        /* ----------------------------------------------------------------- */
        ///
        /// Configure
        /// 
        /// <summary>
        /// Ghostscript オブジェクトを生成し、必要な設定を行います。
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        private Ghostscript.Converter Configure(UserSetting setting, string src, string dest)
        {
            var gs = new Ghostscript.Converter(_messages);
            if (!string.IsNullOrEmpty(setting.LibPath)) gs.AddInclude(IoEx.Path.Combine(setting.LibPath, "lib"));
            gs.Device = Parameter.GetDevice(setting.FileType, setting.Grayscale);
            gs.Resolution = Parameter.ToValue(setting.Resolution);
            if (setting.Orientation == Parameter.Orientations.Auto) gs.AutoRotatePages = true;
            else gs.Orientation = (int)setting.Orientation;

            ConfigureCommonImage(setting, gs);
            if (Parameter.IsImageType(setting.FileType)) ConfigureBitmap(setting, gs);
            else ConfigureDocument(setting, gs);

            gs.AddSource(src);
            gs.Destination = dest;

            return gs;
        }
예제 #2
0
        /* ----------------------------------------------------------------- */
        ///
        /// Run
        /// 
        /// NOTE: 文書プロパティ,パスワード関連とファイル結合は iText
        /// に任せる.出力パスに指定されたファイルが存在する場合がある.
        /// そのときは,_setting.ExistedFile の指定に従う.
        /// ExistedFile: 上書き,先頭に結合,末尾に結合
        /// 結合部分は,iText が行う.
        /// 
        /* ----------------------------------------------------------------- */
        public bool Run(UserSetting setting)
        {
            // Ghostscript に指定するパスに日本語が入るとエラーが発生する
            // 場合があるので,作業ディレクトリを変更する.
            this.CreateWorkingDirectory(setting);

            Ghostscript.Converter gs = new Ghostscript.Converter(_messages);
            gs.Device = Parameter.Device(setting.FileType, setting.Grayscale);
            bool status = true;
            try {
                gs.AddInclude(setting.LibPath + @"\lib");
                gs.PageRotation = setting.PageRotation;
                gs.Resolution = Parameter.ResolutionValue(setting.Resolution);

                this.ConfigImageOperations(setting, gs);
                if (Parameter.IsImageType(setting.FileType)) this.ConfigImage(setting, gs);
                else this.ConfigDocument(setting, gs);
                this.EscapeExistedFile(setting);

                gs.AddSource(setting.InputPath);
                gs.Destination = setting.OutputPath;
                gs.Run();

                if (setting.FileType == Parameter.FileTypes.PDF)
                {
                    PDFModifier modifier = new PDFModifier(_escaped, _messages);
                    status = modifier.Run(setting);
                    _messages.Add(new Message(Message.Levels.Info, String.Format("CubePDF.PDFModifier.Run: {0}", status.ToString())));
                }

                if (status)
                {
                    PostProcess postproc = new PostProcess(_messages);
                    status = postproc.Run(setting);
                    _messages.Add(new Message(Message.Levels.Info, String.Format("CubePDF.PostProcess.Run: {0}", status.ToString())));
                }
            }
            catch (Exception err) {
                _messages.Add(new Message(Message.Levels.Error, err));
                _messages.Add(new Message(Message.Levels.Debug, err));
                status = false;
            }
            finally {
                if (Directory.Exists(Utility.WorkingDirectory)) Directory.Delete(Utility.WorkingDirectory, true);
                if (setting.DeleteOnClose && File.Exists(setting.InputPath))
                {
                    _messages.Add(new Message(Message.Levels.Debug, String.Format("{0}: delete on close", setting.InputPath)));
                    File.Delete(setting.InputPath);
                }
            }

            return status;
        }