Convert() public method

Convert a single file!
You must pass all the parameter for the conversion as Proprieties of this class
public Convert ( string inputFile, string outputFile ) : bool
inputFile string The file PDf to convert
outputFile string The image file that will be created
return bool
Exemplo n.º 1
0
        /// <summary>
        /// Convert PDF to PNG format.
        /// </summary>
        /// <param name="inputPdfFile"></param>
        /// <returns>an array of PNG images</returns>
        public static string[] ConvertPdf2Png(string inputPdfFile)
        {
            PDFConvert converter = new PDFConvert();
            converter.GraphicsAlphaBit = 4;
            converter.TextAlphaBit = 4;
            converter.ResolutionX = 300; // -r300
            converter.OutputFormat = "pnggray"; // -sDEVICE

            string sOutputFile = string.Format("{0}\\workingimage%03d.png", Path.GetDirectoryName(inputPdfFile));
            bool success = converter.Convert(inputPdfFile, sOutputFile);

            if (success)
            {
                // find working files
                string[] workingFiles = Directory.GetFiles(Path.GetDirectoryName(inputPdfFile), "workingimage???.png");
                return workingFiles;
            }
            else
            {
                return new string[0];
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Split PDF.
        /// </summary>
        /// <param name="inputPdfFile"></param>
        /// <param name="outputPdfFile"></param>
        /// <param name="firstPage"></param>
        /// <param name="lastPage"></param>
        public static void SplitPdf(string inputPdfFile, string outputPdfFile, string firstPage, string lastPage)
        {
            PDFConvert converter = new PDFConvert();
            converter.OutputFormat = "pdfwrite"; // -sDEVICE
            converter.ThrowOnlyException = true; // rethrow exceptions

            //gs -sDEVICE=pdfwrite -dNOPAUSE -dQUIET -dBATCH -dFirstPage=m -dLastPage=n -sOutputFile=out.pdf in.pdf
            if (firstPage.Trim().Length > 0)
            {
                converter.FirstPageToConvert = Int32.Parse(firstPage);
            }

            if (lastPage.Trim().Length > 0)
            {
                converter.LastPageToConvert = Int32.Parse(lastPage);
            }

            if (!converter.Convert(inputPdfFile, outputPdfFile))
            {
                throw new ApplicationException("Split PDF failed.");
            }
        }