Beispiel #1
0
        /// <summary>
        /// Initialize GhostscriptWrapper with relevant parameters for PDF2PNGSingle conversion.
        /// This method convert only the first page of the PDF to PNG.
        /// </summary>
        public void InitPDF2PNGSingleConversion()
        {
            Cleanup();

            // Parameters creation.
            string[] parameters = new string[6];
            parameters[0] = "this is gs command .exe name";		// Ghostscript exe command.
            parameters[1] = "-dNOPAUSE";						// Do not prompt and pause for each page
            parameters[2] = "-dFirstPage=1";		            // Convert only the first page of the PDF to PNG.
            parameters[3] = "-dLastPage=1";		                // Convert only the first page of the PDF to PNG.
            parameters[4] = "-sDEVICE=pngalpha";				// what kind of export format i should provide, in this case "pngalpha" for transparent PNG.
            parameters[5] = "-dDOINTERPOLATE";

            // Create the Ghostscript wrapper.
            m_GhostscriptWrapper = new GhostscriptWrapper();
            m_GhostscriptWrapper.Init(parameters);
        }
Beispiel #2
0
        /// <summary>
        /// Initialize GhostscriptWrapper with relevant parameters for PDF2JPG conversion.
        /// </summary>
        public void InitPDF2JPGConversion()
        {
            Cleanup();

            // Parameters creation.
            string[] parameters = new string[4];
            parameters[0] = "this is gs command .exe name";		// Ghostscript exe command.
            parameters[1] = "-dNOPAUSE";						// Do not prompt and pause for each page
            parameters[2] = "-sDEVICE=jpeg";					// what kind of export format i should provide.
            parameters[3] = "-dDOINTERPOLATE";

            // Create the Ghostscript wrapper.
            m_GhostscriptWrapper = new GhostscriptWrapper();
            m_GhostscriptWrapper.Init(parameters);
        }
Beispiel #3
0
        /// <summary>
        /// Convert PDF to EPS.
        /// </summary>
        /// <param name="inPathFileToConvert"></param>
        /// <param name="inOutputFileFullPath"></param>
        /// <param name="inFirstPageToConvert"></param>
        /// <param name="inLastPageToConvert"></param>
        /// <returns></returns>
        public bool ConvertPDF2EPS(string inPathFileToConvert, string inOutputFileFullPath, double inFirstPageToConvert, double inLastPageToConvert)
        {
            // Parameters creation.
            string[] parameters = new string[10];
            parameters[0] = "this is gs command .exe name";								// Ghostscript exe command.
            parameters[1] = "-dNOPAUSE";												// Do not prompt and pause for each page
            parameters[2] = "-dBATCH";													// Terminate when accomplish.
            parameters[3] = "-dGraphicsAlphaBits=2";
            parameters[4] = "-dTextAlphaBits=4";
            parameters[5] = "-dFirstPage=" + Convert.ToInt32(inFirstPageToConvert);		// First page to convert in the PDF.
            parameters[6] = "-dLastPage=" + Convert.ToInt32(inLastPageToConvert);		// Last page to convert in the PDF.
            parameters[7] = "-sDEVICE=eps2write";										// Device name.
            parameters[8] = "-sOutputFile=" + inOutputFileFullPath;						// Where to write the output.
            parameters[9] = inPathFileToConvert;										// File to convert.

            // Create the Ghostscript wrapper.
            m_GhostscriptWrapper = new GhostscriptWrapper();
            bool convertResult = m_GhostscriptWrapper.Init(parameters);

            Cleanup();

            return convertResult;
        }
Beispiel #4
0
        /// <summary>
        /// Convert EPS to PDF.
        /// </summary>
        /// <param name="inPathFileToConvert"></param>
        /// <param name="inOutputFileFullPath"></param>
        /// <returns></returns>
        public bool ConvertPDF2LowResPDF(string inPathFileToConvert, string inOutputFileFullPath, int dpiResolution = 72)
        {
            // Parameters creation.
            List<string> parameters = new List<string>();
            parameters.Add("this is gs command .exe name");								// Ghostscript exe command.
            parameters.Add("-dNOPAUSE");												// Do not prompt and pause for each page
            parameters.Add("-dBATCH");													// Terminate when accomplish.
            parameters.Add("-dPDFSETTINGS=/default");
            parameters.Add("-r" + dpiResolution);
            parameters.Add("-sDEVICE=pdfwrite");										// Device name.
            parameters.Add("-sOutputFile=" + inOutputFileFullPath);						// Where to write the output.
            parameters.Add(inPathFileToConvert);										// File to convert.

            // Create the Ghostscript wrapper.
            m_GhostscriptWrapper = new GhostscriptWrapper();
            bool convertResult = m_GhostscriptWrapper.Init(parameters.ToArray());

            Cleanup();

            return convertResult;
        }
Beispiel #5
0
        /// <summary>
        /// Convert JPG to low res JPG.
        /// </summary>
        /// <param name="inPathFileToConvert"></param>
        /// <param name="inOutputFileFullPath"></param>
        /// <returns></returns>
        public bool ConvertJPG2LowResJPG(string inPathFileToConvert, string inOutputFileFullPath, int dpiResolution = 72)
        {
            //Command example:
            //gswin32c -sDEVICE=jpeg -dBATCH -dNOPAUSE -r72 -sOutputFile=file.jpg viewjpeg.ps -c "(c:/photos/file.jpg) << /PageSize 2 index viewJPEGgetsize 2 array astore  >> setpagedevice viewJPEG showpage"

            string fullExeNameAndPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
            string exeDirectory = System.IO.Path.GetDirectoryName(fullExeNameAndPath);

            // Parameters creation.
            string[] parameters = new string[11];
            parameters[0] = "this is gs command .exe name";								// Ghostscript exe command.
            parameters[1] = "-dNOPAUSE";												// Do not prompt and pause for each page
            parameters[2] = "-dBATCH";													// Terminate when accomplish.
            parameters[3] = "-dGraphicsAlphaBits=2";
            parameters[4] = "-dTextAlphaBits=4";
            parameters[5] = "-r" + dpiResolution;
            parameters[6] = "-sDEVICE=jpeg";											// Device name.
            parameters[7] = "-sOutputFile=" + inOutputFileFullPath;						// Where to write the output.
            parameters[8] = exeDirectory + "\\viewjpeg.ps";
            parameters[9] = "-c";
            parameters[10] = "(" + inPathFileToConvert.Replace("\\", "/") + ") << /PageSize 2 index viewJPEGgetsize 2 array astore >> setpagedevice viewJPEG showpage";

            // Create the Ghostscript wrapper.
            m_GhostscriptWrapper = new GhostscriptWrapper();
            bool convertResult = m_GhostscriptWrapper.Init(parameters);

            Cleanup();

            return convertResult;
        }