GhostScriptSharp/GhostscriptSharp.cs
/// <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>
Returns an array of arguments to be sent to the Ghostscript API
Returns an array of arguments to be sent to the Ghostscript API
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");
			}
			args.Add(String.Format("-sDEVICE={0}", settings.Device));
			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));
				}
			}
			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()));
			}
			args.Add(String.Format("-dDEVICEXRESOLUTION={0}", settings.Resolution.Width));
			args.Add(String.Format("-dDEVICEYRESOLUTION={0}", settings.Resolution.Height));
			args.Add(String.Format("-sOutputFile={0}", outputPath));
			args.Add(inputPath);
			return (string[])args.ToArray(typeof(string));
		}
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 ( " " , " " ) ; } if ( settings . Page . AllPages == false && ( settings . Page . Start <= 0 && settings . Page . End < settings . Page . Start ) ) { throw new ArgumentException ( " " , " " ) ; } if ( settings . Resolution . IsEmpty ) { throw new ArgumentException ( " " , " " ) ; } if ( settings . Size . Native == Settings . GhostscriptPageSizes . UNDEFINED && settings . Size . Manual . IsEmpty ) { throw new ArgumentException ( " " , " " ) ; } args . Add ( String . Format ( " " , settings . Device ) ) ; if ( settings . Page . AllPages ) { args . Add ( " " ) ; } else { args . Add ( String . Format ( " " , settings . Page . Start ) ) ; if ( settings . Page . End >= settings . Page . Start ) { args . Add ( String . Format ( " " , settings . Page . End ) ) ; } } if ( settings . Size . Native == Settings . GhostscriptPageSizes . UNDEFINED ) { args . Add ( String . Format ( " " , settings . Size . Manual . Width ) ) ; args . Add ( String . Format ( " " , settings . Size . Manual . Height ) ) ; } else { args . Add ( String . Format ( " " , settings . Size . Native . ToString ( ) ) ) ; } args . Add ( String . Format ( " " , settings . Resolution . Width ) ) ; args . Add ( String . Format ( " " , settings . Resolution . Height ) ) ; args . Add ( String . Format ( " " , outputPath ) ) ; args . Add ( inputPath ) ; return ( string [ ] ) args . ToArray ( typeof ( string ) ) ; }
Returns an array of arguments to be sent to the Ghostscript API
Returns an array of arguments to be sent to the Ghostscript API
// Output device // Pages to output // Page size // Page resolution // Files
None
inputPath
string
Path to the source file
Path to the source file
outputPath
string
Path to the output file
Path to the output file
settings
GhostscriptSettings
None