Пример #1
0
        ///<Summary>
        /// ConvertPdfToBmp method to convert PDF to BMP
        ///</Summary>
        public Response ConvertPdfToBmp(string fileName, string folderName)
        {
            return(ProcessTask(fileName, folderName, ".bmp", true, "", true, delegate(string inFilePath, string outPath, string zipOutFolder)
            {
                Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(inFilePath);

                string outfileName = Path.GetFileNameWithoutExtension(fileName) + "_{0}";
                int totalPages = pdfDocument.Pages.Count;
                for (int pageCount = 1; pageCount <= totalPages; pageCount++)
                {
                    if (totalPages > 1)
                    {
                        outPath = zipOutFolder + "/" + outfileName;
                        outPath = string.Format(outPath, pageCount);
                    }
                    else
                    {
                        outPath = zipOutFolder + "/" + Path.GetFileNameWithoutExtension(fileName);
                    }

                    Resolution resolution = new Resolution(300);
                    BmpDevice bmpDevice = new BmpDevice(resolution);
                    bmpDevice.Process(pdfDocument.Pages[pageCount], outPath + ".bmp");
                }
            }));
        }
        public static void Run()
        {
            // ExStart:ConvertToBMP         
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_Images();

            // Open document
            Document pdfDocument = new Document(dataDir + "AddImage.pdf");

            for (int pageCount = 1; pageCount <= pdfDocument.Pages.Count; pageCount++)
            {
                using (FileStream imageStream = new FileStream("image" + pageCount + "_out" + ".bmp", FileMode.Create))
                {
                    // Create Resolution object
                    Resolution resolution = new Resolution(300);
                    // Create BMP device with specified attributes
                    // Width, Height, Resolution, PageSize

                    BmpDevice bmpDevice = new BmpDevice(resolution);
                    // Convert a particular page and save the image to stream
                    bmpDevice.Process(pdfDocument.Pages[pageCount], imageStream);
                    // Close stream
                    imageStream.Close();
                }
            } 
            // ExEnd:ConvertToBMP   
            Console.WriteLine("\nPDF file converted to bmp successfully!"); 
        }
Пример #3
0
        public static void Run()
        {
            // ExStart:ConvertToBMP
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_Images();

            // Open document
            Document pdfDocument = new Document(dataDir + "AddImage.pdf");

            for (int pageCount = 1; pageCount <= pdfDocument.Pages.Count; pageCount++)
            {
                using (FileStream imageStream = new FileStream("image" + pageCount + "_out" + ".bmp", FileMode.Create))
                {
                    // Create Resolution object
                    Resolution resolution = new Resolution(300);
                    // Create BMP device with specified attributes
                    // Width, Height, Resolution, PageSize

                    BmpDevice bmpDevice = new BmpDevice(resolution);
                    // Convert a particular page and save the image to stream
                    bmpDevice.Process(pdfDocument.Pages[pageCount], imageStream);
                    // Close stream
                    imageStream.Close();
                }
            }
            // ExEnd:ConvertToBMP
            Console.WriteLine("\nPDF file converted to bmp successfully!");
        }
Пример #4
0
        private static Stream ToStream(int pageIndex)
        {
            var memoryStream = new MemoryStream();

            if (PdfDoc.Pages.Count >= pageIndex)
            {
                var device = new BmpDevice(new Resolution(150));
                device.Process(PdfDoc.Pages[pageIndex], memoryStream);
            }
            memoryStream.Seek(0, SeekOrigin.Begin);
            return(memoryStream);
        }