We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Asp.net Aspose, trying to make a multiple page pdf file turn into multiple png files with variations to the name

Im trying to have a multiple page pdf be turn into multiple png files shouldn´t the code im using work or am i missing something here is some code.

protected void PdfToPng(string filepdf, int width,  int height)
        string pdfFile = "";
        string fileName = Path.GetFileName(filepdf);

        string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName);
        DirectoryInfo AnexoDirectory = new DirectoryInfo(PathForPdf);
        FileInfo[] filesInDir = AnexoDirectory.GetFiles("*" + fileNameWithoutExtension + ".pdf");

        foreach (FileInfo foundFile in filesInDir)
            pdfFile = foundFile.FullName;

            // Open PDF document
            Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(pdfFile);

        // Loop through each page
        foreach (var page in pdfDocument.Pages)

            // Create file stream for output image
            using (FileStream imageStream = new FileStream(PathForPdf + @"\\" + string.Format((fileNameWithoutExtension + ".png"), page.Number), FileMode.Create))
                // Create Resolution object
                Aspose.Pdf.Devices.Resolution resolution = new Resolution(1200);

                // Create Png device with specified attributes
                // Width, Height, Resolution
                PngDevice PngDevice = new PngDevice(width, height, resolution);

                // Convert a particular page and save the image to stream
                PngDevice.Process(page, imageStream);

                // Close stream





The code seems fine. However, please explain what type of issue are your facing? Please share a sample PDF as well so that we can test the scenario in our environment and address the issue accordingly.