Example #1
0
        private void SavePDF2Images(string strPDFPath)
        {
            string            sourcePath   = strPDFPath;
            string            outputPath   = System.IO.Path.GetDirectoryName(Application.ExecutablePath) + "\\Output\\Images\\";
            PdfImageConverter pdfConverter = new PdfImageConverter(sourcePath);

            pdfConverter.DPI = 96;
            Directory.CreateDirectory(Path.GetDirectoryName(outputPath));


            for (int i = 0; i < pdfConverter.PageCount - 1; i++)
            {
                Image pageImage = pdfConverter.PageToImage(i, 300, 300);
                pageImage.Save(outputPath + "Page" + i + ".jpg", ImageFormat.Jpeg);
            }
        }
Example #2
0
        public static void ConvertPdfToImage()
        {
            // Create a PDF converter instance by loading a local file
            PdfImageConverter pdfConverter = new PdfImageConverter("sample.pdf");

            // Set the dpi, the output image will be rendered in such resolution
            pdfConverter.DPI = 96;

            for (int i = 0; i < pdfConverter.PageCount; i++)
            {
                // Convert each pdf page to jpeg image with original page size
                //Image pageImage = pdfConverter.PageToImage(i);
                // Convert pdf to jpg in customized image size
                Image pageImage = pdfConverter.PageToImage(i, 500, 800);

                // Save converted image to jpeg format
                pageImage.Save("Page " + i + ".jpg", ImageFormat.Jpeg);
            }
        }
Example #3
0
        public List <Image> pdfToImage(string pdfFilePath, int dpi, float resModifier)
        {
            // Create a PDF converter instance by loading a local file
            PdfImageConverter pdfConverter = new PdfImageConverter(pdfFilePath);

            // Set the dpi, the output image will be rendered in such resolution
            pdfConverter.DPI = dpi;

            // the output image will be rendered to grayscale image or not
            pdfConverter.GrayscaleOutput = true;

            // open and load the file
            using (PdfSharp.Pdf.PdfDocument inputDocument = PdfReader.Open(pdfFilePath, PdfDocumentOpenMode.Import))
            {
                List <Image> tempImagePdfPages = new List <Image>();

                // process and save pages one by one
                for (int i = 0; i < inputDocument.Pages.Count; i++)
                {
                    PdfSharp.Pdf.PdfPage currentPage = inputDocument.Pages[i];

                    /*// Create instance of Ghostscript wrapper class.
                     * GS gs = new GS();*/

                    /*int widthPdfPage = Convert.ToInt32(currentPage.Width.Point);
                     * int heightPdfPage = Convert.ToInt32(currentPage.Height.Point);*/

                    int widthPdfPage  = Convert.ToInt32(currentPage.Width.Point * resModifier);
                    int heightPdfPage = Convert.ToInt32(currentPage.Height.Point * resModifier);

                    // Convert pdf to png in customized image size
                    Image image = pdfConverter.PageToImage(i, widthPdfPage, heightPdfPage);

                    tempImagePdfPages.Add(image);
                }

                pdfConverter.Dispose();

                return(tempImagePdfPages);
            }
        }