コード例 #1
0
        public void ConvertPdfPageToImage(string outputFileName, int pageNumber)
        {
            if (pageNumber < 1 || pageNumber > this.PageCount)
            {
                throw new ArgumentException("Page number is out of bounds", "pageNumber");
            }

            using (GhostScriptAPI api = new GhostScriptAPI())
                api.Execute(this.GetConversionArguments(this._pdfFileName, outputFileName, pageNumber, this.PdfPassword, this.Settings));
        }
コード例 #2
0
        //Преобразование pdf в картинку
        private void ConvertPdfPageToImage(string outputFileName, int pageNumber)
        {
            if (pageNumber < 1 || pageNumber > _pageCount)
            {
                throw new ArgumentException(Resources.ReadPageError, "pageNumber");
            }

            using (var api = new GhostScriptAPI())
            {
                api.Execute(GetConversionArguments(_pdfFileName, outputFileName, pageNumber,
                                                   null, _settings));
            }
        }
コード例 #3
0
        protected virtual IDictionary <GhostScriptCommand, object> GetConversionArguments(string pdfFileName, string outputImageFileName, int pageNumber, string password, Pdf2ImageSettings settings)
        {
            Dictionary <GhostScriptCommand, object> arguments;

            arguments = new Dictionary <GhostScriptCommand, object>();

            // basic GhostScript setup
            arguments.Add(GhostScriptCommand.Silent, null);
            arguments.Add(GhostScriptCommand.Safer, null);
            arguments.Add(GhostScriptCommand.Batch, null);
            arguments.Add(GhostScriptCommand.NoPause, null);

            // specify the output
            arguments.Add(GhostScriptCommand.Device, GhostScriptAPI.GetDeviceName(settings.ImageFormat));
            arguments.Add(GhostScriptCommand.OutputFile, outputImageFileName);

            // page numbers
            arguments.Add(GhostScriptCommand.FirstPage, pageNumber);
            arguments.Add(GhostScriptCommand.LastPage, pageNumber);

            // graphics options
            arguments.Add(GhostScriptCommand.UseCIEColor, null);

            if (settings.AntiAliasMode != AntiAliasMode.None)
            {
                arguments.Add(GhostScriptCommand.TextAlphaBits, settings.AntiAliasMode);
                arguments.Add(GhostScriptCommand.GraphicsAlphaBits, settings.AntiAliasMode);
            }

            arguments.Add(GhostScriptCommand.GridToFitTT, settings.GridFitMode);

            // image size
            if (settings.TrimMode != PdfTrimMode.PaperSize)
            {
                arguments.Add(GhostScriptCommand.Resolution, settings.Dpi.ToString());
            }

            switch (settings.TrimMode)
            {
            case PdfTrimMode.PaperSize:
                if (settings.PaperSize != PaperSize.Default)
                {
                    arguments.Add(GhostScriptCommand.FixedMedia, true);
                    arguments.Add(GhostScriptCommand.PaperSize, settings.PaperSize);
                }
                break;

            case PdfTrimMode.TrimBox:
                arguments.Add(GhostScriptCommand.UseTrimBox, true);
                break;

            case PdfTrimMode.CropBox:
                arguments.Add(GhostScriptCommand.UseCropBox, true);
                break;
            }

            // pdf password
            if (!string.IsNullOrEmpty(password))
            {
                arguments.Add(GhostScriptCommand.PDFPassword, password);
            }

            // pdf filename
            arguments.Add(GhostScriptCommand.InputFile, pdfFileName);

            return(arguments);
        }
コード例 #4
0
ファイル: Pdf2Image.cs プロジェクト: nandusharma/ocrdemo
        public void ConvertPdfPageToImage(string outputFileName, int pageNumber)
        {
            if (pageNumber < 1 || pageNumber > this.PageCount)
            throw new ArgumentException("Page number is out of bounds", "pageNumber");

              using (GhostScriptAPI api = new GhostScriptAPI())
            api.Execute(this.GetConversionArguments(this._pdfFileName, outputFileName, pageNumber, this.PdfPassword, this.Settings));
        }