Initialize() public method

public Initialize ( string sArgs ) : bool
sArgs string
return bool
Example #1
0
        /// <summary>
        /// Get PDF Page Count.
        /// </summary>
        /// <param name="inputPdfFile"></param>
        /// <returns></returns>
        public static int GetPdfPageCount(string inputPdfFile)
        {
            PDFConvert converter = new PDFConvert();
            converter.RedirectIO = true;
            converter.ThrowOnlyException = true; // rethrow exceptions

            //gs -q -sPDFname=test.pdf pdfpagecount.ps
            List<string> gsArgs = new List<string>();
            gsArgs.Add("-gs");
            gsArgs.Add("-dNOPAUSE");
            gsArgs.Add("-dQUIET");
            gsArgs.Add("-dBATCH");
            gsArgs.Add("-sPDFname=" + inputPdfFile);
            gsArgs.Add("Library/pdfpagecount.ps");

            int pageCount = 0;

            using (StringWriter writer = new StringWriter())
            {
                try
                {
                    converter.StdOut = writer;
                    if (converter.Initialize(gsArgs.ToArray()))
                    {
                        pageCount = Int32.Parse(writer.ToString().Replace("%%Pages: ", String.Empty));
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }

            return pageCount;
        }
Example #2
0
        /// <summary>
        /// Merge PDF files.
        /// </summary>
        /// <param name="inputPdfFiles"></param>
        /// <param name="outputPdfFile"></param>
        public static void MergePdf(string[] inputPdfFiles, string outputPdfFile)
        {
            PDFConvert converter = new PDFConvert();
            converter.ThrowOnlyException = true; // rethrow exceptions

            //gs -sDEVICE=pdfwrite -dNOPAUSE -dQUIET -dBATCH -sOutputFile=out.pdf in1.pdf in2.pdf in3.pdf
            List<string> gsArgs = new List<string>();
            gsArgs.Add("-gs");
            gsArgs.Add("-sDEVICE=pdfwrite");
            gsArgs.Add("-dNOPAUSE");
            gsArgs.Add("-dQUIET");
            gsArgs.Add("-dBATCH");
            gsArgs.Add("-sOutputFile=" + outputPdfFile);

            foreach (string inputPdfFile in inputPdfFiles)
            {
                gsArgs.Add(inputPdfFile);
            }

            if (!converter.Initialize(gsArgs.ToArray()))
            {
                throw new ApplicationException("Merge PDF failed.");
            }
        }