Ejemplo n.º 1
1
        /// <summary>
        /// Returns an array of arguments to be sent to the Ghostscript API
        /// </summary>
        /// <param name="inputPath">Path to the source file</param>
        /// <param name="outputPath">Path to the output file</param>
        /// <param name="firstPage">The page of the file to start on</param>
        /// <param name="lastPage">The page of the file to end on</param>
        private static string[] GetArgs(string inputPath,
                                        string outputPath,
                                        int firstPage,
                                        int lastPage,
                                        int dpix,
                                        int dpiy,
                                        int width,
                                        int height)
        {
            // To maintain backwards compatibility, this method uses previous hardcoded values.

            GhostscriptSettings s = new GhostscriptSettings();

            s.Device     = Settings.GhostscriptDevices.jpeg;
            s.Page.Start = firstPage;
            s.Page.End   = lastPage;
            s.Resolution = new System.Drawing.Size(dpix, dpiy);

            Settings.GhostscriptPageSize pageSize = new Settings.GhostscriptPageSize();
            if (width == 0 && height == 0)
            {
                pageSize.Native = GhostscriptSharp.Settings.GhostscriptPageSizes.a7;
            }
            else
            {
                pageSize.Manual = new Size(width, height);
            }
            s.Size = pageSize;

            return(GetArgs(inputPath, outputPath, s));
        }
Ejemplo n.º 2
0
        protected GhostscriptManager()
        {
            revisionInfoLoaded = false;
            libraryHandle      = IntPtr.Zero;

            LoadGhostscriptLibrary();

            this.settings = new GhostscriptSettings();
        }
        protected GhostscriptManager()
        {
            revisionInfoLoaded = false;
            libraryHandle = IntPtr.Zero;

            LoadGhostscriptLibrary();

            this.settings = new GhostscriptSettings();
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Rasterises a PDF into selected format
 /// </summary>
 /// <param name="inputPath">PDF file to convert</param>
 /// <param name="outputPath">Destination file</param>
 /// <param name="settings">Conversion settings</param>
 public static void GenerateOutput(string inputPath, string outputPath, GhostscriptSettings settings)
 {
     if (architecture == Architecture.X86)
     {
         API.GhostScript32.CallAPI(GetArgs(inputPath, outputPath, settings));
     }
     else
     {
         API.GhostScript64.CallAPI(GetArgs(inputPath, outputPath, settings));
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Rasterises a PDF into selected format
 /// </summary>
 /// <param name="inputPath">PDF file to convert</param>
 /// <param name="outputPath">Destination file</param>
 /// <param name="settings">Conversion settings</param>
 public static void GenerateOutput(string inputPath, string outputPath, GhostscriptSettings settings)
 {
     if (IntPtr.Size == 4)
     {
         API.GhostScript32.CallAPI(GetArgs(inputPath, outputPath, settings));
     }
     else
     {
         API.GhostScript64.CallAPI(GetArgs(inputPath, outputPath, settings));
     }
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Rasterises a PDF into selected format
 /// </summary>
 /// <param name="inputPath">PDF file to convert</param>
 /// <param name="outputPath">Destination file</param>
 /// <param name="settings">Conversion settings</param>
 public static void GenerateOutput(string inputPath, string outputPath, GhostscriptSettings settings)
 {
     if (!CheckOS.Is64BitOperatingSystem())
     {
         API.GhostScript32.CallAPI(GetArgs(inputPath, outputPath, settings));
     }
     else
     {
         API.GhostScript64.CallAPI(GetArgs(inputPath, outputPath, settings));
     }
 }
        /// <summary>
        /// Returns an array of arguments to be sent to the Ghostscript API
        /// </summary>
        /// <param name="inputPath">Path to the source file</param>
        /// <param name="outputPath">Path to the output file</param>
        /// <param name="firstPage">The page of the file to start on</param>
        /// <param name="lastPage">The page of the file to end on</param>
        private static string[] GetArgs(string inputPath, string outputPath, int firstPage, int lastPage, int dpix, int dpiy, int width, int height)
        {
            // To maintain backwards compatibility, this method uses previous hardcoded values.
            GhostscriptSettings s = new GhostscriptSettings();
            s.Device = GhostscriptDevices.jpeg;
            s.Pages.Start = firstPage;
            s.Pages.End = lastPage;
            s.Resolution = new System.Drawing.Size(dpix, dpiy);

            GhostscriptPageSize pageSize = new GhostscriptPageSize();
            if (width == 0 && height == 0)
            {
                pageSize.Native = GhostscriptPageSizes.a7;
            }
            else
            {
                pageSize.Manual = new Size(width, height);
            }
            s.Size = pageSize;

            return GetArgs(inputPath, outputPath, s);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Convert a postscript file to a pdf
        /// </summary>
        /// <param name="outputPath">The path to create the output file. Put '%d' the path to create multiple numbered files, one for each page</param>
        /// <param name="inputPaths">One or more input files</param>
        public static void PsToPdf(String outputPath, params String[] inputPaths)
        {
            GhostscriptManager gsm = GhostscriptManager.GetInstance();
            bool libraryLoaded     = (gsm.libraryHandle != IntPtr.Zero);

            if (!libraryLoaded)
            {
                gsm.LoadGhostscriptLibrary();
            }
            GhostscriptSettings oldSettings = gsm.Settings;

            gsm.settings               = new GhostscriptSettings();
            gsm.Settings.Device        = GhostscriptSharp.Settings.GhostscriptDevices.pdfwrite;
            gsm.Settings.Page.AllPages = true;
            gsm.Settings.Quiet         = true;
            gsm.DoConvert(outputPath, inputPaths);
            if (!libraryLoaded)
            {
                gsm.UnloadGhostscriptLibrary();
            }
            gsm.settings = oldSettings;
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Returns an array of arguments to be sent to the Ghostscript API
        /// </summary>
        /// <param name="inputPath">Path to the source file</param>
        /// <param name="outputPath">Path to the output file</param>
        /// <param name="settings">API parameters</param>
        /// <returns>API arguments</returns>
        private static string[] GetArgs(string inputPath,
                                        string outputPath,
                                        GhostscriptSettings settings)
        {
            System.Collections.ArrayList args = new System.Collections.ArrayList(ARGS);

            if (settings.Device == Settings.GhostscriptDevices.UNDEFINED)
            {
                throw new ArgumentException("An output device must be defined for Ghostscript", "GhostscriptSettings.Device");
            }

            if (settings.Page.AllPages == false && (settings.Page.Start <= 0 && settings.Page.End < settings.Page.Start))
            {
                throw new ArgumentException("Pages to be printed must be defined.", "GhostscriptSettings.Pages");
            }

            if (settings.Resolution.IsEmpty)
            {
                throw new ArgumentException("An output resolution must be defined", "GhostscriptSettings.Resolution");
            }

            if (settings.Size.Native == Settings.GhostscriptPageSizes.UNDEFINED && settings.Size.Manual.IsEmpty)
            {
                throw new ArgumentException("Page size must be defined", "GhostscriptSettings.Size");
            }

            // Output device
            args.Add(String.Format("-sDEVICE={0}", settings.Device));

            // Pages to output
            if (settings.Page.AllPages)
            {
                args.Add("-dFirstPage=1");
            }
            else
            {
                args.Add(String.Format("-dFirstPage={0}", settings.Page.Start));
                if (settings.Page.End >= settings.Page.Start)
                {
                    args.Add(String.Format("-dLastPage={0}", settings.Page.End));
                }
            }

            // Page size
            if (settings.Size.Native == Settings.GhostscriptPageSizes.UNDEFINED)
            {
                args.Add(String.Format("-dDEVICEWIDTHPOINTS={0}", settings.Size.Manual.Width));
                args.Add(String.Format("-dDEVICEHEIGHTPOINTS={0}", settings.Size.Manual.Height));
                args.Add("-dFIXEDMEDIA");
                args.Add("-dPDFFitPage");
            }
            else
            {
                args.Add(String.Format("-sPAPERSIZE={0}", settings.Size.Native.ToString()));
            }

            // Page resolution
            args.Add(String.Format("-dDEVICEXRESOLUTION={0}", settings.Resolution.Width));
            args.Add(String.Format("-dDEVICEYRESOLUTION={0}", settings.Resolution.Height));

            // Files
            args.Add(String.Format("-sOutputFile={0}", outputPath));
            args.Add(inputPath);

            return((string[])args.ToArray(typeof(string)));
        }
 /// <summary>
 /// Rasterises a PDF into selected format
 /// </summary>
 /// <param name="inputPath">PDF file to convert</param>
 /// <param name="outputPath">Destination file</param>
 /// <param name="settings">Conversion settings</param>
 public static void GenerateOutput(string inputPath, string outputPath, GhostscriptSettings settings)
 {
     CallAPI(GetArgs(inputPath, outputPath, settings));
 }
        /// <summary>
        /// Returns an array of arguments to be sent to the Ghostscript API
        /// </summary>
        /// <param name="inputPath">Path to the source file</param>
        /// <param name="outputPath">Path to the output file</param>
        /// <param name="settings">API parameters</param>
        /// <returns>API arguments</returns>
        private static string[] GetArgs(string inputPath,
			string outputPath,
			GhostscriptSettings settings)
        {
            System.Collections.ArrayList args = new System.Collections.ArrayList(ARGS);

            if (settings.Device == Settings.GhostscriptDevices.UNDEFINED)
            {
                throw new ArgumentException("An output device must be defined for Ghostscript", "GhostscriptSettings.Device");
            }

            if (settings.Page.AllPages == false && (settings.Page.Start <= 0 && settings.Page.End < settings.Page.Start))
            {
                throw new ArgumentException("Pages to be printed must be defined.", "GhostscriptSettings.Pages");
            }

            if (settings.Resolution.IsEmpty)
            {
                throw new ArgumentException("An output resolution must be defined", "GhostscriptSettings.Resolution");
            }

            if (settings.Size.Native == Settings.GhostscriptPageSizes.UNDEFINED && settings.Size.Manual.IsEmpty)
            {
                throw new ArgumentException("Page size must be defined", "GhostscriptSettings.Size");
            }

            // Output device
            args.Add(String.Format("-sDEVICE={0}", settings.Device));

            // Pages to output
            if (settings.Page.AllPages)
            {
                args.Add("-dFirstPage=1");
            }
            else
            {
                args.Add(String.Format("-dFirstPage={0}", settings.Page.Start));
                if (settings.Page.End >= settings.Page.Start)
                {
                    args.Add(String.Format("-dLastPage={0}", settings.Page.End));
                }
            }

            // Page size
            if (settings.Size.Native == Settings.GhostscriptPageSizes.UNDEFINED)
            {
                args.Add(String.Format("-dDEVICEWIDTHPOINTS={0}", settings.Size.Manual.Width));
                args.Add(String.Format("-dDEVICEHEIGHTPOINTS={0}", settings.Size.Manual.Height));
            }
            else
            {
                args.Add(String.Format("-sPAPERSIZE={0}", settings.Size.Native.ToString()));
            }

            // Page resolution
            args.Add(String.Format("-dDEVICEXRESOLUTION={0}", settings.Resolution.Width));
            args.Add(String.Format("-dDEVICEYRESOLUTION={0}", settings.Resolution.Height));

            // Password
            if (settings.Password != null)
            {
                args.Add(String.Format("-sPDFPassword={0}", settings.Password.Password));
            }

            // Files
            args.Add(String.Format("-sOutputFile={0}", outputPath));
            args.Add(inputPath);

            return (string[])args.ToArray(typeof(string));
        }
        /// <summary>
        /// Returns an array of arguments to be sent to the Ghostscript API
        /// </summary>
        /// <param name="inputPath">Path to the source file</param>
        /// <param name="outputPath">Path to the output file</param>
        /// <param name="firstPage">The page of the file to start on</param>
        /// <param name="lastPage">The page of the file to end on</param>
        private static string[] GetArgs(string inputPath,
			string outputPath,
			int firstPage,
			int lastPage,
			int width,
			int height)
        {
            // To maintain backwards compatibility, this method uses previous hardcoded values.

            GhostscriptSettings s = new GhostscriptSettings();
            s.Device = Settings.GhostscriptDevices.jpeg;
            s.Page.Start = firstPage;
            s.Page.End = lastPage;
            s.Resolution = new System.Drawing.Size(width, height);

            Settings.GhostscriptPageSize pageSize = new Settings.GhostscriptPageSize();
            pageSize.Native = GhostscriptSharp.Settings.GhostscriptPageSizes.a7;
            s.Size = pageSize;

            return GetArgs(inputPath, outputPath, s);
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Rasterises a PDF into selected format
 /// </summary>
 /// <param name="inputPath">PDF file to convert</param>
 /// <param name="outputPath">Destination file</param>
 /// <param name="settings">Conversion settings</param>
 public static void GenerateOutput(string inputPath, string outputPath, GhostscriptSettings settings)
 {
     CallAPI(GetArgs(inputPath, outputPath, settings));
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Rasterises a PDF into selected format
 /// </summary>
 /// <param name="inputPath">PDF file to convert</param>
 /// <param name="outputPath">Destination file</param>
 /// <param name="settings">Conversion settings</param>
 public static void GenerateOutput(string inputPath, string outputPath, GhostscriptSettings settings)
 {
     if (IntPtr.Size == 4)
         API.GhostScript32.CallAPI(GetArgs(inputPath, outputPath, settings));
     else
         API.GhostScript64.CallAPI(GetArgs(inputPath, outputPath, settings));
 }